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].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[tables, hashes, times, algorithm, sets, sequtils, random],
|
std/[tables, hashes, times, algorithm, sets, sequtils],
|
||||||
chronos, chronicles, stint, nimcrypto/keccak,
|
chronos, chronicles, stint, nimcrypto/keccak,
|
||||||
../keys,
|
../keys, ./discoveryv5/random2,
|
||||||
./enode
|
./enode
|
||||||
|
|
||||||
export sets # TODO: This should not be needed, but compilation fails otherwise
|
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) =
|
proc init(r: var RoutingTable, thisNode: Node) =
|
||||||
r.thisNode = thisNode
|
r.thisNode = thisNode
|
||||||
r.buckets = @[newKBucket(0.u256, high(UInt256))]
|
r.buckets = @[newKBucket(0.u256, high(UInt256))]
|
||||||
randomize() # for later `randomNodes` selection
|
|
||||||
|
|
||||||
proc splitBucket(r: var RoutingTable, index: int) =
|
proc splitBucket(r: var RoutingTable, index: int) =
|
||||||
let bucket = r.buckets[index]
|
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
|
# insignificant compared to the time it takes for the network roundtrips when connecting
|
||||||
# to nodes.
|
# to nodes.
|
||||||
while len(seen) < count:
|
while len(seen) < count:
|
||||||
let bucket = k.routing.buckets.sample()
|
let bucket = k.rng[].sample(k.routing.buckets)
|
||||||
if bucket.nodes.len != 0:
|
if bucket.nodes.len != 0:
|
||||||
let node = bucket.nodes.sample()
|
let node = k.rng[].sample(bucket.nodes)
|
||||||
if node notin seen:
|
if node notin seen:
|
||||||
result.add(node)
|
result.add(node)
|
||||||
seen.incl(node)
|
seen.incl(node)
|
||||||
|
|
Loading…
Reference in New Issue