Browse Source

Make bad protocol disconnects a bit more obvious.

cl-refactor
Gav Wood 10 years ago
parent
commit
1faaed3395
  1. 2
      libethereum/BlockChain.cpp
  2. 8
      libethereum/EthereumPeer.cpp
  3. 4
      libp2p/Session.cpp

2
libethereum/BlockChain.cpp

@ -439,7 +439,7 @@ void BlockChain::checkConsistency()
h256 h((byte const*)it->key().data(), h256::ConstructFromPointer); h256 h((byte const*)it->key().data(), h256::ConstructFromPointer);
auto dh = details(h); auto dh = details(h);
auto p = dh.parent; auto p = dh.parent;
if (p != h256() && p != m_genesisHash) if (p != h256() && p != m_genesisHash) // TODO: for some reason the genesis details with the children get squished. not sure why.
{ {
auto dp = details(p); auto dp = details(p);
if (asserts(contains(dp.children, h))) if (asserts(contains(dp.children, h)))

8
libethereum/EthereumPeer.cpp

@ -287,6 +287,8 @@ void EthereumPeer::attemptSync()
} }
bool EthereumPeer::interpret(unsigned _id, RLP const& _r) bool EthereumPeer::interpret(unsigned _id, RLP const& _r)
{
try
{ {
switch (_id) switch (_id)
{ {
@ -509,5 +511,11 @@ bool EthereumPeer::interpret(unsigned _id, RLP const& _r)
default: default:
return false; return false;
} }
}
catch (std::exception const& _e)
{
clogS(NetWarn) << "Peer causing an exception:" << _e.what() << _r;
}
return true; return true;
} }

4
libp2p/Session.cpp

@ -297,6 +297,7 @@ bool Session::interpret(RLP const& _r)
peerAddress = bi::address_v4(_r[i][0].toHash<FixedHash<4>>().asArray()); peerAddress = bi::address_v4(_r[i][0].toHash<FixedHash<4>>().asArray());
else else
{ {
cwarn << "Received bad peer packet:" << _r;
disconnect(BadProtocol); disconnect(BadProtocol);
return true; return true;
} }
@ -372,7 +373,7 @@ bool Session::interpret(RLP const& _r)
} }
catch (std::exception const& _e) catch (std::exception const& _e)
{ {
clogS(NetWarn) << "Peer causing an exception:" << _e.what(); clogS(NetWarn) << "Peer causing an exception:" << _e.what() << _r;
disconnect(BadProtocol); disconnect(BadProtocol);
return true; return true;
} }
@ -579,6 +580,7 @@ void Session::doRead()
if (!interpret(r)) if (!interpret(r))
{ {
// error - bad protocol // error - bad protocol
clogS(NetWarn) << "Couldn't interpret packet." << RLP(r);
disconnect(BadProtocol); disconnect(BadProtocol);
return; return;
} }

Loading…
Cancel
Save