Browse Source

Various networking fixes.

cl-refactor
Gav Wood 11 years ago
parent
commit
d60ee48ddd
  1. 18
      alethzero/DownloadView.cpp
  2. 2
      libdevcore/Worker.cpp
  3. 1
      libethereum/DownloadMan.h
  4. 2
      libethereum/EthereumPeer.cpp
  5. 5
      libp2p/Host.cpp

18
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);

2
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";

1
libethereum/DownloadMan.h

@ -120,6 +120,7 @@ public:
h256s chain() const { return m_chain; }
void foreachSub(std::function<void(DownloadSub const&)> 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<unsigned> blocksGot() const { return m_blocksGot; }
private:

2
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;

5
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);
}
}

Loading…
Cancel
Save