Slightly improved logging traces for error on message responses (#364)

This commit is contained in:
Kim De Mey 2021-06-09 14:55:00 +02:00 committed by GitHub
parent 0ad571ab27
commit d18ebaa570
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 18 deletions

View File

@ -546,18 +546,23 @@ proc waitNodes(d: Protocol, fromNode: Node, reqId: RequestId):
## If one reply is lost here (timed out), others are ignored too. ## If one reply is lost here (timed out), others are ignored too.
## Same counts for out of order receival. ## Same counts for out of order receival.
var op = await d.waitMessage(fromNode, reqId) var op = await d.waitMessage(fromNode, reqId)
if op.isSome and op.get.kind == nodes: if op.isSome:
var res = op.get.nodes.enrs if op.get.kind == nodes:
let total = op.get.nodes.total var res = op.get.nodes.enrs
for i in 1 ..< total: let total = op.get.nodes.total
op = await d.waitMessage(fromNode, reqId) for i in 1 ..< total:
if op.isSome and op.get.kind == nodes: op = await d.waitMessage(fromNode, reqId)
res.add(op.get.nodes.enrs) if op.isSome and op.get.kind == nodes:
else: res.add(op.get.nodes.enrs)
# No error on this as we received some nodes. else:
break # No error on this as we received some nodes.
return ok(res) break
return ok(res)
else:
discovery_message_requests_outgoing.inc(labelValues = ["invalid_response"])
return err("Invalid response to find node message")
else: else:
discovery_message_requests_outgoing.inc(labelValues = ["no_response"])
return err("Nodes message not received in time") return err("Nodes message not received in time")
proc sendMessage*[T: SomeMessage](d: Protocol, toNode: Node, m: T): proc sendMessage*[T: SomeMessage](d: Protocol, toNode: Node, m: T):
@ -586,9 +591,14 @@ proc ping*(d: Protocol, toNode: Node):
PingMessage(enrSeq: d.localNode.record.seqNum)) PingMessage(enrSeq: d.localNode.record.seqNum))
let resp = await d.waitMessage(toNode, reqId) let resp = await d.waitMessage(toNode, reqId)
if resp.isSome() and resp.get().kind == pong: if resp.isSome():
d.routingTable.setJustSeen(toNode) if resp.get().kind == pong:
return ok(resp.get().pong) d.routingTable.setJustSeen(toNode)
return ok(resp.get().pong)
else:
d.replaceNode(toNode)
discovery_message_requests_outgoing.inc(labelValues = ["invalid_response"])
return err("Invalid response to ping message")
else: else:
d.replaceNode(toNode) d.replaceNode(toNode)
discovery_message_requests_outgoing.inc(labelValues = ["no_response"]) discovery_message_requests_outgoing.inc(labelValues = ["no_response"])
@ -609,7 +619,6 @@ proc findNode*(d: Protocol, toNode: Node, distances: seq[uint32]):
return ok(res) return ok(res)
else: else:
d.replaceNode(toNode) d.replaceNode(toNode)
discovery_message_requests_outgoing.inc(labelValues = ["no_response"])
return err(nodes.error) return err(nodes.error)
proc talkreq*(d: Protocol, toNode: Node, protocol, request: seq[byte]): proc talkreq*(d: Protocol, toNode: Node, protocol, request: seq[byte]):
@ -621,9 +630,14 @@ proc talkreq*(d: Protocol, toNode: Node, protocol, request: seq[byte]):
TalkReqMessage(protocol: protocol, request: request)) TalkReqMessage(protocol: protocol, request: request))
let resp = await d.waitMessage(toNode, reqId) let resp = await d.waitMessage(toNode, reqId)
if resp.isSome() and resp.get().kind == talkresp: if resp.isSome():
d.routingTable.setJustSeen(toNode) if resp.get().kind == talkresp:
return ok(resp.get().talkresp) d.routingTable.setJustSeen(toNode)
return ok(resp.get().talkresp)
else:
d.replaceNode(toNode)
discovery_message_requests_outgoing.inc(labelValues = ["invalid_response"])
return err("Invalid response to talk request message")
else: else:
d.replaceNode(toNode) d.replaceNode(toNode)
discovery_message_requests_outgoing.inc(labelValues = ["no_response"]) discovery_message_requests_outgoing.inc(labelValues = ["no_response"])