Browse Source

Additional network niceness.

cl-refactor
Gav Wood 10 years ago
parent
commit
0f31e3b317
  1. 2
      alethzero/MainWin.cpp
  2. 6
      libethereum/EthereumHost.cpp
  3. 27
      libethereum/EthereumPeer.cpp
  4. 3
      libethereum/EthereumPeer.h
  5. 1
      libp2p/Common.h
  6. 2
      libp2p/Session.h
  7. 4
      merge.sh

2
alethzero/MainWin.cpp

@ -743,7 +743,7 @@ void Main::refreshNetwork()
ui->peerCount->setText(QString::fromStdString(toString(ps.size())) + " peer(s)");
ui->peers->clear();
for (PeerInfo const& i: ps)
ui->peers->addItem(QString("[%6] %3 ms - %1:%2 - %4 %5").arg(i.host.c_str()).arg(i.port).arg(chrono::duration_cast<chrono::milliseconds>(i.lastPing).count()).arg(i.clientVersion.c_str()).arg(QString::fromStdString(toString(i.caps))).arg(i.socket));
ui->peers->addItem(QString("[%7] %3 ms - %1:%2 - %4 %5 %6").arg(i.host.c_str()).arg(i.port).arg(chrono::duration_cast<chrono::milliseconds>(i.lastPing).count()).arg(i.clientVersion.c_str()).arg(QString::fromStdString(toString(i.caps))).arg(QString::fromStdString(toString(i.notes))).arg(i.socket));
}
void Main::refreshAll()

6
libethereum/EthereumHost.cpp

@ -102,7 +102,7 @@ void EthereumHost::noteHaveChain(EthereumPeer* _from)
if (_from->m_neededBlocks.empty())
{
_from->m_grabbing = Grabbing::Nothing;
_from->setGrabbing(Grabbing::Nothing);
updateGrabbing(Grabbing::Nothing);
return;
}
@ -112,7 +112,7 @@ void EthereumHost::noteHaveChain(EthereumPeer* _from)
if (td < m_chain.details().totalDifficulty || (td == m_chain.details().totalDifficulty && m_chain.currentHash() == _from->m_latestHash))
{
clog(NetNote) << "Difficulty of hashchain not HIGHER. Ignoring.";
_from->m_grabbing = Grabbing::Nothing;
_from->setGrabbing(Grabbing::Nothing);
updateGrabbing(Grabbing::Nothing);
return;
}
@ -123,7 +123,7 @@ void EthereumHost::noteHaveChain(EthereumPeer* _from)
m_man.resetToChain(_from->m_neededBlocks);
m_latestBlockSent = _from->m_latestHash;
_from->m_grabbing = Grabbing::Chain;
_from->setGrabbing(Grabbing::Chain);
updateGrabbing(Grabbing::Chain);
}

27
libethereum/EthereumPeer.cpp

@ -38,6 +38,7 @@ EthereumPeer::EthereumPeer(Session* _s, HostCapabilityFace* _h):
Capability(_s, _h),
m_sub(host()->m_man)
{
setGrabbing(Grabbing::State);
sendStatus();
}
@ -120,11 +121,11 @@ void EthereumPeer::giveUpOnFetch()
if (m_grabbing == Grabbing::Chain || m_grabbing == Grabbing::ChainHelper)
{
host()->noteDoneBlocks(this);
m_grabbing = Grabbing::Nothing;
setGrabbing(Grabbing::Nothing);
}
m_sub.doneFetch();
// NOTE: need to notify of giving up on chain-hashes, too, altering state as necessary.
m_sub.doneFetch();
}
bool EthereumPeer::interpret(RLP const& _r)
@ -244,8 +245,8 @@ bool EthereumPeer::interpret(RLP const& _r)
if (_r.itemCount() == 1)
{
// Couldn't get any from last batch - probably got to this peer's latest block - just give up.
m_sub.doneFetch();
giveUpOnFetch();
if (m_grabbing == Grabbing::Chain || m_grabbing == Grabbing::ChainHelper)
giveUpOnFetch();
break;
}
@ -283,7 +284,8 @@ bool EthereumPeer::interpret(RLP const& _r)
}
}
clogS(NetMessageSummary) << dec << knownParents << "known parents," << unknownParents << "unknown," << used << "used.";
continueGettingChain();
if (m_grabbing == Grabbing::Chain || m_grabbing == Grabbing::ChainHelper)
continueGettingChain();
break;
}
default:
@ -297,13 +299,18 @@ void EthereumPeer::ensureGettingChain()
if (m_grabbing == Grabbing::ChainHelper)
return; // Already asked & waiting for some.
// Switch to ChainHelper otherwise, unless we're already the Chain grabber.
if (m_grabbing != Grabbing::Chain)
setGrabbing(Grabbing::ChainHelper);
continueGettingChain();
}
void EthereumPeer::continueGettingChain()
{
if (m_grabbing != Grabbing::Chain)
m_grabbing = Grabbing::ChainHelper;
// If we're getting the hashes already, then we shouldn't be asking for the chain.
if (m_grabbing == Grabbing::Hashes)
return;
auto blocks = m_sub.nextFetch(c_maxBlocksAsk);
@ -319,3 +326,9 @@ void EthereumPeer::continueGettingChain()
else
giveUpOnFetch();
}
void EthereumPeer::setGrabbing(Grabbing _g)
{
m_grabbing = _g;
session()->addNote("grab", _g == Grabbing::Nothing ? "nothing" : _g == Grabbing::State ? "state" : _g == Grabbing::Hashes ? "hashes" : _g == Grabbing::Chain ? "chain" : _g == Grabbing::ChainHelper ? "chainhelper" : "?");
}

3
libethereum/EthereumPeer.h

@ -71,11 +71,12 @@ private:
void giveUpOnFetch();
void clearKnownTransactions() { std::lock_guard<std::mutex> l(x_knownTransactions); m_knownTransactions.clear(); }
void setGrabbing(Grabbing _g);
unsigned m_protocolVersion;
u256 m_networkId;
Grabbing m_grabbing = Grabbing::State;
Grabbing m_grabbing;
h256 m_latestHash; ///< Peer's latest block's hash.
u256 m_totalDifficulty; ///< Peer's latest block's total difficulty.

1
libp2p/Common.h

@ -96,6 +96,7 @@ struct PeerInfo
std::chrono::steady_clock::duration lastPing;
std::set<std::string> caps;
unsigned socket;
std::map<std::string, std::string> notes;
};
}

2
libp2p/Session.h

@ -71,6 +71,8 @@ public:
void addRating(unsigned _r) { m_rating += _r; }
void addNote(std::string const& _k, std::string const& _v) { m_info.notes[_k] = _v; }
private:
void dropped();
void doRead();

4
merge.sh

@ -0,0 +1,4 @@
#!/bin/bash
git checkout "$1+" && git merge --no-ff develop && git push && git tag -f $1 && git push --tags -f && git checkout develop
Loading…
Cancel
Save