option to pass mix nodes as argument

This commit is contained in:
Prem Chaitanya Prathi 2025-07-30 15:27:02 +05:30
parent bff3179906
commit 14e4ee5b16
2 changed files with 24 additions and 7 deletions

View File

@ -396,6 +396,22 @@ proc maintainSubscription(
await sleepAsync(30000) # Subscription maintenance interval
proc processMixNodes(localnode: WakuNode, nodes: seq[string]) {.async.} =
if nodes.len == 0:
return
echo "Processing mix nodes: ", $nodes
for node in nodes:
var enrRec: enr.Record
if enrRec.fromURI(node):
let peerInfo = enrRec.toRemotePeerInfo().valueOr:
error "Failed to parse mix node", error = error
continue
localnode.peermanager.addPeer(peerInfo, Discv5)
info "Added mix node", peer = peerInfo
else:
error "Failed to parse mix node ENR", node = node
{.pop.}
# @TODO confutils.nim(775, 17) Error: can raise an unlisted exception: ref IOError
proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
@ -479,7 +495,8 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
(await node.mountMix(conf.clusterId, mixPrivKey)).isOkOr:
error "failed to mount waku mix protocol: ", error = $error
quit(QuitFailure)
if conf.mixnodes.len > 0:
await processMixNodes(node, conf.mixnodes)
await node.start()
node.peerManager.start()
@ -512,10 +529,6 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
conf: conf,
)
if conf.staticnodes.len > 0:
echo "Connecting to static peers..."
await connectToNodes(chat, conf.staticnodes)
var dnsDiscoveryUrl = none(string)
if conf.fleet != Fleet.none:
@ -635,14 +648,14 @@ proc processInput(rfd: AsyncFD, rng: ref HmacDrbgContext) {.async.} =
else:
error "LightPushClient not mounted. Couldn't parse conf.serviceNode",
error = peerInfo.error
# TODO: Loop faster and also switch to rendezvous
# TODO: Loop faster
node.startPeerExchangeLoop()
while node.getMixNodePoolSize() < 3:
info "waiting for mix nodes to be discovered",
currentpoolSize = node.getMixNodePoolSize()
await sleepAsync(1000)
notice "ready tp publish with mix node pool size ",
notice "ready to publish with mix node pool size ",
currentpoolSize = node.getMixNodePoolSize()
echo "ready to publish messages now"
# Subscribe to a topic, if relay is mounted

View File

@ -82,6 +82,10 @@ type
name: "staticnode"
.}: seq[string]
mixnodes* {.
desc: "Peer ENR to add as a mixnode. Argument may be repeated.", name: "mixnode"
.}: seq[string]
keepAlive* {.
desc: "Enable keep-alive for idle connections: true|false",
defaultValue: false,