From 086162183ca7265407f0dd788c45499907916ae7 Mon Sep 17 00:00:00 2001 From: Kim De Mey Date: Mon, 22 Nov 2021 19:45:38 +0100 Subject: [PATCH] Make queryRandom async and add exports (#431) queryRandom was currently only async for the `enrField` version. However the basic queryRandom is also exported and thus gets changed so it can be properly used as async proc. Also added exports for the modules of which objects are used in the discovery public API. --- eth/p2p/discoveryv5/protocol.nim | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/eth/p2p/discoveryv5/protocol.nim b/eth/p2p/discoveryv5/protocol.nim index 1efc09f..4f3a4a2 100644 --- a/eth/p2p/discoveryv5/protocol.nim +++ b/eth/p2p/discoveryv5/protocol.nim @@ -76,13 +76,13 @@ import std/[tables, sets, options, math, sequtils, algorithm], stew/shims/net as stewNet, json_serialization/std/net, - stew/endians2, chronicles, chronos, stint, bearssl, metrics, + stew/[endians2, results], chronicles, chronos, stint, bearssl, metrics, ".."/../[rlp, keys, async_utils], "."/[messages, encoding, node, routing_table, enr, random2, sessions, ip_vote, nodes_verification] import nimcrypto except toHex -export options +export options, results, node, enr declareCounter discovery_message_requests_outgoing, "Discovery protocol outgoing message requests", labels = ["response"] @@ -422,8 +422,10 @@ proc receive*(d: Protocol, a: Address, packet: openArray[byte]) = # In that case we can add/update it to the routing table. if packet.node.isSome(): let node = packet.node.get() - # Not filling table with nodes without correct IP in the ENR - # TODO: Should we care about this??? + # Lets not add nodes without correct IP in the ENR to the routing table. + # The ENR could contain bogus IPs and although they would get removed + # on the next revalidation, one could spam these as the handshake + # message occurs on (first) incoming messages. if node.address.isSome() and a == node.address.get(): if d.addNode(node): trace "Added new node to routing table after handshake", node @@ -716,9 +718,9 @@ proc query*(d: Protocol, target: NodeId, k = BUCKET_SIZE): Future[seq[Node]] d.lastLookup = now(chronos.Moment) return queryBuffer -proc queryRandom*(d: Protocol): Future[seq[Node]] = +proc queryRandom*(d: Protocol): Future[seq[Node]] {.async.} = ## Perform a query for a random target, return all nodes discovered. - d.query(NodeId.random(d.rng[])) + return await d.query(NodeId.random(d.rng[])) proc queryRandom*(d: Protocol, enrField: (string, seq[byte])): Future[seq[Node]] {.async.} =