diff --git a/eth/p2p/kademlia.nim b/eth/p2p/kademlia.nim index dad8814..038b30c 100644 --- a/eth/p2p/kademlia.nim +++ b/eth/p2p/kademlia.nim @@ -443,7 +443,8 @@ proc findNode*(k: KademliaProtocol, nodesSeen: ref HashSet[Node], var bondedNodes: seq[Future[bool]] = @[] for node in candidates: - bondedNodes.add(k.bond(node)) + if node != k.thisNode: + bondedNodes.add(k.bond(node)) await allFutures(bondedNodes) @@ -602,22 +603,25 @@ proc recvPing*(k: KademliaProtocol, n: Node, msgHash: any) k.wire.sendPong(n, msgHash) if getTime() - k.lastPongReceived(n) > BOND_EXPIRATION: - let pingId = pingId(n, k.ping(n)) + # 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 fut = if pingId in k.pongFutures: - k.pongFutures[pingId] - else: - k.waitPong(n, pingId) + let fut = if pingId in k.pongFutures: + k.pongFutures[pingId] + else: + k.waitPong(n, pingId) - let cb = proc(data: pointer) {.gcsafe.} = - # fut.read == true if pingid exists - try: - if fut.completed and fut.read: - k.updateRoutingTable(n) - except CatchableError as ex: - error "recvPing:WaitPong exception", msg=ex.msg + let cb = proc(data: pointer) {.gcsafe.} = + # fut.read == true if pingid exists + try: + if fut.completed and fut.read: + k.updateRoutingTable(n) + except CatchableError as ex: + error "recvPing:WaitPong exception", msg=ex.msg - fut.addCallback cb + fut.addCallback cb else: k.updateRoutingTable(n)