refactor(waku utils): Separate waku node start from pairing process

This commit is contained in:
Emil Ivanichkov 2024-03-11 19:22:43 +02:00 committed by Emil Ivanichkov
parent ed5f30260c
commit 27f47d3354
2 changed files with 9 additions and 11 deletions

View File

@ -60,6 +60,9 @@ proc startWakuNode*(rng: ref HmacDrbgContext,
some(node.peerManager),
node.topicSubscriptionQueue)
notice "Starting Waku Node", enr=bootstrapNode, wakuPort=wakuPort,
discv5Port=discv5Port
await node.start()
await node.mountRelay()
node.peerManager.start()
@ -73,10 +76,10 @@ proc startWakuNode*(rng: ref HmacDrbgContext,
let numConnectedPeers = node.peerManager.peerStore[
ConnectionBook].book.values().countIt(it == Connected)
if numConnectedPeers >= requiredConnectedPeers:
notice "Node is ready", connectedPeers = numConnectedPeers,
notice "Waku Node is ready", connectedPeers = numConnectedPeers,
required = requiredConnectedPeers
break
notice "Waiting for the node to be ready",
notice "Waiting for the waku node to be ready",
connectedPeers = numConnectedPeers, required = requiredConnectedPeers
await sleepAsync(5000)

View File

@ -20,9 +20,9 @@ type WakuPairResult* = object
wakuNode*: WakuNode
wakuHandshakeResult*: HandshakeResult
proc wakuPair*(rng: ref HmacDrbgContext, qr, qrMessageNameTagHex: string,
wakuPort, discv5Port: uint16,
requiredConnectedPeers: int,
proc wakuPair*(rng: ref HmacDrbgContext,
node: WakuNode,
qr, qrMessageNameTagHex: string,
pubSubTopic: PubsubTopic
): Future[WakuPairResult] {.async.} =
# Initiator static/ephemeral key initialization and commitment
@ -34,18 +34,13 @@ proc wakuPair*(rng: ref HmacDrbgContext, qr, qrMessageNameTagHex: string,
# We set the contentTopic from the content topic parameters exchanged in the QR
contentTopic = initContentTopicFromQr(qr)
notice "Initializing Waku pairing", wakuPort = wakuPort,
discv5Port = discv5Port
notice "Initializing Waku pairing"
notice "Initial information parsed from the QR", contentTopic = contentTopic,
qrMessageNameTag = qrMessageNameTag
var initiatorHSResult: HandshakeResult
# Start nwaku instance
let node = await startWakuNode(rng, wakuPort, discv5Port,
requiredConnectedPeers)
# Perform the handshake
initiatorHSResult = await initiatorHandshake(rng, node, pubSubTopic,
contentTopic, qr,