mirror of https://github.com/status-im/nim-eth.git
kad: remove unnecessary randomize call (#535)
* kad: remove unnecessary randomize call * use `rng.sample`
This commit is contained in:
parent
059d319c16
commit
2734ed6bda
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue