mirror of
https://github.com/status-im/nim-eth.git
synced 2025-01-12 15:24:21 +00:00
Add ping proc
This commit is contained in:
parent
942e978269
commit
c4c1bb967d
@ -333,15 +333,19 @@ proc processClient(transp: DatagramTransport,
|
|||||||
debug "Receive failed", exception = e.name, msg = e.msg,
|
debug "Receive failed", exception = e.name, msg = e.msg,
|
||||||
stacktrace = e.getStackTrace()
|
stacktrace = e.getStackTrace()
|
||||||
|
|
||||||
|
proc ping(p: Protocol, toNode: Node): RequestId =
|
||||||
|
let
|
||||||
|
reqId = newRequestId()
|
||||||
|
ping = PingPacket(enrSeq: p.localNode.record.seqNum)
|
||||||
|
packet = encodePacket(ping, reqId)
|
||||||
|
(data, nonce) = p.codec.encodeEncrypted(toNode, packet, challenge = nil)
|
||||||
|
p.pendingRequests[nonce] = PendingRequest(node: toNode, packet: packet)
|
||||||
|
p.send(toNode, data)
|
||||||
|
return reqId
|
||||||
|
|
||||||
proc revalidateNode(p: Protocol, n: Node)
|
proc revalidateNode(p: Protocol, n: Node)
|
||||||
{.async, raises:[Defect, Exception].} = # TODO: Exception
|
{.async, raises:[Defect, Exception].} = # TODO: Exception
|
||||||
let reqId = newRequestId()
|
let reqId = p.ping(n)
|
||||||
var ping: PingPacket
|
|
||||||
ping.enrSeq = p.localNode.record.seqNum
|
|
||||||
let packet = encodePacket(ping, reqId)
|
|
||||||
let (data, nonce) = p.codec.encodeEncrypted(n, packet, challenge = nil)
|
|
||||||
p.pendingRequests[nonce] = PendingRequest(node: n, packet: packet)
|
|
||||||
p.send(n, data)
|
|
||||||
|
|
||||||
let resp = await p.waitPacket(n, reqId)
|
let resp = await p.waitPacket(n, reqId)
|
||||||
if resp.isSome and resp.get.kind == pong:
|
if resp.isSome and resp.get.kind == pong:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user