Merge pull request #193 from status-im/discv5-fixes

Fix invalid packet in pendingRequest
This commit is contained in:
Kim De Mey 2020-03-09 10:23:01 +01:00 committed by GitHub
commit 19a8c6ee0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 6 deletions

View File

@ -334,14 +334,19 @@ proc processClient(transp: DatagramTransport,
debug "Receive failed", exception = e.name, msg = e.msg,
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)
{.async, raises:[Defect, Exception].} = # TODO: Exception
let reqId = newRequestId()
var ping: PingPacket
ping.enrSeq = p.localNode.record.seqNum
let (data, nonce) = p.codec.encodeEncrypted(n, encodePacket(ping, reqId), challenge = nil)
p.pendingRequests[nonce] = PendingRequest(node: n, packet: data)
p.send(n, data)
let reqId = p.ping(n)
let resp = await p.waitPacket(n, reqId)
if resp.isSome and resp.get.kind == pong: