mirror of https://github.com/status-im/nim-eth.git
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:
parent
fef47331c3
commit
64b56d866c
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue