diff --git a/alethzero/DownloadView.cpp b/alethzero/DownloadView.cpp index 657727a6a..a6533023c 100644 --- a/alethzero/DownloadView.cpp +++ b/alethzero/DownloadView.cpp @@ -51,7 +51,7 @@ void DownloadView::paintEvent(QPaintEvent*) QSizeF area(n, n); QPointF pos(0, 0); - auto const& bg = m_man->blocksGot(); + auto bg = m_man->blocksGot(); for (unsigned i = bg.all().first, ei = bg.all().second; i < ei; ++i) { @@ -63,7 +63,7 @@ void DownloadView::paintEvent(QPaintEvent*) unsigned h = 0; m_man->foreachSub([&](DownloadSub const& sub) { - if (sub.asked().contains(i)) + if (sub.askedContains(i)) s = h; h++; }); diff --git a/libdevcore/RangeMask.h b/libdevcore/RangeMask.h index f1b0043ff..e6a66776c 100644 --- a/libdevcore/RangeMask.h +++ b/libdevcore/RangeMask.h @@ -43,7 +43,7 @@ public: using Range = std::pair; using Ranges = std::vector; - RangeMask() {} + RangeMask(): m_all(0, 0) {} RangeMask(T _begin, T _end): m_all(_begin, _end) {} RangeMask(Range const& _c): m_all(_c) {} @@ -150,7 +150,7 @@ public: bool full() const { - return m_ranges.size() == 1 && m_ranges.begin()->first == m_all.first && m_ranges.begin()->second == m_all.second; + return m_all.first == m_all.second || (m_ranges.size() == 1 && m_ranges.begin()->first == m_all.first && m_ranges.begin()->second == m_all.second); } void clear() @@ -158,6 +158,12 @@ public: m_ranges.clear(); } + void reset() + { + m_ranges.clear(); + m_all = std::make_pair(0, 0); + } + std::pair const& all() const { return m_all; } class const_iterator diff --git a/libethereum/DownloadMan.h b/libethereum/DownloadMan.h index 382c6aeae..6f4c4bafb 100644 --- a/libethereum/DownloadMan.h +++ b/libethereum/DownloadMan.h @@ -54,8 +54,9 @@ public: /// Nothing doing here. void doneFetch() { resetFetch(); } - RangeMask const& asked() const { Guard l(m_fetch); return m_asked; } - RangeMask const& attemped() const { Guard l(m_fetch); return m_attempted; } + bool askedContains(unsigned _i) const { Guard l(m_fetch); return m_asked.contains(_i); } + RangeMask const& asked() const { return m_asked; } + RangeMask const& attemped() const { return m_attempted; } private: void resetFetch() // Called by DownloadMan when we need to reset the download. @@ -63,8 +64,8 @@ private: Guard l(m_fetch); m_remaining.clear(); m_indices.clear(); - m_asked.clear(); - m_attempted.clear(); + m_asked.reset(); + m_attempted.reset(); } DownloadMan* m_man = nullptr; @@ -94,14 +95,12 @@ public: for (auto i: m_subs) i->resetFetch(); } - { - WriteGuard l(x_chain); - m_chain.clear(); - m_chain.reserve(_chain.size()); - for (auto i = _chain.rbegin(); i != _chain.rend(); ++i) - m_chain.push_back(*i); - m_blocksGot = RangeMask(0, m_chain.size()); - } + WriteGuard l(m_lock); + m_chain.clear(); + m_chain.reserve(_chain.size()); + for (auto i = _chain.rbegin(); i != _chain.rend(); ++i) + m_chain.push_back(*i); + m_blocksGot = RangeMask(0, m_chain.size()); } void reset() @@ -111,15 +110,14 @@ public: for (auto i: m_subs) i->resetFetch(); } - { - WriteGuard l(x_chain); - m_chain.clear(); - m_blocksGot.clear(); - } + WriteGuard l(m_lock); + m_chain.clear(); + m_blocksGot.reset(); } RangeMask taken(bool _desperate = false) const { + ReadGuard l(m_lock); auto ret = m_blocksGot; if (!_desperate) { @@ -132,16 +130,17 @@ public: bool isComplete() const { + ReadGuard l(m_lock); return m_blocksGot.full(); } - h256s chain() const { ReadGuard l(x_chain); return m_chain; } + h256s chain() const { ReadGuard l(m_lock); 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; } + RangeMask blocksGot() const { ReadGuard l(m_lock); return m_blocksGot; } private: - mutable SharedMutex x_chain; + mutable SharedMutex m_lock; h256s m_chain; RangeMask m_blocksGot; diff --git a/libethereum/EthereumHost.cpp b/libethereum/EthereumHost.cpp index de0e991e6..e7e80c28a 100644 --- a/libethereum/EthereumHost.cpp +++ b/libethereum/EthereumHost.cpp @@ -74,12 +74,19 @@ void EthereumHost::noteHavePeerState(EthereumPeer* _who) { clog(NetAllDetail) << "Have peer state."; + // TODO: FIX: BUG: Better state management! + // if already downloading hash-chain, ignore. if (m_grabbing != Grabbing::Nothing) { - clog(NetAllDetail) << "Already downloading chain. Just set to help out."; - _who->ensureGettingChain(); - return; + for (auto const& i: peers()) + if (i->cap()->m_grabbing == m_grabbing || m_grabbing == Grabbing::State) + { + clog(NetAllDetail) << "Already downloading chain. Just set to help out."; + _who->ensureGettingChain(); + return; + } + m_grabbing = Grabbing::Nothing; } // otherwise check to see if we should be downloading... diff --git a/libethereum/EthereumPeer.cpp b/libethereum/EthereumPeer.cpp index d7d69187d..b45abfbff 100644 --- a/libethereum/EthereumPeer.cpp +++ b/libethereum/EthereumPeer.cpp @@ -115,7 +115,7 @@ void EthereumPeer::tryGrabbingHashChain() void EthereumPeer::giveUpOnFetch() { - clogS(NetNote) << "GIVE UP FETCH"; + clogS(NetNote) << "Finishing 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 || m_grabbing == Grabbing::ChainHelper) diff --git a/libwhisper/WhisperPeer.cpp b/libwhisper/WhisperPeer.cpp index 4baccdf9c..e92e2cac3 100644 --- a/libwhisper/WhisperPeer.cpp +++ b/libwhisper/WhisperPeer.cpp @@ -92,15 +92,17 @@ void WhisperPeer::sendMessages() n++; } - // pause before sending if no messages to send - if (!n) + if (n) + { + RLPStream s; + prep(s); + s.appendList(n + 1) << MessagesPacket; + s.appendRaw(amalg.out(), n); + sealAndSend(s); + } + else + // just pause if no messages to send this_thread::sleep_for(chrono::milliseconds(100)); - - RLPStream s; - prep(s); - s.appendList(n + 1) << MessagesPacket; - s.appendRaw(amalg.out(), n); - sealAndSend(s); } void WhisperPeer::noteNewMessage(h256 _h, Message const& _m) diff --git a/third/MainWin.cpp b/third/MainWin.cpp index 5305abc12..10f07ef6a 100644 --- a/third/MainWin.cpp +++ b/third/MainWin.cpp @@ -347,7 +347,7 @@ QString Main::lookup(QString const& _a) const void Main::on_about_triggered() { - QMessageBox::about(this, "About Third PoC-" + QString(dev::Version).section('.', 1, 1), QString("Third/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM) "\n" DEV_QUOTED(ETH_COMMIT_HASH) + (ETH_CLEAN_REPO ? "\nCLEAN" : "\n+ LOCAL CHANGES") + "\n\nBy Gav Wood, 2014.\nBased on a design by Vitalik Buterin.\n\nThanks to the various contributors including: Alex Leverington, Tim Hughes, caktux, Eric Lombrozo, Marko Simovic."); + QMessageBox::about(this, "About Third PoC-" + QString(dev::Version).section('.', 1, 1), QString("Third/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM) "\n" DEV_QUOTED(ETH_COMMIT_HASH) + (ETH_CLEAN_REPO ? "\nCLEAN" : "\n+ LOCAL CHANGES") + "\n\nBy Gav Wood, 2014.\nThis software wouldn't be where it is today without the many leaders & contributors including:\n\nVitalik Buterin, Tim Hughes, caktux, Nick Savers, Eric Lombrozo, Marko Simovic, the many testers and the Berlin \304\220\316\236V team."); } void Main::writeSettings()