From 9343c0b0eb85e927c7f969e63beffee0967737de Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Mon, 11 Mar 2019 16:35:47 -0500 Subject: [PATCH 1/5] m_sentPings maps pinged udp::endpoint to NodeValidation --- libp2p/NodeTable.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libp2p/NodeTable.cpp b/libp2p/NodeTable.cpp index f2c498dc8b4..2be0d05fcca 100644 --- a/libp2p/NodeTable.cpp +++ b/libp2p/NodeTable.cpp @@ -502,6 +502,7 @@ void NodeTable::onPacketReceived( // create or update nodeEntry with new Pong received time DEV_GUARDED(x_nodes) { + auto const& sourceId = pong.sourceid; auto it = m_allNodes.find(sourceId); if (it == m_allNodes.end()) sourceNodeEntry = make_shared(m_hostNodeID, sourceId, From a1d3b8d39dec9d12a442bc89531df67016606df2 Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Wed, 13 Mar 2019 09:59:24 -0500 Subject: [PATCH 2/5] Check whether node's endpoint changed when handling discovery packets --- libp2p/NodeTable.cpp | 33 ++++--- libp2p/NodeTable.h | 2 +- test/unittests/libp2p/net.cpp | 156 +++++++++++++++++++++++++++------- 3 files changed, 149 insertions(+), 42 deletions(-) diff --git a/libp2p/NodeTable.cpp b/libp2p/NodeTable.cpp index 2be0d05fcca..389028b2e19 100644 --- a/libp2p/NodeTable.cpp +++ b/libp2p/NodeTable.cpp @@ -83,7 +83,8 @@ bool NodeTable::addNode(Node const& _node) DEV_GUARDED(x_nodes) { auto const it = m_allNodes.find(_node.id); - needToPing = (it == m_allNodes.end() || !it->second->hasValidEndpointProof()); + needToPing = (it == m_allNodes.end() || it->second->endpoint != _node.endpoint || + !it->second->hasValidEndpointProof()); } if (needToPing) @@ -115,7 +116,7 @@ bool NodeTable::addKnownNode( if (entry->hasValidEndpointProof()) { LOG(m_logger) << "Known " << _node; - noteActiveNode(move(entry), _node.endpoint); + noteActiveNode(move(entry)); } else { @@ -355,7 +356,7 @@ void NodeTable::evict(NodeEntry const& _leastSeen, shared_ptr _replac m_nodeEventHandler->appendEvent(_leastSeen.id(), NodeEntryScheduledForEviction); } -void NodeTable::noteActiveNode(shared_ptr _nodeEntry, bi::udp::endpoint const& _endpoint) +void NodeTable::noteActiveNode(shared_ptr _nodeEntry) { assert(_nodeEntry); @@ -364,7 +365,7 @@ void NodeTable::noteActiveNode(shared_ptr _nodeEntry, bi::udp::endpoi LOG(m_logger) << "Skipping making self active."; return; } - if (!isAllowedEndpoint(NodeIPEndpoint(_endpoint.address(), _endpoint.port(), _endpoint.port()))) + if (!isAllowedEndpoint(_nodeEntry->endpoint)) { LOG(m_logger) << "Skipping making node with unallowed endpoint active. Node " << _nodeEntry->node; @@ -374,11 +375,7 @@ void NodeTable::noteActiveNode(shared_ptr _nodeEntry, bi::udp::endpoi if (!_nodeEntry->hasValidEndpointProof()) return; - LOG(m_logger) << "Active node " << _nodeEntry->node; - // TODO: don't activate in case endpoint has changed - _nodeEntry->node.endpoint.setAddress(_endpoint.address()); - _nodeEntry->node.endpoint.setUdpPort(_endpoint.port()); - + LOG(m_logger) << "Active node " << *_nodeEntry; shared_ptr nodeToEvict; { @@ -513,6 +510,10 @@ void NodeTable::onPacketReceived( sourceNodeEntry = it->second; sourceNodeEntry->lastPongReceivedTime = RLPXDatagramFace::secondsSinceEpoch(); + + if (sourceNodeEntry->endpoint != _from) + sourceNodeEntry->endpoint = NodeIPEndpoint{ + _from.address(), _from.port(), nodeValidation.tcpPort}; } } @@ -538,6 +539,11 @@ void NodeTable::onPacketReceived( << ") not found in node table. Ignoring Neighbours packet."; return; } + if (sourceNodeEntry->endpoint != _from) + { + LOG(m_logger) << "Neighbours packet from unexpected endpoint."; + return; + } auto const& in = dynamic_cast(*packet); @@ -571,6 +577,11 @@ void NodeTable::onPacketReceived( << ") not found in node table. Ignoring FindNode request."; return; } + if (sourceNodeEntry->endpoint != _from) + { + LOG(m_logger) << "FindNode packet from unexpected endpoint."; + return; + } if (!sourceNodeEntry->lastPongReceivedTime) { LOG(m_logger) << "Unexpected FindNode packet! Endpoint proof hasn't been performed yet."; @@ -627,7 +638,7 @@ void NodeTable::onPacketReceived( } if (sourceNodeEntry) - noteActiveNode(move(sourceNodeEntry), _from); + noteActiveNode(move(sourceNodeEntry)); } catch (exception const& _e) { @@ -711,7 +722,7 @@ void NodeTable::doHandleTimeouts() // activate replacement nodes and put them into buckets for (auto const& n : nodesToActivate) - noteActiveNode(n, n->endpoint()); + doHandleTimeouts(); }); diff --git a/libp2p/NodeTable.h b/libp2p/NodeTable.h index 08e01f5d071..0725e1ea2bd 100644 --- a/libp2p/NodeTable.h +++ b/libp2p/NodeTable.h @@ -261,7 +261,7 @@ class NodeTable : UDPSocketEvents /// Called whenever activity is received from a node in order to maintain node table. Only /// called for nodes for which we've completed an endpoint proof. - void noteActiveNode(std::shared_ptr _nodeEntry, bi::udp::endpoint const& _endpoint); + void noteActiveNode(std::shared_ptr _nodeEntry); /// Used to drop node when timeout occurs or when evict() result is to keep previous node. void dropNode(std::shared_ptr _n); diff --git a/test/unittests/libp2p/net.cpp b/test/unittests/libp2p/net.cpp index 03301da9f71..4f95aa219a2 100644 --- a/test/unittests/libp2p/net.cpp +++ b/test/unittests/libp2p/net.cpp @@ -79,7 +79,7 @@ struct TestNodeTable: public NodeTable auto entry = make_shared(m_hostNodeID, n.first, NodeIPEndpoint(ourIp, n.second, n.second), RLPXDatagramFace::secondsSinceEpoch(), RLPXDatagramFace::secondsSinceEpoch()); - noteActiveNode(move(entry), bi::udp::endpoint(ourIp, n.second)); + noteActiveNode(move(entry)); } else break; @@ -100,7 +100,7 @@ struct TestNodeTable: public NodeTable NodeIPEndpoint(ourIp, testNode->second, testNode->second), RLPXDatagramFace::secondsSinceEpoch(), RLPXDatagramFace::secondsSinceEpoch())); auto distance = node->distance; - noteActiveNode(move(node), bi::udp::endpoint(ourIp, testNode->second)); + noteActiveNode(move(node)); { Guard stateGuard(x_state); @@ -138,7 +138,7 @@ struct TestNodeTable: public NodeTable auto entry = make_shared(m_hostNodeID, testNode->first, NodeIPEndpoint(ourIp, testNode->second, testNode->second), RLPXDatagramFace::secondsSinceEpoch(), RLPXDatagramFace::secondsSinceEpoch()); - noteActiveNode(move(entry), bi::udp::endpoint(ourIp, testNode->second)); + noteActiveNode(move(entry)); ++testNode; } @@ -500,7 +500,7 @@ BOOST_AUTO_TEST_CASE(noteActiveNodeUpdatesKnownNode) auto& nodeTable = nodeTableHost.nodeTable; auto knownNode = nodeTable->bucketFirstNode(bucketIndex); - nodeTable->noteActiveNode(knownNode, knownNode->endpoint()); + nodeTable->noteActiveNode(knownNode); // check that node was moved to the back of the bucket BOOST_CHECK_NE(nodeTable->bucketFirstNode(bucketIndex), knownNode); @@ -550,32 +550,6 @@ BOOST_AUTO_TEST_CASE(noteActiveNodeEvictsTheNodeWhenBucketIsFull) BOOST_CHECK_EQUAL(evicted->replacementNodeEntry->id(), newNodeId); } -BOOST_AUTO_TEST_CASE(noteActiveNodeReplacesNodeInFullBucketWhenEndpointChanged) -{ - TestNodeTableHost nodeTableHost(512); - int const bucketIndex = nodeTableHost.populateUntilBucketSize(16); - BOOST_REQUIRE(bucketIndex >= 0); - - auto& nodeTable = nodeTableHost.nodeTable; - auto leastRecentlySeenNode = nodeTable->bucketFirstNode(bucketIndex); - - // addNode will replace the node in the m_allNodes map, because it's the same id with enother - // endpoint - auto const port = randomPortNumber(); - NodeIPEndpoint newEndpoint{bi::address::from_string(c_localhostIp), port, port }; - nodeTable->noteActiveNode(leastRecentlySeenNode, newEndpoint); - - // the bucket is still max size - BOOST_CHECK_EQUAL(nodeTable->bucketSize(bucketIndex), 16); - // least recently seen node removed - BOOST_CHECK_NE(nodeTable->bucketFirstNode(bucketIndex)->id(), leastRecentlySeenNode->id()); - // but added as most recently seen with new endpoint - auto mostRecentNodeEntry = nodeTable->bucketLastNode(bucketIndex); - BOOST_CHECK_EQUAL(mostRecentNodeEntry->id(), leastRecentlySeenNode->id()); - BOOST_CHECK_EQUAL(mostRecentNodeEntry->endpoint().address(), newEndpoint.address()); - BOOST_CHECK_EQUAL(mostRecentNodeEntry->endpoint().udpPort(), newEndpoint.udpPort()); -} - BOOST_AUTO_TEST_CASE(unexpectedPong) { // NodeTable receiving PONG @@ -1173,6 +1147,128 @@ BOOST_AUTO_TEST_CASE(addNodePingsNodeOnlyOnce) BOOST_REQUIRE_EQUAL(sentPing->pingHash, sentPing2->pingHash); } +class PacketsWithChangedEndpointFixture : public TestOutputHelperFixture +{ +public: + PacketsWithChangedEndpointFixture() + { + nodeTableHost.start(); + nodeSocketHost1.start(); + nodePort1 = nodeSocketHost1.port; + nodeSocketHost2.start(); + nodePort2 = nodeSocketHost2.port; + + nodeEndpoint1 = + NodeIPEndpoint{bi::address::from_string(c_localhostIp), nodePort1, nodePort1}; + nodeEndpoint2 = + NodeIPEndpoint{bi::address::from_string(c_localhostIp), nodePort2, nodePort2}; + + // add a node to node table, initiating PING + nodeTable->addNode(Node{nodePubKey, nodeEndpoint1}); + + // handle received PING + auto pingDataReceived = nodeSocketHost1.packetsReceived.pop(); + auto pingDatagram = + DiscoveryDatagram::interpretUDP(bi::udp::endpoint{}, dev::ref(pingDataReceived)); + auto ping = dynamic_cast(*pingDatagram); + + // send PONG + Pong pong(nodeTable->m_hostNodeEndpoint); + pong.echo = ping.echo; + pong.sign(nodeKeyPair.secret()); + nodeSocketHost1.socket->send(pong); + + // wait for PONG to be received and handled + nodeTable->packetsReceived.pop(chrono::seconds(5)); + + nodeEntry = nodeTable->nodeEntry(nodePubKey); + } + + TestNodeTableHost nodeTableHost{0}; + shared_ptr& nodeTable = nodeTableHost.nodeTable; + + // socket representing initial peer node + TestUDPSocketHost nodeSocketHost1; + uint16_t nodePort1 = 0; + + // socket representing peer with changed endpoint + TestUDPSocketHost nodeSocketHost2; + uint16_t nodePort2 = 0; + + NodeIPEndpoint nodeEndpoint1; + NodeIPEndpoint nodeEndpoint2; + KeyPair nodeKeyPair = KeyPair::create(); + NodeID nodePubKey = nodeKeyPair.pub(); + + shared_ptr nodeEntry; +}; + +BOOST_FIXTURE_TEST_SUITE(packetsWithChangedEndpointSuite, PacketsWithChangedEndpointFixture) + +BOOST_AUTO_TEST_CASE(addNode) +{ + // this should initiate Ping to endpoint 2 + nodeTable->addNode(Node{nodePubKey, nodeEndpoint2}); + + // handle received PING + auto pingDataReceived = nodeSocketHost2.packetsReceived.pop(); + auto pingDatagram = + DiscoveryDatagram::interpretUDP(bi::udp::endpoint{}, dev::ref(pingDataReceived)); + auto ping = dynamic_cast(*pingDatagram); + + // send PONG + Pong pong(nodeTable->m_hostNodeEndpoint); + pong.echo = ping.echo; + pong.sign(nodeKeyPair.secret()); + nodeSocketHost2.socket->send(pong); + + // wait for PONG to be received and handled + nodeTable->packetsReceived.pop(chrono::seconds(5)); + + BOOST_REQUIRE_EQUAL(nodeEntry->endpoint, nodeEndpoint2); +} + +BOOST_AUTO_TEST_CASE(findNode) +{ + // Create and send the FindNode packet through endpoint 2 + FindNode findNode(nodeTable->m_hostNodeEndpoint, KeyPair::create().pub() /* target */); + findNode.sign(nodeKeyPair.secret()); + nodeSocketHost2.socket->send(findNode); + + // Wait for FindNode to be received + nodeTable->packetsReceived.pop(chrono::seconds(5)); + + // Verify that no neighbours response is received + BOOST_CHECK_THROW(nodeSocketHost2.packetsReceived.pop(chrono::seconds(5)), WaitTimeout); +} + +BOOST_AUTO_TEST_CASE(neighbours) +{ + // Wait for FindNode arriving to endpoint 1 + auto findNodeDataReceived = nodeSocketHost1.packetsReceived.pop(chrono::seconds(10)); + auto findNodeDatagram = + DiscoveryDatagram::interpretUDP(bi::udp::endpoint{}, dev::ref(findNodeDataReceived)); + auto findNode = dynamic_cast(*findNodeDatagram); + + // send Neighbours through endpoint 2 + // TODO fill nearest with one node + NodeIPEndpoint neighbourEndpoint{boost::asio::ip::address::from_string("200.200.200.200"), + c_defaultListenPort, c_defaultListenPort}; + vector> nearest{make_shared(nodeTable->m_hostNodeID, + KeyPair::create().pub(), neighbourEndpoint, RLPXDatagramFace::secondsSinceEpoch(), 0)}; + Neighbours neighbours(nodeTable->m_hostNodeEndpoint, nearest); + neighbours.sign(nodeKeyPair.secret()); + nodeSocketHost2.socket->send(neighbours); + + // Wait for Neighbours to be received + nodeTable->packetsReceived.pop(chrono::seconds(5)); + + // no Ping is sent to neighbour + auto sentPing = nodeTable->nodeValidation(neighbourEndpoint); + BOOST_REQUIRE(!sentPing.is_initialized()); +} + +BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END() BOOST_FIXTURE_TEST_SUITE(netTypes, TestOutputHelperFixture) From 5719e7d7ff109a6a5cef2669ff9ba31bce099309 Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Mon, 25 Mar 2019 14:54:11 +0100 Subject: [PATCH 3/5] Minor improvements --- libp2p/NodeTable.cpp | 7 ++++--- test/unittests/libp2p/net.cpp | 34 +++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/libp2p/NodeTable.cpp b/libp2p/NodeTable.cpp index 389028b2e19..5e772fd4548 100644 --- a/libp2p/NodeTable.cpp +++ b/libp2p/NodeTable.cpp @@ -499,7 +499,6 @@ void NodeTable::onPacketReceived( // create or update nodeEntry with new Pong received time DEV_GUARDED(x_nodes) { - auto const& sourceId = pong.sourceid; auto it = m_allNodes.find(sourceId); if (it == m_allNodes.end()) sourceNodeEntry = make_shared(m_hostNodeID, sourceId, @@ -541,7 +540,8 @@ void NodeTable::onPacketReceived( } if (sourceNodeEntry->endpoint != _from) { - LOG(m_logger) << "Neighbours packet from unexpected endpoint."; + LOG(m_logger) << "Neighbours packet from unexpected endpoint " << _from + << " instead of " << sourceNodeEntry->endpoint; return; } @@ -579,7 +579,8 @@ void NodeTable::onPacketReceived( } if (sourceNodeEntry->endpoint != _from) { - LOG(m_logger) << "FindNode packet from unexpected endpoint."; + LOG(m_logger) << "FindNode packet from unexpected endpoint " << _from + << " instead of " << sourceNodeEntry->endpoint; return; } if (!sourceNodeEntry->lastPongReceivedTime) diff --git a/test/unittests/libp2p/net.cpp b/test/unittests/libp2p/net.cpp index 4f95aa219a2..dba286c0423 100644 --- a/test/unittests/libp2p/net.cpp +++ b/test/unittests/libp2p/net.cpp @@ -1167,13 +1167,14 @@ class PacketsWithChangedEndpointFixture : public TestOutputHelperFixture nodeTable->addNode(Node{nodePubKey, nodeEndpoint1}); // handle received PING - auto pingDataReceived = nodeSocketHost1.packetsReceived.pop(); + auto pingDataReceived = nodeSocketHost1.packetsReceived.pop(chrono::seconds(5)); auto pingDatagram = DiscoveryDatagram::interpretUDP(bi::udp::endpoint{}, dev::ref(pingDataReceived)); + BOOST_REQUIRE_EQUAL(pingDatagram->typeName(), "Ping"); auto ping = dynamic_cast(*pingDatagram); // send PONG - Pong pong(nodeTable->m_hostNodeEndpoint); + Pong pong{nodeTable->m_hostNodeEndpoint}; pong.echo = ping.echo; pong.sign(nodeKeyPair.secret()); nodeSocketHost1.socket->send(pong); @@ -1214,16 +1215,20 @@ BOOST_AUTO_TEST_CASE(addNode) auto pingDataReceived = nodeSocketHost2.packetsReceived.pop(); auto pingDatagram = DiscoveryDatagram::interpretUDP(bi::udp::endpoint{}, dev::ref(pingDataReceived)); + BOOST_REQUIRE_EQUAL(pingDatagram->typeName(), "Ping"); auto ping = dynamic_cast(*pingDatagram); // send PONG - Pong pong(nodeTable->m_hostNodeEndpoint); + Pong pong{nodeTable->m_hostNodeEndpoint}; pong.echo = ping.echo; pong.sign(nodeKeyPair.secret()); nodeSocketHost2.socket->send(pong); // wait for PONG to be received and handled - nodeTable->packetsReceived.pop(chrono::seconds(5)); + auto pongDataReceived = nodeTable->packetsReceived.pop(chrono::seconds(5)); + auto pongDatagram = + DiscoveryDatagram::interpretUDP(bi::udp::endpoint{}, dev::ref(pongDataReceived)); + BOOST_REQUIRE_EQUAL(pongDatagram->typeName(), "Pong"); BOOST_REQUIRE_EQUAL(nodeEntry->endpoint, nodeEndpoint2); } @@ -1231,12 +1236,15 @@ BOOST_AUTO_TEST_CASE(addNode) BOOST_AUTO_TEST_CASE(findNode) { // Create and send the FindNode packet through endpoint 2 - FindNode findNode(nodeTable->m_hostNodeEndpoint, KeyPair::create().pub() /* target */); + FindNode findNode{nodeTable->m_hostNodeEndpoint, KeyPair::create().pub() /* target */}; findNode.sign(nodeKeyPair.secret()); nodeSocketHost2.socket->send(findNode); // Wait for FindNode to be received - nodeTable->packetsReceived.pop(chrono::seconds(5)); + auto findNodeDataReceived = nodeTable->packetsReceived.pop(chrono::seconds(5)); + auto findNodeDatagram = + DiscoveryDatagram::interpretUDP(bi::udp::endpoint{}, dev::ref(findNodeDataReceived)); + BOOST_REQUIRE_EQUAL(findNodeDatagram->typeName(), "FindNode"); // Verify that no neighbours response is received BOOST_CHECK_THROW(nodeSocketHost2.packetsReceived.pop(chrono::seconds(5)), WaitTimeout); @@ -1248,20 +1256,24 @@ BOOST_AUTO_TEST_CASE(neighbours) auto findNodeDataReceived = nodeSocketHost1.packetsReceived.pop(chrono::seconds(10)); auto findNodeDatagram = DiscoveryDatagram::interpretUDP(bi::udp::endpoint{}, dev::ref(findNodeDataReceived)); + BOOST_REQUIRE_EQUAL(findNodeDatagram->typeName(), "FindNode"); auto findNode = dynamic_cast(*findNodeDatagram); // send Neighbours through endpoint 2 - // TODO fill nearest with one node NodeIPEndpoint neighbourEndpoint{boost::asio::ip::address::from_string("200.200.200.200"), c_defaultListenPort, c_defaultListenPort}; - vector> nearest{make_shared(nodeTable->m_hostNodeID, - KeyPair::create().pub(), neighbourEndpoint, RLPXDatagramFace::secondsSinceEpoch(), 0)}; - Neighbours neighbours(nodeTable->m_hostNodeEndpoint, nearest); + vector> nearest{ + make_shared(nodeTable->m_hostNodeID, KeyPair::create().pub(), neighbourEndpoint, + RLPXDatagramFace::secondsSinceEpoch(), 0 /* pongSentTime */)}; + Neighbours neighbours{nodeTable->m_hostNodeEndpoint, nearest}; neighbours.sign(nodeKeyPair.secret()); nodeSocketHost2.socket->send(neighbours); // Wait for Neighbours to be received - nodeTable->packetsReceived.pop(chrono::seconds(5)); + auto neighboursDataReceived = nodeTable->packetsReceived.pop(chrono::seconds(5)); + auto neighboursDatagram = + DiscoveryDatagram::interpretUDP(bi::udp::endpoint{}, dev::ref(neighboursDataReceived)); + BOOST_REQUIRE_EQUAL(neighboursDatagram->typeName(), "Neighbours"); // no Ping is sent to neighbour auto sentPing = nodeTable->nodeValidation(neighbourEndpoint); From bca8cb629dbcfa49847760840cbefef818c87dd3 Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Mon, 25 Mar 2019 14:58:16 +0100 Subject: [PATCH 4/5] Add changelog message --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c1e05e7e9d..d54fdcd5a52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,5 +10,6 @@ - Fixed: [#5512](https://github.com/ethereum/aleth/pull/5512) Calling `eth_call` without `from` argument. - Fixed: [#5502](https://github.com/ethereum/aleth/pull/5502) Fix Discovery terminating prematurely because of race condition. - Fixed: [#5452](https://github.com/ethereum/aleth/pull/5452) Correctly handle Discovery messages when the peer changes public key. +- Fixed: [#5519](https://github.com/ethereum/aleth/pull/5519) Correctly handle Discovery messages with known public key but unknown endpoint. [1.6.0]: https://github.com/ethereum/aleth/compare/v1.6.0-alpha.1...master \ No newline at end of file From 28984b48427cfdd82998ddefb062e240c1d5a0bf Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Tue, 26 Mar 2019 11:48:27 +0100 Subject: [PATCH 5/5] Fix build after bad rebase --- libp2p/NodeTable.cpp | 20 ++++++++++---------- test/unittests/libp2p/net.cpp | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libp2p/NodeTable.cpp b/libp2p/NodeTable.cpp index 5e772fd4548..0917b40460e 100644 --- a/libp2p/NodeTable.cpp +++ b/libp2p/NodeTable.cpp @@ -83,7 +83,7 @@ bool NodeTable::addNode(Node const& _node) DEV_GUARDED(x_nodes) { auto const it = m_allNodes.find(_node.id); - needToPing = (it == m_allNodes.end() || it->second->endpoint != _node.endpoint || + needToPing = (it == m_allNodes.end() || it->second->endpoint() != _node.endpoint || !it->second->hasValidEndpointProof()); } @@ -365,7 +365,7 @@ void NodeTable::noteActiveNode(shared_ptr _nodeEntry) LOG(m_logger) << "Skipping making self active."; return; } - if (!isAllowedEndpoint(_nodeEntry->endpoint)) + if (!isAllowedEndpoint(_nodeEntry->endpoint())) { LOG(m_logger) << "Skipping making node with unallowed endpoint active. Node " << _nodeEntry->node; @@ -375,7 +375,7 @@ void NodeTable::noteActiveNode(shared_ptr _nodeEntry) if (!_nodeEntry->hasValidEndpointProof()) return; - LOG(m_logger) << "Active node " << *_nodeEntry; + LOG(m_logger) << "Active node " << _nodeEntry->node; shared_ptr nodeToEvict; { @@ -510,8 +510,8 @@ void NodeTable::onPacketReceived( sourceNodeEntry->lastPongReceivedTime = RLPXDatagramFace::secondsSinceEpoch(); - if (sourceNodeEntry->endpoint != _from) - sourceNodeEntry->endpoint = NodeIPEndpoint{ + if (sourceNodeEntry->endpoint() != _from) + sourceNodeEntry->node.endpoint = NodeIPEndpoint{ _from.address(), _from.port(), nodeValidation.tcpPort}; } } @@ -538,10 +538,10 @@ void NodeTable::onPacketReceived( << ") not found in node table. Ignoring Neighbours packet."; return; } - if (sourceNodeEntry->endpoint != _from) + if (sourceNodeEntry->endpoint() != _from) { LOG(m_logger) << "Neighbours packet from unexpected endpoint " << _from - << " instead of " << sourceNodeEntry->endpoint; + << " instead of " << sourceNodeEntry->endpoint(); return; } @@ -577,10 +577,10 @@ void NodeTable::onPacketReceived( << ") not found in node table. Ignoring FindNode request."; return; } - if (sourceNodeEntry->endpoint != _from) + if (sourceNodeEntry->endpoint() != _from) { LOG(m_logger) << "FindNode packet from unexpected endpoint " << _from - << " instead of " << sourceNodeEntry->endpoint; + << " instead of " << sourceNodeEntry->endpoint(); return; } if (!sourceNodeEntry->lastPongReceivedTime) @@ -723,7 +723,7 @@ void NodeTable::doHandleTimeouts() // activate replacement nodes and put them into buckets for (auto const& n : nodesToActivate) - + noteActiveNode(n); doHandleTimeouts(); }); diff --git a/test/unittests/libp2p/net.cpp b/test/unittests/libp2p/net.cpp index dba286c0423..b62bc591861 100644 --- a/test/unittests/libp2p/net.cpp +++ b/test/unittests/libp2p/net.cpp @@ -1230,7 +1230,7 @@ BOOST_AUTO_TEST_CASE(addNode) DiscoveryDatagram::interpretUDP(bi::udp::endpoint{}, dev::ref(pongDataReceived)); BOOST_REQUIRE_EQUAL(pongDatagram->typeName(), "Pong"); - BOOST_REQUIRE_EQUAL(nodeEntry->endpoint, nodeEndpoint2); + BOOST_REQUIRE_EQUAL(nodeEntry->endpoint(), nodeEndpoint2); } BOOST_AUTO_TEST_CASE(findNode)