Browse Source

merged upstream

cl-refactor
arkpar 10 years ago
parent
commit
dd2be233ce
  1. 4
      alethzero/DownloadView.cpp
  2. 10
      libdevcore/RangeMask.h
  3. 39
      libethereum/DownloadMan.h
  4. 13
      libethereum/EthereumHost.cpp
  5. 2
      libethereum/EthereumPeer.cpp
  6. 18
      libwhisper/WhisperPeer.cpp
  7. 2
      third/MainWin.cpp

4
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++;
});

10
libdevcore/RangeMask.h

@ -43,7 +43,7 @@ public:
using Range = std::pair<T, T>;
using Ranges = std::vector<Range>;
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<T, T> const& all() const { return m_all; }
class const_iterator

39
libethereum/DownloadMan.h

@ -54,8 +54,9 @@ public:
/// Nothing doing here.
void doneFetch() { resetFetch(); }
RangeMask<unsigned> const& asked() const { Guard l(m_fetch); return m_asked; }
RangeMask<unsigned> 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<unsigned> const& asked() const { return m_asked; }
RangeMask<unsigned> 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<unsigned>(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<unsigned>(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<unsigned> 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<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; }
RangeMask<unsigned> blocksGot() const { ReadGuard l(m_lock); return m_blocksGot; }
private:
mutable SharedMutex x_chain;
mutable SharedMutex m_lock;
h256s m_chain;
RangeMask<unsigned> m_blocksGot;

13
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<EthereumPeer>()->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...

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

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

2
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()

Loading…
Cancel
Save