diff --git a/alethzero/DownloadView.cpp b/alethzero/DownloadView.cpp index 52dc99004..8242a2793 100644 --- a/alethzero/DownloadView.cpp +++ b/alethzero/DownloadView.cpp @@ -38,7 +38,7 @@ void DownloadView::paintEvent(QPaintEvent*) { QPainter p(this); - if (!m_man || m_man->chain().empty()) + if (!m_man || m_man->chain().empty() || !m_man->subCount()) { p.fillRect(rect(), Qt::white); return; @@ -46,7 +46,13 @@ void DownloadView::paintEvent(QPaintEvent*) p.fillRect(rect(), Qt::black); - double n = sqrt(double(rect().width()) * rect().height() / m_man->chain().size()); + + double ratio = (double)rect().width() / rect().height(); + if (ratio < 1) + ratio = 1 / ratio; + double n = min(rect().width(), rect().height()) / ceil(sqrt(m_man->chain().size() / ratio)); + +// double n = sqrt(double(rect().width()) * rect().height() / (m_man->chain().size())); QSizeF area(n, n); QPointF pos(0, 0); @@ -57,6 +63,14 @@ void DownloadView::paintEvent(QPaintEvent*) QColor c = Qt::black; if (bg.contains(i)) c = Qt::white; + unsigned h = 0; + unsigned dh = 360 / m_man->subCount(); + m_man->foreachSub([&](DownloadSub const& s) + { + if (s.asked().contains(i)) + c = QColor::fromHsv(h, 64, 128); + h += dh; + }); p.fillRect(QRectF(pos, area), QBrush(c)); pos.setX(pos.x() + n); diff --git a/libdevcore/Worker.cpp b/libdevcore/Worker.cpp index 88ed57602..29ff766d7 100644 --- a/libdevcore/Worker.cpp +++ b/libdevcore/Worker.cpp @@ -40,7 +40,7 @@ void Worker::startWorking() setThreadName(m_name.c_str()); while (!m_stop) { - this_thread::sleep_for(chrono::milliseconds(100)); + this_thread::sleep_for(chrono::milliseconds(30)); doWork(); } cdebug << "Finishing up worker thread"; diff --git a/libethereum/DownloadMan.h b/libethereum/DownloadMan.h index 3a2506bb5..e67076d5a 100644 --- a/libethereum/DownloadMan.h +++ b/libethereum/DownloadMan.h @@ -120,6 +120,7 @@ public: h256s chain() const { return m_chain; } void foreachSub(std::function const& _f) const { ReadGuard l(x_subs); for(auto i: m_subs) _f(*i); } + unsigned subCount() const { ReadGuard l(x_subs); return m_subs.size(); } RangeMask blocksGot() const { return m_blocksGot; } private: diff --git a/libethereum/EthereumPeer.cpp b/libethereum/EthereumPeer.cpp index ceff02bb5..2ee0905d0 100644 --- a/libethereum/EthereumPeer.cpp +++ b/libethereum/EthereumPeer.cpp @@ -117,7 +117,7 @@ void EthereumPeer::giveUpOnFetch() clogS(NetNote) << "GIVE UP FETCH"; // a bit overkill given that the other nodes may yet have the needed blocks, but better to be safe than sorry. - if (m_grabbing == Grabbing::Chain) + if (m_grabbing == Grabbing::Chain || m_grabbing == Grabbing::ChainHelper) { host()->noteDoneBlocks(this); m_grabbing = Grabbing::Nothing; diff --git a/libp2p/Host.cpp b/libp2p/Host.cpp index 7c523e550..9d033e6f8 100644 --- a/libp2p/Host.cpp +++ b/libp2p/Host.cpp @@ -452,7 +452,6 @@ void Host::growPeers() m_lastPeersRequest = chrono::steady_clock::now(); } - if (!m_accepting) ensureAccepting(); @@ -462,10 +461,8 @@ void Host::growPeers() auto x = time(0) % m_freePeers.size(); m_incomingPeers[m_freePeers[x]].second++; if (!m_peers.count(m_freePeers[x])) - { connect(m_incomingPeers[m_freePeers[x]].first); - m_freePeers.erase(m_freePeers.begin() + x); - } + m_freePeers.erase(m_freePeers.begin() + x); } }