From 6e61e02091c589ca9da3a2f7e5c071b1240e5244 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Wed, 10 May 2023 21:38:57 +0200 Subject: [PATCH] fixup: move sendRequest forward Signed-off-by: Csaba Kiraly --- .../private/eth/p2p/discoveryv5/protocol.nim | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/codexdht/private/eth/p2p/discoveryv5/protocol.nim b/codexdht/private/eth/p2p/discoveryv5/protocol.nim index 4253059..ab6b4b6 100644 --- a/codexdht/private/eth/p2p/discoveryv5/protocol.nim +++ b/codexdht/private/eth/p2p/discoveryv5/protocol.nim @@ -452,6 +452,28 @@ proc replaceNode(d: Protocol, n: Node) = # peers in the routing table. debug "Message request to bootstrap node failed", src=d.localNode, dst=n +proc sendRequest*[T: SomeMessage](d: Protocol, toId: NodeId, toAddr: Address, m: T, + reqId: RequestId) = + let + message = encodeMessage(m, reqId) + + trace "Send message packet", dstId = toId, toAddr, kind = messageKind(T) + discovery_message_requests_outgoing.inc() + + d.transport.sendMessage(toId, toAddr, message) + +proc sendRequest*[T: SomeMessage](d: Protocol, toNode: Node, m: T, + reqId: RequestId) = + doAssert(toNode.address.isSome()) + let + message = encodeMessage(m, reqId) + + trace "Send message packet", dstId = toNode.id, + address = toNode.address, kind = messageKind(T) + discovery_message_requests_outgoing.inc() + + d.transport.sendMessage(toNode, message) + proc waitResponse*[T: SomeMessage](d: Protocol, node: Node, msg: T): Future[Option[Message]] = let reqId = RequestId.init(d.rng[]) @@ -503,28 +525,6 @@ proc waitNodes(d: Protocol, fromNode: Node, reqId: RequestId): discovery_message_requests_outgoing.inc(labelValues = ["no_response"]) return err("Nodes message not received in time") -proc sendRequest*[T: SomeMessage](d: Protocol, toId: NodeId, toAddr: Address, m: T, - reqId: RequestId) = - let - message = encodeMessage(m, reqId) - - trace "Send message packet", dstId = toId, toAddr, kind = messageKind(T) - discovery_message_requests_outgoing.inc() - - d.transport.sendMessage(toId, toAddr, message) - -proc sendRequest*[T: SomeMessage](d: Protocol, toNode: Node, m: T, - reqId: RequestId) = - doAssert(toNode.address.isSome()) - let - message = encodeMessage(m, reqId) - - trace "Send message packet", dstId = toNode.id, - address = toNode.address, kind = messageKind(T) - discovery_message_requests_outgoing.inc() - - d.transport.sendMessage(toNode, message) - proc ping*(d: Protocol, toNode: Node): Future[DiscResult[PongMessage]] {.async.} = ## Send a discovery ping message.