Fabiana Cecin 549834203d
Bump to nim-libp2p 2.0.0
* bump libp2p pin to release/v2.0.0 (c43199378)
* pin nimble.lock: lsquic/websock/boringssl/protobuf_serialization/npeg/jwt
* add libp2p_mix dep and point libp2p/protocols/mix -> libp2p_mix
* migrate rng to libp2p Rng type (prod, channels, noise, tests)
* noise: take Rng, extract bearSslDrbg internally
* waku_switch: TransportConfig factory; withMaxInOut; local MaxConnections
* waku_relay/rendezvous/discv5/kademlia: v2.0.0 API (rng, config, ServiceDiscovery)
* tests: newStandardSwitch shim; PeerId.random(rng); common.rng()/crypto.newRng()
* drop libp2p/utils/semaphore (use chronos AsyncSemaphore)
* add waku/compat/option_valueor shim where needed
* add std/options where transitive re-export dropped
2026-06-02 15:42:58 -03:00

33 lines
1.0 KiB
Nim

import std/[times, random], bearssl/rand, libp2p/crypto/crypto
## Randomization
proc randomize*() =
## Initializes the default random number generator with the given seed.
## From: https://nim-lang.org/docs/random.html#randomize,int64
let now = getTime()
randomize(now.toUnix() * 1_000_000_000 + now.nanosecond)
## RNG
# Copied from here: https://github.com/status-im/nim-libp2p/blob/d522537b19a532bc4af94fcd146f779c1f23bad0/tests/helpers.nim#L28
type Rng = object
rng: crypto.Rng
# Typically having a module variable is considered bad design. This case should
# be considered as an exception and it should be used only in the tests.
var rngVar: Rng
proc getRng(): crypto.Rng =
# TODO: if `rngVar` is a threadvar like it should be, there are random and
# spurious compile failures on mac - this is not gcsafe but for the
# purpose of the tests, it's ok as long as we only use a single thread
{.gcsafe.}:
if rngVar.rng.isNil():
rngVar.rng = crypto.newRng()
rngVar.rng
template rng*(): crypto.Rng =
getRng()