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
|
|
||
| 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.
This part is basically moved to Pong handler (lines 513-516), because we should trust changed endpoint only after valid Pong
libp2p/NodeTable.cpp
Outdated
| // 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.
We already get the sourceId from the pong packet:
Lines 489 to 490 in 0886a34
| sourceNodeEntry = it->second; | ||
| sourceNodeEntry->lastPongReceivedTime = | ||
| RLPXDatagramFace::secondsSinceEpoch(); | ||
|
|
There was a problem hiding this comment.
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.
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
| } | ||
| if (sourceNodeEntry->endpoint != _from) | ||
| { | ||
| LOG(m_logger) << "Neighbours packet from unexpected endpoint."; |
There was a problem hiding this comment.
Should we log both endpoints here?
libp2p/NodeTable.cpp
Outdated
| } | ||
| if (sourceNodeEntry->endpoint != _from) | ||
| { | ||
| LOG(m_logger) << "FindNode packet from unexpected endpoint."; |
There was a problem hiding this comment.
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.
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.
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.
(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.
Should we validate the received packet?
|
Addresses review issues, rebased and added CHANGELOG entry. |
Fixes #5455