diff --git a/waku/discovery/waku_kademlia.nim b/waku/discovery/waku_kademlia.nim index 0774b2855..88076dbb2 100644 --- a/waku/discovery/waku_kademlia.nim +++ b/waku/discovery/waku_kademlia.nim @@ -17,7 +17,7 @@ import import waku/waku_core, waku/node/peer_manager logScope: - topics = "waku kademlia discovery" + topics = "waku kademlia" const DefaultKademliaDiscoveryInterval* = chronos.seconds(10) @@ -68,7 +68,7 @@ proc toRemotePeerInfo(record: ExtendedPeerRecord): Option[RemotePeerInfo] = proc runDiscoveryLoop( self: WakuKademlia, interval: Duration ) {.async: (raises: [CancelledError]).} = - info "kademlia discovery loop started", interval = interval + debug "kademlia discovery loop started", interval = interval while true: await sleepAsync(interval) @@ -130,7 +130,7 @@ proc new*( providedServices: var seq[ServiceInfo], ): T = if bootstrapNodes.len == 0: - info "creating kademlia discovery as seed node (no bootstrap nodes)" + debug "creating kademlia discovery as seed node (no bootstrap nodes)" let kademlia = KademliaDiscovery.new( switch, @@ -141,13 +141,11 @@ proc new*( services = providedServices, ) - info "kademlia service discovery created", bootstrapNodes = bootstrapNodes.len - return WakuKademlia(protocol: kademlia, peerManager: peerManager) proc start*( self: WakuKademlia, interval: Duration = DefaultKademliaDiscoveryInterval -) {.async: (raises: [CancelledError]).} = +) {.async.} = if self.protocol.started: warn "Starting waku kad twice" return @@ -160,7 +158,7 @@ proc start*( info "Waku Kademlia Started" -proc stop*(self: WakuKademlia) {.async: (raises: []).} = +proc stop*(self: WakuKademlia) {.async.} = if not self.protocol.started: return diff --git a/waku/factory/node_factory.nim b/waku/factory/node_factory.nim index 7b67853ff..95a1e240b 100644 --- a/waku/factory/node_factory.nim +++ b/waku/factory/node_factory.nim @@ -476,12 +476,6 @@ proc startNode*( if conf.relay: node.peerManager.start() - if not node.wakuKademlia.isNil(): - let catchRes = catch: - await node.wakuKademlia.start() - if catchRes.isErr(): - return err("failed to start kademlia discovery: " & catchRes.error.msg) - return ok() proc setupNode*( diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index f99ac8b8f..ef01f3b23 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -604,6 +604,9 @@ proc start*(node: WakuNode) {.async.} = if not node.wakuStoreTransfer.isNil(): node.wakuStoreTransfer.start() + if not node.wakuKademlia.isNil(): + await node.wakuKademlia.start() + ## The switch uses this mapper to update peer info addrs ## with announced addrs after start let addressMapper = proc( @@ -664,15 +667,15 @@ proc stop*(node: WakuNode) {.async.} = not node.wakuPeerExchangeClient.pxLoopHandle.isNil(): await node.wakuPeerExchangeClient.pxLoopHandle.cancelAndWait() - if not node.wakuKademlia.isNil(): - await node.wakuKademlia.stop() - if not node.wakuRendezvous.isNil(): await node.wakuRendezvous.stopWait() 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]).} = diff --git a/waku/waku_mix/protocol.nim b/waku/waku_mix/protocol.nim index df6dbc48b..8ee25073f 100644 --- a/waku/waku_mix/protocol.nim +++ b/waku/waku_mix/protocol.nim @@ -45,7 +45,7 @@ proc poolSize*(self: WakuMix): int = proc mixPoolMaintenance( self: WakuMix, interval: Duration ) {.async: (raises: [CancelledError]).} = - ## Periodic maintenance of the mix pool + debug "mix pool maintenance loop started", interval = interval while true: await sleepAsync(interval) @@ -61,12 +61,12 @@ proc mixPoolMaintenance( debug "kademlia not available for mix peer discovery" continue - debug "mix node pool below threshold, performing targeted lookup", + trace "mix node pool below threshold, performing targeted lookup", currentPoolSize = self.currentMixPoolSize, threshold = self.targetMixPoolSize let mixPeers = await self.wakuKademlia.lookup(MixProtocolID) - debug "mix peer discovery completed", discoveredPeers = mixPeers.len + trace "mix peer discovery completed", discoveredPeers = mixPeers.len proc new*( T: typedesc[WakuMix], @@ -79,7 +79,7 @@ proc new*( ): Result[T, string] = let mixPubKey = public(mixPrivKey) - info "mixPubKey", mixPubKey = mixPubKey + debug "Mix Public Key", mixPubKey = mixPubKey let nodeMultiAddr = MultiAddress.init(nodeAddr).valueOr: return err("failed to parse mix node address: " & $nodeAddr & ", error: " & error)