Skip to content

Commit d60ee48

Browse files
committed
Various networking fixes.
1 parent 1220d19 commit d60ee48

5 files changed

Lines changed: 20 additions & 8 deletions

File tree

alethzero/DownloadView.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,21 @@ void DownloadView::paintEvent(QPaintEvent*)
3838
{
3939
QPainter p(this);
4040

41-
if (!m_man || m_man->chain().empty())
41+
if (!m_man || m_man->chain().empty() || !m_man->subCount())
4242
{
4343
p.fillRect(rect(), Qt::white);
4444
return;
4545
}
4646

4747
p.fillRect(rect(), Qt::black);
4848

49-
double n = sqrt(double(rect().width()) * rect().height() / m_man->chain().size());
49+
50+
double ratio = (double)rect().width() / rect().height();
51+
if (ratio < 1)
52+
ratio = 1 / ratio;
53+
double n = min(rect().width(), rect().height()) / ceil(sqrt(m_man->chain().size() / ratio));
54+
55+
// double n = sqrt(double(rect().width()) * rect().height() / (m_man->chain().size()));
5056
QSizeF area(n, n);
5157
QPointF pos(0, 0);
5258

@@ -57,6 +63,14 @@ void DownloadView::paintEvent(QPaintEvent*)
5763
QColor c = Qt::black;
5864
if (bg.contains(i))
5965
c = Qt::white;
66+
unsigned h = 0;
67+
unsigned dh = 360 / m_man->subCount();
68+
m_man->foreachSub([&](DownloadSub const& s)
69+
{
70+
if (s.asked().contains(i))
71+
c = QColor::fromHsv(h, 64, 128);
72+
h += dh;
73+
});
6074
p.fillRect(QRectF(pos, area), QBrush(c));
6175

6276
pos.setX(pos.x() + n);

libdevcore/Worker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void Worker::startWorking()
4040
setThreadName(m_name.c_str());
4141
while (!m_stop)
4242
{
43-
this_thread::sleep_for(chrono::milliseconds(100));
43+
this_thread::sleep_for(chrono::milliseconds(30));
4444
doWork();
4545
}
4646
cdebug << "Finishing up worker thread";

libethereum/DownloadMan.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class DownloadMan
120120

121121
h256s chain() const { return m_chain; }
122122
void foreachSub(std::function<void(DownloadSub const&)> const& _f) const { ReadGuard l(x_subs); for(auto i: m_subs) _f(*i); }
123+
unsigned subCount() const { ReadGuard l(x_subs); return m_subs.size(); }
123124
RangeMask<unsigned> blocksGot() const { return m_blocksGot; }
124125

125126
private:

libethereum/EthereumPeer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void EthereumPeer::giveUpOnFetch()
117117
clogS(NetNote) << "GIVE UP FETCH";
118118

119119
// a bit overkill given that the other nodes may yet have the needed blocks, but better to be safe than sorry.
120-
if (m_grabbing == Grabbing::Chain)
120+
if (m_grabbing == Grabbing::Chain || m_grabbing == Grabbing::ChainHelper)
121121
{
122122
host()->noteDoneBlocks(this);
123123
m_grabbing = Grabbing::Nothing;

libp2p/Host.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,6 @@ void Host::growPeers()
452452
m_lastPeersRequest = chrono::steady_clock::now();
453453
}
454454

455-
456455
if (!m_accepting)
457456
ensureAccepting();
458457

@@ -462,10 +461,8 @@ void Host::growPeers()
462461
auto x = time(0) % m_freePeers.size();
463462
m_incomingPeers[m_freePeers[x]].second++;
464463
if (!m_peers.count(m_freePeers[x]))
465-
{
466464
connect(m_incomingPeers[m_freePeers[x]].first);
467-
m_freePeers.erase(m_freePeers.begin() + x);
468-
}
465+
m_freePeers.erase(m_freePeers.begin() + x);
469466
}
470467
}
471468

0 commit comments

Comments
 (0)