@@ -675,6 +675,54 @@ BOOST_AUTO_TEST_CASE(validPong)
675675 BOOST_CHECK (addedNode->lastPongReceivedTime > 0 );
676676}
677677
678+ BOOST_AUTO_TEST_CASE (pongWithChangedNodeID)
679+ {
680+ // NodeTable sending PING
681+ TestNodeTableHost nodeTableHost (0 );
682+ nodeTableHost.start ();
683+ auto & nodeTable = nodeTableHost.nodeTable ;
684+ nodeTable->setRequestTimeToLive (std::chrono::seconds (1 ));
685+
686+ // socket receiving PING
687+ TestUDPSocketHost nodeSocketHost{getRandomPortNumber ()};
688+ nodeSocketHost.start ();
689+ uint16_t nodePort = nodeSocketHost.port ;
690+
691+ // add a node to node table, initiating PING
692+ auto nodeEndpoint = NodeIPEndpoint{bi::address::from_string (c_localhostIp), nodePort, nodePort};
693+ auto nodeKeyPair = KeyPair::create ();
694+ auto nodePubKey = nodeKeyPair.pub ();
695+ nodeTable->addNode (Node{nodePubKey, nodeEndpoint});
696+
697+ // handle received PING
698+ auto pingDataReceived = nodeSocketHost.packetsReceived .pop ();
699+ auto pingDatagram =
700+ DiscoveryDatagram::interpretUDP (bi::udp::endpoint{}, dev::ref (pingDataReceived));
701+ auto ping = dynamic_cast <PingNode const &>(*pingDatagram);
702+
703+ // send PONG with different NodeID
704+ Pong pong (nodeTable->m_hostNodeEndpoint );
705+ pong.echo = ping.echo ;
706+ auto newNodeKeyPair = KeyPair::create ();
707+ auto newNodePubKey = newNodeKeyPair.pub ();
708+ pong.sign (newNodeKeyPair.secret ());
709+ nodeSocketHost.socket ->send (pong);
710+
711+ // wait for PONG to be received and handled
712+ nodeTable->packetsReceived .pop ();
713+
714+ BOOST_REQUIRE (nodeTable->nodeExists (newNodeKeyPair.pub ()));
715+ auto addedNode = nodeTable->nodeEntry (newNodePubKey);
716+ BOOST_CHECK (addedNode->lastPongReceivedTime > 0 );
717+
718+ // wait for old node to be kicked out after timeout
719+ this_thread::sleep_for (std::chrono::seconds (6 ));
720+
721+ BOOST_CHECK (!nodeTable->nodeExists (nodePubKey));
722+ auto sentPing = nodeTable->nodeValidation (nodePubKey);
723+ BOOST_CHECK (!sentPing.is_initialized ());
724+ }
725+
678726BOOST_AUTO_TEST_CASE (pingTimeout)
679727{
680728 // NodeTable sending PING
0 commit comments