mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-06-06 05:59:33 +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
a6aee7cc71
commit
1c7f5e07be
@ -90,6 +90,9 @@ if not defined(macosx) and not defined(android):
|
|||||||
nimStackTraceOverride
|
nimStackTraceOverride
|
||||||
switch("import", "libbacktrace")
|
switch("import", "libbacktrace")
|
||||||
|
|
||||||
|
# Shim to provide valueOr and withValue for Option[T]
|
||||||
|
switch("import", "waku/common/option_shim")
|
||||||
|
|
||||||
--define:
|
--define:
|
||||||
nimOldCaseObjects
|
nimOldCaseObjects
|
||||||
# https://github.com/status-im/nim-confutils/issues/9
|
# https://github.com/status-im/nim-confutils/issues/9
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{.used.}
|
{.used.}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[sequtils, strutils, net],
|
std/[options, sequtils, strutils, net],
|
||||||
stew/byteutils,
|
stew/byteutils,
|
||||||
testutils/unittests,
|
testutils/unittests,
|
||||||
chronicles,
|
chronicles,
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{.used.}
|
{.used.}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[os, strutils, sequtils, sysrand, math],
|
std/[options, os, strutils, sequtils, sysrand, math],
|
||||||
stew/byteutils,
|
stew/byteutils,
|
||||||
testutils/unittests,
|
testutils/unittests,
|
||||||
chronos,
|
chronos,
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{.used.}
|
{.used.}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/sequtils,
|
std/[options, sequtils],
|
||||||
testutils/unittests,
|
testutils/unittests,
|
||||||
chronicles,
|
chronicles,
|
||||||
chronos,
|
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
|
type WakuKademlia* = ref object
|
||||||
protocol*: KademliaDiscovery
|
protocol*: KademliaDiscovery
|
||||||
peerManager: PeerManager
|
peerManager: PeerManager
|
||||||
|
loopInterval: Duration
|
||||||
walkIntervalFut: Future[void]
|
walkIntervalFut: Future[void]
|
||||||
|
|
||||||
proc toRemotePeerInfo(record: ExtendedPeerRecord): Option[RemotePeerInfo] =
|
proc toRemotePeerInfo(record: ExtendedPeerRecord): Option[RemotePeerInfo] =
|
||||||
@ -128,6 +129,7 @@ proc new*(
|
|||||||
peerManager: PeerManager,
|
peerManager: PeerManager,
|
||||||
bootstrapNodes: seq[(PeerId, seq[MultiAddress])],
|
bootstrapNodes: seq[(PeerId, seq[MultiAddress])],
|
||||||
providedServices: var seq[ServiceInfo],
|
providedServices: var seq[ServiceInfo],
|
||||||
|
loopInterval: Duration = DefaultKademliaDiscoveryInterval,
|
||||||
): T =
|
): T =
|
||||||
if bootstrapNodes.len == 0:
|
if bootstrapNodes.len == 0:
|
||||||
debug "creating kademlia discovery as seed node (no bootstrap nodes)"
|
debug "creating kademlia discovery as seed node (no bootstrap nodes)"
|
||||||
@ -141,11 +143,11 @@ proc new*(
|
|||||||
services = providedServices,
|
services = providedServices,
|
||||||
)
|
)
|
||||||
|
|
||||||
return WakuKademlia(protocol: kademlia, peerManager: peerManager)
|
return WakuKademlia(
|
||||||
|
protocol: kademlia, peerManager: peerManager, loopInterval: loopInterval
|
||||||
|
)
|
||||||
|
|
||||||
proc start*(
|
proc start*(self: WakuKademlia) {.async.} =
|
||||||
self: WakuKademlia, interval: Duration = DefaultKademliaDiscoveryInterval
|
|
||||||
) {.async.} =
|
|
||||||
if self.protocol.started:
|
if self.protocol.started:
|
||||||
warn "Starting waku kad twice"
|
warn "Starting waku kad twice"
|
||||||
return
|
return
|
||||||
@ -154,7 +156,7 @@ proc start*(
|
|||||||
|
|
||||||
await self.protocol.start()
|
await self.protocol.start()
|
||||||
|
|
||||||
self.walkIntervalFut = self.runDiscoveryLoop(interval)
|
self.walkIntervalFut = self.runDiscoveryLoop(self.loopInterval)
|
||||||
|
|
||||||
info "Waku Kademlia Started"
|
info "Waku Kademlia Started"
|
||||||
|
|
||||||
|
|||||||
@ -640,9 +640,6 @@ proc stop*(node: WakuNode) {.async.} =
|
|||||||
if not node.wakuRendezvousClient.isNil():
|
if not node.wakuRendezvousClient.isNil():
|
||||||
await node.wakuRendezvousClient.stopWait()
|
await node.wakuRendezvousClient.stopWait()
|
||||||
|
|
||||||
if not node.wakuKademlia.isNil():
|
|
||||||
await node.wakuKademlia.stop()
|
|
||||||
|
|
||||||
node.started = false
|
node.started = false
|
||||||
|
|
||||||
proc isReady*(node: WakuNode): Future[bool] {.async: (raises: [Exception]).} =
|
proc isReady*(node: WakuNode): Future[bool] {.async: (raises: [Exception]).} =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user