Add own node checks before sending ping (#548)

Seems there are two occasions possible where we try to ping the
own local node which causes an assert

- One via the bounding
- One via a received ping, which is strange in the first place but
notice in a stack trace
This commit is contained in:
Kim De Mey 2022-11-07 14:25:11 +01:00 committed by GitHub
parent fef47331c3
commit 64b56d866c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 14 deletions

View File

@ -443,6 +443,7 @@ proc findNode*(k: KademliaProtocol, nodesSeen: ref HashSet[Node],
var bondedNodes: seq[Future[bool]] = @[] var bondedNodes: seq[Future[bool]] = @[]
for node in candidates: for node in candidates:
if node != k.thisNode:
bondedNodes.add(k.bond(node)) bondedNodes.add(k.bond(node))
await allFutures(bondedNodes) await allFutures(bondedNodes)
@ -602,6 +603,9 @@ proc recvPing*(k: KademliaProtocol, n: Node, msgHash: any)
k.wire.sendPong(n, msgHash) k.wire.sendPong(n, msgHash)
if getTime() - k.lastPongReceived(n) > BOND_EXPIRATION: if getTime() - k.lastPongReceived(n) > BOND_EXPIRATION:
# TODO: It is strange that this would occur, as it means our own node would
# have pinged us which should have caused an assert in the first place.
if n != k.thisNode:
let pingId = pingId(n, k.ping(n)) let pingId = pingId(n, k.ping(n))
let fut = if pingId in k.pongFutures: let fut = if pingId in k.pongFutures: