mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-05-11 21:09:27 +00:00
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:
parent
8bed6241b0
commit
b0b72e98af
@ -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
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{.used.}
|
||||
|
||||
import
|
||||
std/[sequtils, strutils, net],
|
||||
std/[options, sequtils, strutils, net],
|
||||
stew/byteutils,
|
||||
testutils/unittests,
|
||||
chronicles,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{.used.}
|
||||
|
||||
import
|
||||
std/[os, strutils, sequtils, sysrand, math],
|
||||
std/[options, os, strutils, sequtils, sysrand, math],
|
||||
stew/byteutils,
|
||||
testutils/unittests,
|
||||
chronos,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{.used.}
|
||||
|
||||
import
|
||||
std/sequtils,
|
||||
std/[options, sequtils],
|
||||
testutils/unittests,
|
||||
chronicles,
|
||||
chronos,
|
||||
|
||||
26
waku/common/option_shim.nim
Normal file
26
waku/common/option_shim.nim
Normal 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
|
||||
@ -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"
|
||||
|
||||
|
||||
@ -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]).} =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user