From d4af5b8a44b9488f4db8342f6a6ad888aaf6cfb9 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Wed, 23 Feb 2022 20:56:19 +0100 Subject: [PATCH] protocol.sendMessage: allow destination as (NodeId, Address) --- eth/p2p/discoveryv5/protocol.nim | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/eth/p2p/discoveryv5/protocol.nim b/eth/p2p/discoveryv5/protocol.nim index 0afc7f0..6c1f3b0 100644 --- a/eth/p2p/discoveryv5/protocol.nim +++ b/eth/p2p/discoveryv5/protocol.nim @@ -379,6 +379,18 @@ 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 sendMessage*[T: SomeMessage](d: Protocol, toId: NodeId, toAddr: Address, m: T): + RequestId = + let + reqId = RequestId.init(d.rng[]) + 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) + return reqId + proc sendMessage*[T: SomeMessage](d: Protocol, toNode: Node, m: T): RequestId = doAssert(toNode.address.isSome())