-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Handle receiving Discovery packets with changed endpoint #5519
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5519 +/- ##
==========================================
+ Coverage 61.8% 61.89% +0.08%
==========================================
Files 344 344
Lines 28694 28753 +59
Branches 3261 3264 +3
==========================================
+ Hits 17735 17797 +62
+ Misses 9797 9789 -8
- Partials 1162 1167 +5 |
7a9d46b
to
0886a34
Compare
libp2p/NodeTable.cpp
Outdated
@@ -375,10 +376,6 @@ void NodeTable::noteActiveNode(shared_ptr<NodeEntry> _nodeEntry, bi::udp::endpoi | |||
return; | |||
|
|||
LOG(m_logger) << "Active node " << *_nodeEntry; | |||
// TODO: don't activate in case endpoint has changed | |||
_nodeEntry->endpoint.setAddress(_endpoint.address()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is basically moved to Pong handler (lines 513-516), because we should trust changed endpoint only after valid Pong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor suggestions and a few questions
libp2p/NodeTable.cpp
Outdated
@@ -502,6 +499,7 @@ void NodeTable::onPacketReceived( | |||
// create or update nodeEntry with new Pong received time | |||
DEV_GUARDED(x_nodes) | |||
{ | |||
auto const& sourceId = pong.sourceid; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already get the sourceId from the pong packet:
Lines 489 to 490 in 0886a34
// in case the node answers with new NodeID, drop the record with the old NodeID | |
auto const& sourceId = pong.sourceid; |
@@ -512,6 +510,10 @@ void NodeTable::onPacketReceived( | |||
sourceNodeEntry = it->second; | |||
sourceNodeEntry->lastPongReceivedTime = | |||
RLPXDatagramFace::secondsSinceEpoch(); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is good practice but do you know if we ever actually hit this case? It seems like we wouldn't given that pongs have to be received within 1 minute of the ping being sent to be considered valid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how it is related to Pong timeout, this is the case when there is a record in the bucket of the node table (maybe added long ago), but we receive a valid Pong with the same NodeID but from another endpoint.
libp2p/NodeTable.cpp
Outdated
@@ -537,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."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we log both endpoints here?
libp2p/NodeTable.cpp
Outdated
@@ -570,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."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we log both endpoints here?
test/unittests/libp2p/net.cpp
Outdated
auto findNode = dynamic_cast<FindNode const&>(*findNodeDatagram); | ||
|
||
// send Neighbours through endpoint 2 | ||
// TODO fill nearest with one node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO? I think you already do this?
test/unittests/libp2p/net.cpp
Outdated
NodeIPEndpoint neighbourEndpoint{boost::asio::ip::address::from_string("200.200.200.200"), | ||
c_defaultListenPort, c_defaultListenPort}; | ||
vector<shared_ptr<NodeEntry>> nearest{make_shared<NodeEntry>(nodeTable->m_hostNodeID, | ||
KeyPair::create().pub(), neighbourEndpoint, RLPXDatagramFace::secondsSinceEpoch(), 0)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to comment the 0, especially since there are a lot of ctor args
test/unittests/libp2p/net.cpp
Outdated
c_defaultListenPort, c_defaultListenPort}; | ||
vector<shared_ptr<NodeEntry>> nearest{make_shared<NodeEntry>(nodeTable->m_hostNodeID, | ||
KeyPair::create().pub(), neighbourEndpoint, RLPXDatagramFace::secondsSinceEpoch(), 0)}; | ||
Neighbours neighbours(nodeTable->m_hostNodeEndpoint, nearest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Nit) {} initializers
test/unittests/libp2p/net.cpp
Outdated
nodeSocketHost2.socket->send(neighbours); | ||
|
||
// Wait for Neighbours to be received | ||
nodeTable->packetsReceived.pop(chrono::seconds(5)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we validate the received packet?
Addresses review issues, rebased and added CHANGELOG entry. |
Fixes #5455