Browse Source

gracefully handle old pingnode packet

cl-refactor
subtly 10 years ago
parent
commit
887cdf4bfb
  1. 2
      libp2p/NodeTable.h
  2. 2
      libp2p/UDP.h
  3. 11
      test/net.cpp

2
libp2p/NodeTable.h

@ -316,7 +316,7 @@ struct PingNode: RLPXDatagram<PingNode>
static const uint8_t type = 1; static const uint8_t type = 1;
unsigned version = dev::p2p::c_protocolVersion; unsigned version = 0;
std::string ipAddress; std::string ipAddress;
unsigned port; unsigned port;
unsigned expiration; unsigned expiration;

2
libp2p/UDP.h

@ -77,7 +77,7 @@ template <class T>
struct RLPXDatagram: public RLPXDatagramFace struct RLPXDatagram: public RLPXDatagramFace
{ {
RLPXDatagram(bi::udp::endpoint const& _ep): RLPXDatagramFace(_ep) {} RLPXDatagram(bi::udp::endpoint const& _ep): RLPXDatagramFace(_ep) {}
static T fromBytesConstRef(bi::udp::endpoint const& _ep, bytesConstRef _bytes) { T t(_ep); t.interpretRLP(_bytes); return std::move(t); } static T fromBytesConstRef(bi::udp::endpoint const& _ep, bytesConstRef _bytes) { try { T t(_ep); t.interpretRLP(_bytes); return std::move(t); } catch(...) { T t(_ep); return std::move(t); } }
uint8_t packetType() { return T::type; } uint8_t packetType() { return T::type; }
}; };

11
test/net.cpp

@ -145,6 +145,17 @@ public:
bool success = false; bool success = false;
}; };
BOOST_AUTO_TEST_CASE(badPingNodePacket)
{
// test old versino of pingNode packet w/new
RLPStream s;
s.appendList(3); s << "1.1.1.1" << 30303 << std::chrono::duration_cast<std::chrono::seconds>((std::chrono::system_clock::now() + chrono::seconds(60)).time_since_epoch()).count();
PingNode p((bi::udp::endpoint()));
BOOST_REQUIRE_NO_THROW(p = PingNode::fromBytesConstRef(bi::udp::endpoint(), bytesConstRef(&s.out())));
BOOST_REQUIRE(p.version = 0);
}
BOOST_AUTO_TEST_CASE(test_neighbours_packet) BOOST_AUTO_TEST_CASE(test_neighbours_packet)
{ {
KeyPair k = KeyPair::create(); KeyPair k = KeyPair::create();

Loading…
Cancel
Save