kad loop interval conf

std/options fixes

- add Option[T] valueOr/withValue no longer provided by libp2p
- add missing std/options imports no longer re-exported by libp2p
This commit is contained in:
SionoiS 2026-03-26 07:37:45 -04:00
parent 8bed6241b0
commit b0b72e98af
No known key found for this signature in database
GPG Key ID: C9458A8CB1852951
7 changed files with 39 additions and 11 deletions

View File

@ -90,6 +90,9 @@ if not defined(macosx) and not defined(android):
nimStackTraceOverride
switch("import", "libbacktrace")
# Shim to provide valueOr and withValue for Option[T]
switch("import", "waku/common/option_shim")
--define:
nimOldCaseObjects
# https://github.com/status-im/nim-confutils/issues/9

View File

@ -1,7 +1,7 @@
{.used.}
import
std/[sequtils, strutils, net],
std/[options, sequtils, strutils, net],
stew/byteutils,
testutils/unittests,
chronicles,

View File

@ -1,7 +1,7 @@
{.used.}
import
std/[os, strutils, sequtils, sysrand, math],
std/[options, os, strutils, sequtils, sysrand, math],
stew/byteutils,
testutils/unittests,
chronos,

View File

@ -1,7 +1,7 @@
{.used.}
import
std/sequtils,
std/[options, sequtils],
testutils/unittests,
chronicles,
chronos,

View File

@ -0,0 +1,26 @@
# Shim to provide valueOr and withValue for Option[T]
{.push raises: [].}
import std/options
template valueOr*[T](self: Option[T], def: untyped): T =
let s = self
if s.isSome():
s.get()
else:
def
template withValue*[T](self: Option[T], value, body: untyped) =
let s = self
if s.isSome():
let value {.inject.} = s.get()
body
template withValue*[T](self: Option[T], value, body, elseStmt: untyped) =
let s = self
if s.isSome():
let value {.inject.} = s.get()
body
else:
elseStmt

View File

@ -24,6 +24,7 @@ const DefaultKademliaDiscoveryInterval* = chronos.seconds(10)
type WakuKademlia* = ref object
protocol*: KademliaDiscovery
peerManager: PeerManager
loopInterval: Duration
walkIntervalFut: Future[void]
proc toRemotePeerInfo(record: ExtendedPeerRecord): Option[RemotePeerInfo] =
@ -128,6 +129,7 @@ proc new*(
peerManager: PeerManager,
bootstrapNodes: seq[(PeerId, seq[MultiAddress])],
providedServices: var seq[ServiceInfo],
loopInterval: Duration = DefaultKademliaDiscoveryInterval,
): T =
if bootstrapNodes.len == 0:
debug "creating kademlia discovery as seed node (no bootstrap nodes)"
@ -141,11 +143,11 @@ proc new*(
services = providedServices,
)
return WakuKademlia(protocol: kademlia, peerManager: peerManager)
return WakuKademlia(
protocol: kademlia, peerManager: peerManager, loopInterval: loopInterval
)
proc start*(
self: WakuKademlia, interval: Duration = DefaultKademliaDiscoveryInterval
) {.async.} =
proc start*(self: WakuKademlia) {.async.} =
if self.protocol.started:
warn "Starting waku kad twice"
return
@ -154,7 +156,7 @@ proc start*(
await self.protocol.start()
self.walkIntervalFut = self.runDiscoveryLoop(interval)
self.walkIntervalFut = self.runDiscoveryLoop(self.loopInterval)
info "Waku Kademlia Started"

View File

@ -638,9 +638,6 @@ proc stop*(node: WakuNode) {.async.} =
if not node.wakuRendezvousClient.isNil():
await node.wakuRendezvousClient.stopWait()
if not node.wakuKademlia.isNil():
await node.wakuKademlia.stop()
node.started = false
proc isReady*(node: WakuNode): Future[bool] {.async: (raises: [Exception]).} =