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

Commit 1c03c6f

Browse files
committed
When the node sends Pong with changed NodeID, drop the record with old NodeID from the node table
1 parent 5373edf commit 1c03c6f

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

libp2p/NodeTable.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,21 +481,29 @@ void NodeTable::onPacketReceived(
481481
}
482482

483483
auto const& pong = dynamic_cast<Pong const&>(*packet);
484-
if (pong.echo != sentPing->second.pingHash)
484+
auto const& nodeValidation = sentPing->second;
485+
if (pong.echo != nodeValidation.pingHash)
485486
{
486487
LOG(m_logger) << "Invalid PONG from " << _from.address().to_string() << ":"
487488
<< _from.port();
488489
return;
489490
}
490491

492+
// in case the node answers with new NodeID, drop the record with the old NodeID
493+
auto const& sourceId = pong.sourceid;
494+
if (sourceId != nodeValidation.nodeID)
495+
{
496+
if (auto node = nodeEntry(nodeValidation.nodeID))
497+
dropNode(move(node));
498+
}
499+
491500
// create or update nodeEntry with new Pong received time
492501
DEV_GUARDED(x_nodes)
493502
{
494-
auto const& sourceId = pong.sourceid;
495503
auto it = m_allNodes.find(sourceId);
496504
if (it == m_allNodes.end())
497505
sourceNodeEntry = make_shared<NodeEntry>(m_hostNodeID, sourceId,
498-
NodeIPEndpoint{_from.address(), _from.port(), sentPing->second.tcpPort},
506+
NodeIPEndpoint{_from.address(), _from.port(), nodeValidation.tcpPort},
499507
RLPXDatagramFace::secondsSinceEpoch(), 0);
500508
else
501509
{

0 commit comments

Comments
 (0)