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 <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2022-03-16 22:12:57 +01:00
parent 4d7e773c42
commit 7bef1e105f
2 changed files with 5 additions and 1 deletions

View File

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

View File

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