Browse Source

Better NodeTable error detection.

cl-refactor
Gav Wood 10 years ago
parent
commit
22b45721d8
  1. 26
      libp2p/NodeTable.cpp
  2. 6
      libp2p/NodeTable.h

26
libp2p/NodeTable.cpp

@ -578,3 +578,29 @@ void NodeTable::doRefreshBuckets(boost::system::error_code const& _ec)
m_bucketRefreshTimer.async_wait(runcb);
}
void PingNode::streamRLP(RLPStream& _s) const
{
_s.appendList(4);
_s << dev::p2p::c_protocolVersion << ipAddress << port << expiration;
}
void PingNode::interpretRLP(bytesConstRef _bytes)
{
RLP r(_bytes);
if (r.itemCountStrict() == 3)
{
version = 2;
ipAddress = r[0].toString();
port = r[1].toInt<unsigned>(RLP::Strict);
expiration = r[2].toInt<unsigned>(RLP::Strict);
}
else if (r.itemCountStrict() == 4)
{
version = r[0].toInt<unsigned>(RLP::Strict);
ipAddress = r[1].toString();
port = r[2].toInt<unsigned>(RLP::Strict);
expiration = r[3].toInt<unsigned>(RLP::Strict);
}
else
BOOST_THROW_EXCEPTION(InvalidRLP());
}

6
libp2p/NodeTable.h

@ -288,6 +288,8 @@ inline std::ostream& operator<<(std::ostream& _out, NodeTable const& _nodeTable)
return _out;
}
struct InvalidRLP: public Exception {};
/**
* Ping packet: Sent to check if node is alive.
* PingNode is cached and regenerated after expiration - t, where t is timeout.
@ -321,8 +323,8 @@ struct PingNode: RLPXDatagram<PingNode>
unsigned port;
unsigned expiration;
void streamRLP(RLPStream& _s) const { _s.appendList(4); _s << dev::p2p::c_protocolVersion << ipAddress << port << expiration; }
void interpretRLP(bytesConstRef _bytes) { RLP r(_bytes); version = r[0].toInt<unsigned>(); ipAddress = r[1].toString(); port = r[2].toInt<unsigned>(); expiration = r[3].toInt<unsigned>(); }
void streamRLP(RLPStream& _s) const override;
void interpretRLP(bytesConstRef _bytes) override;
};
/**

Loading…
Cancel
Save