mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-26 14:51:49 +00:00
Start relay protocol on wakunode2 (#446)
* Start relay protocol on wakunode2
This commit is contained in:
parent
e7c21c2f74
commit
683577f045
@ -10,6 +10,7 @@ import
|
||||
libp2p/switch,
|
||||
libp2p/protocols/pubsub/rpc/messages,
|
||||
libp2p/protocols/pubsub/pubsub,
|
||||
libp2p/protocols/pubsub/gossipsub,
|
||||
eth/keys,
|
||||
../../waku/v2/protocol/[waku_relay, waku_message, message_notifier],
|
||||
../../waku/v2/protocol/waku_store/waku_store,
|
||||
@ -394,7 +395,8 @@ procSuite "WakuNode":
|
||||
await node1.stop()
|
||||
await node2.stop()
|
||||
await node3.stop()
|
||||
asyncTest "testing rln-relay with mocked zkp":
|
||||
|
||||
asyncTest "testing rln-relay with mocked zkp":
|
||||
|
||||
let
|
||||
# publisher node
|
||||
@ -449,3 +451,41 @@ asyncTest "testing rln-relay with mocked zkp":
|
||||
await node1.stop()
|
||||
await node2.stop()
|
||||
await node3.stop()
|
||||
|
||||
asyncTest "Relay protocol is started correctly":
|
||||
let
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
node1 = WakuNode.init(nodeKey1, ValidIpAddress.init("0.0.0.0"),
|
||||
Port(60000))
|
||||
|
||||
# Relay protocol starts if mounted after node start
|
||||
|
||||
await node1.start()
|
||||
|
||||
node1.mountRelay()
|
||||
|
||||
check:
|
||||
GossipSub(node1.wakuRelay).heartbeatFut.isNil == false
|
||||
|
||||
# Relay protocol starts if mounted before node start
|
||||
|
||||
let
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
node2 = WakuNode.init(nodeKey2, ValidIpAddress.init("0.0.0.0"),
|
||||
Port(60002))
|
||||
|
||||
node2.mountRelay()
|
||||
|
||||
check:
|
||||
# Relay has not yet started as node has not yet started
|
||||
GossipSub(node2.wakuRelay).heartbeatFut.isNil
|
||||
|
||||
await node2.start()
|
||||
|
||||
check:
|
||||
# Relay started on node start
|
||||
GossipSub(node2.wakuRelay).heartbeatFut.isNil == false
|
||||
|
||||
await allFutures([node1.stop(), node2.stop()])
|
||||
|
||||
|
||||
|
@ -66,6 +66,7 @@ type
|
||||
filters*: Filters
|
||||
subscriptions*: MessageNotificationSubscriptions
|
||||
rng*: ref BrHmacDrbgContext
|
||||
started*: bool # Indicates that node has started listening
|
||||
|
||||
# NOTE Any difference here in Waku vs Eth2?
|
||||
# E.g. Devp2p/Libp2p support, etc.
|
||||
@ -162,12 +163,19 @@ proc start*(node: WakuNode) {.async.} =
|
||||
## XXX: this should be /ip4..., / stripped?
|
||||
info "Listening on", full = listenStr
|
||||
|
||||
if not node.wakuRelay.isNil:
|
||||
await node.wakuRelay.start()
|
||||
|
||||
node.started = true
|
||||
|
||||
proc stop*(node: WakuNode) {.async.} =
|
||||
if not node.wakuRelay.isNil:
|
||||
await node.wakuRelay.stop()
|
||||
|
||||
await node.switch.stop()
|
||||
|
||||
node.started = false
|
||||
|
||||
proc subscribe*(node: WakuNode, topic: Topic, handler: TopicHandler) =
|
||||
## Subscribes to a PubSub topic. Triggers handler when receiving messages on
|
||||
## this topic. TopicHandler is a method that takes a topic and some data.
|
||||
@ -415,6 +423,13 @@ proc mountRelay*(node: WakuNode, topics: seq[string] = newSeq[string](), rlnRela
|
||||
# TODO currently the message validator is set for the defaultTopic, this can be configurable to accept other pubsub topics as well
|
||||
addRLNRelayValidator(node, defaultTopic)
|
||||
info "WakuRLNRelay is mounted successfully"
|
||||
|
||||
if node.started:
|
||||
# Node has already started. Start the WakuRelay protocol
|
||||
|
||||
waitFor node.wakuRelay.start()
|
||||
|
||||
info "relay mounted and started successfully"
|
||||
|
||||
|
||||
## Helpers
|
||||
|
Loading…
x
Reference in New Issue
Block a user