diff --git a/eth/p2p/kademlia.nim b/eth/p2p/kademlia.nim index 511b7b7..dad8814 100644 --- a/eth/p2p/kademlia.nim +++ b/eth/p2p/kademlia.nim @@ -8,9 +8,9 @@ {.push raises: [Defect].} import - std/[tables, hashes, times, algorithm, sets, sequtils, random], + std/[tables, hashes, times, algorithm, sets, sequtils], chronos, chronicles, stint, nimcrypto/keccak, - ../keys, + ../keys, ./discoveryv5/random2, ./enode export sets # TODO: This should not be needed, but compilation fails otherwise @@ -276,7 +276,6 @@ proc computeSharedPrefixBits(nodes: openArray[Node]): int = proc init(r: var RoutingTable, thisNode: Node) = r.thisNode = thisNode r.buckets = @[newKBucket(0.u256, high(UInt256))] - randomize() # for later `randomNodes` selection proc splitBucket(r: var RoutingTable, index: int) = let bucket = r.buckets[index] @@ -669,9 +668,9 @@ proc randomNodes*(k: KademliaProtocol, count: int): seq[Node] = # insignificant compared to the time it takes for the network roundtrips when connecting # to nodes. while len(seen) < count: - let bucket = k.routing.buckets.sample() + let bucket = k.rng[].sample(k.routing.buckets) if bucket.nodes.len != 0: - let node = bucket.nodes.sample() + let node = k.rng[].sample(bucket.nodes) if node notin seen: result.add(node) seen.incl(node)