From abc61e188aebf67e049b44795f3efa97283615c1 Mon Sep 17 00:00:00 2001 From: kdeme Date: Mon, 30 Mar 2020 14:08:50 +0200 Subject: [PATCH] discv5: Add check on ip address after handshake --- eth/p2p/discoveryv5/protocol.nim | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/eth/p2p/discoveryv5/protocol.nim b/eth/p2p/discoveryv5/protocol.nim index bc5cd9d..baee0b4 100644 --- a/eth/p2p/discoveryv5/protocol.nim +++ b/eth/p2p/discoveryv5/protocol.nim @@ -218,8 +218,11 @@ proc receive*(d: Protocol, a: Address, msg: Bytes) {.gcsafe, if node.isNil: node = d.routingTable.getNode(sender) else: - debug "Adding new node to routing table", node = $node, localNode = $d.localNode - discard d.routingTable.addNode(node) + # Not filling table with nodes without correct IP in the ENR + if a.ip == node.address.ip: + debug "Adding new node to routing table", node = $node, + localNode = $d.localNode + discard d.routingTable.addNode(node) case packet.kind of ping: @@ -241,8 +244,10 @@ proc receive*(d: Protocol, a: Address, msg: Bytes) {.gcsafe, # Still adding the node in case there is a packet error (could be # unsupported packet) if not node.isNil: - debug "Adding new node to routing table", node = $node, localNode = $d.localNode - discard d.routingTable.addNode(node) + if a.ip == node.address.ip: + debug "Adding new node to routing table", node = $node, + localNode = $d.localNode + discard d.routingTable.addNode(node) proc processClient(transp: DatagramTransport, raddr: TransportAddress): Future[void] {.async, gcsafe.} =