From 7bef1e105ff8eea598eed3a72c55e50cb39915d1 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Wed, 16 Mar 2022 22:12:57 +0100 Subject: [PATCH] fix bootstrap: add node after successful handshake Previous version was very conservative about adding nodes to the routing table, requiring a full request/response message exchange initiated by us. Here we also add the node as 'seen' if the whoareyou/handshake exchange was successful. This significantly speeds up bootstreap from 0 Signed-off-by: Csaba Kiraly --- libp2pdht/private/eth/p2p/discoveryv5/node.nim | 3 ++- libp2pdht/private/eth/p2p/discoveryv5/transport.nim | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libp2pdht/private/eth/p2p/discoveryv5/node.nim b/libp2pdht/private/eth/p2p/discoveryv5/node.nim index cf61e47..4e7a854 100644 --- a/libp2pdht/private/eth/p2p/discoveryv5/node.nim +++ b/libp2pdht/private/eth/p2p/discoveryv5/node.nim @@ -28,7 +28,8 @@ type address*: Option[Address] record*: SignedPeerRecord seen*: bool ## Indicates if there was at least one successful - ## request-response with this node. + ## request-response with this node, or if the nde was verified + ## through the underlying transport mechanisms. func toNodeId*(pk: keys.PublicKey): NodeId = ## Convert public key to a node identifier. diff --git a/libp2pdht/private/eth/p2p/discoveryv5/transport.nim b/libp2pdht/private/eth/p2p/discoveryv5/transport.nim index c49770c..adff276 100644 --- a/libp2pdht/private/eth/p2p/discoveryv5/transport.nim +++ b/libp2pdht/private/eth/p2p/discoveryv5/transport.nim @@ -144,6 +144,9 @@ proc receive*(t: Transport, a: Address, packet: openArray[byte]) = # on the next revalidation, one could spam these as the handshake # message occurs on (first) incoming messages. if node.address.isSome() and a == node.address.get(): + # TODO: maybe here we could verify that the address matches what we were + # sending the 'whoareyou' message to. In that case, we can set 'seen' + node.seen = true if t.client.addNode(node): trace "Added new node to routing table after handshake", node else: