Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Handle receiving Discovery packets with changed endpoint #5519

Merged
merged 5 commits into from
Mar 26, 2019

Conversation

gumb0
Copy link
Member

@gumb0 gumb0 commented Mar 13, 2019

Fixes #5455

@codecov-io
Copy link

codecov-io commented Mar 14, 2019

Codecov Report

Merging #5519 into master will increase coverage by 0.08%.
The diff coverage is 95.29%.

Impacted file tree graph

@@            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

@gumb0 gumb0 force-pushed the changed-endpoint branch 3 times, most recently from 7a9d46b to 0886a34 Compare March 18, 2019 15:47
@@ -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());
Copy link
Member Author

@gumb0 gumb0 Mar 18, 2019

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

@gumb0 gumb0 requested review from halfalicious and chfast March 18, 2019 15:58
@gumb0 gumb0 removed the in progress label Mar 18, 2019
Copy link
Contributor

@halfalicious halfalicious left a 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

@@ -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;
Copy link
Contributor

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:

aleth/libp2p/NodeTable.cpp

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();

Copy link
Contributor

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?

Copy link
Member Author

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.

@@ -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.";
Copy link
Contributor

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?

@@ -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.";
Copy link
Contributor

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 Show resolved Hide resolved
test/unittests/libp2p/net.cpp Show resolved Hide resolved
auto findNode = dynamic_cast<FindNode const&>(*findNodeDatagram);

// send Neighbours through endpoint 2
// TODO fill nearest with one node
Copy link
Contributor

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?

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)};
Copy link
Contributor

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

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Nit) {} initializers

nodeSocketHost2.socket->send(neighbours);

// Wait for Neighbours to be received
nodeTable->packetsReceived.pop(chrono::seconds(5));
Copy link
Contributor

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?

@gumb0 gumb0 force-pushed the changed-endpoint branch from 7f5c400 to 8163800 Compare March 25, 2019 13:58
@gumb0
Copy link
Member Author

gumb0 commented Mar 25, 2019

Addresses review issues, rebased and added CHANGELOG entry.

@gumb0 gumb0 requested a review from halfalicious March 25, 2019 13:59
@gumb0 gumb0 force-pushed the changed-endpoint branch from 8163800 to 2f589f7 Compare March 26, 2019 10:19
@gumb0 gumb0 force-pushed the changed-endpoint branch from 2f589f7 to 28984b4 Compare March 26, 2019 10:48
@gumb0 gumb0 merged commit 9f2e689 into master Mar 26, 2019
@gumb0 gumb0 deleted the changed-endpoint branch March 26, 2019 11:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants