diff --git a/eth/p2p/discoveryv5/protocol.nim b/eth/p2p/discoveryv5/protocol.nim index ac14a75..2d4ac91 100644 --- a/eth/p2p/discoveryv5/protocol.nim +++ b/eth/p2p/discoveryv5/protocol.nim @@ -5,6 +5,9 @@ import import nimcrypto except toHex +logScope: + topics = "discv5" + type Protocol* = ref object transp: DatagramTransport @@ -247,12 +250,17 @@ proc lookupWorker(p: Protocol, destNode: Node, target: NodeId): Future[seq[Node] discard p.routingTable.addNode(n) proc lookup(p: Protocol, target: NodeId): Future[seq[Node]] {.async.} = - result = p.routingTable.neighbours(target, 16) + ## Perform a lookup for the given target, return the closest n nodes to the + ## target. Maximum value for n is `BUCKET_SIZE`. + # TODO: Sort the returned nodes on distance + result = p.routingTable.neighbours(target, BUCKET_SIZE) var asked = initHashSet[NodeId]() asked.incl(p.localNode.id) var seen = asked + for node in result: + seen.incl(node.id) - const alpha = 3 + const alpha = 3 # Kademlia concurrency factor var pendingQueries = newSeqOfCap[Future[seq[Node]]](alpha) diff --git a/tests/p2p/test_discoveryv5.nim b/tests/p2p/test_discoveryv5.nim index 7998833..4399b6b 100644 --- a/tests/p2p/test_discoveryv5.nim +++ b/tests/p2p/test_discoveryv5.nim @@ -43,6 +43,7 @@ suite "Discovery v5 Tests": for node in nodes: let discovered = await node.lookupRandom() + check discovered.len < nodes.len debug "Lookup from random id", node=node.localNode, discovered # Check for each node if the other nodes shows up in the routing table