Prem Chaitanya Prathi 4a3db364e7
fix(kademlia): allow clientMode without switch.mount
ServiceDiscovery.new(client=true) installs no inbound handler, so
switch.mount always failed. Skip mount for clientMode and keep the
protocol for outbound mix lookups only. Add a unit test and document
relative CHAT_UI paths in the mixnet chat-ui launcher.
2026-07-09 18:41:49 +05:30

53 lines
1.7 KiB
Nim

{.used.}
import std/[options, sets]
import chronos, chronicles, results
import libp2p/[peerid, multiaddress, switch]
import libp2p/extended_peer_record
import libp2p/protocols/service_discovery/types as sd_types
import libp2p/crypto/crypto as libp2p_keys
import
logos_delivery/waku/discovery/waku_kademlia,
logos_delivery/waku/node/peer_manager/peer_manager
import ../testlib/[wakucore, common]
export wakucore, common, peerid, multiaddress, switch, extended_peer_record, sd_types
proc newTestKademlia*(
switch: Switch,
bootstrapNodes: seq[(PeerId, seq[MultiAddress])] = @[],
servicesToAdvertise: seq[ServiceInfo] = @[],
servicesToDiscover: seq[string] = @[],
randomLookupInterval: Duration = 100.milliseconds,
serviceLookupInterval: Duration = 100.milliseconds,
clientMode: bool = false,
xprPublishing: bool = true,
): WakuKademlia =
let peerManager = PeerManager.new(switch)
let wk = WakuKademlia
.new(
switch = switch,
peerManager = peerManager,
bootstrapNodes = bootstrapNodes,
servicesToAdvertise = toHashSet(servicesToAdvertise),
servicesToDiscover = toHashSet(servicesToDiscover),
randomLookupInterval = randomLookupInterval,
serviceLookupInterval = serviceLookupInterval,
rng = rng(),
clientMode = clientMode,
xprPublishing = xprPublishing,
)
.tryGet()
# clientMode has no inbound stream handler; mount would fail (see mountKademlia).
if not clientMode:
switch.mount(wk.protocol)
wk
proc buildExtendedPeerRecord*(
peerId: PeerId, addrs: seq[MultiAddress], services: seq[ServiceInfo] = @[]
): ExtendedPeerRecord =
ExtendedPeerRecord.init(peerId = peerId, addresses = addrs, services = services)