Skip to content

Commit

Permalink
Add explicit started state for wakunode2
Browse files Browse the repository at this point in the history
  • Loading branch information
jm-clius committed Apr 1, 2021
1 parent 8c112cd commit 31700c8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion waku/v2/node/wakunode2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -164,13 +165,17 @@ proc start*(node: WakuNode) {.async.} =

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.
Expand Down Expand Up @@ -419,7 +424,7 @@ proc mountRelay*(node: WakuNode, topics: seq[string] = newSeq[string](), rlnRela
addRLNRelayValidator(node, defaultTopic)
info "WakuRLNRelay is mounted successfully"

if node.libp2pTransportLoops.len > 0:
if node.started:
# Node has already started. Start the WakuRelay protocol

waitFor node.wakuRelay.start()
Expand Down

0 comments on commit 31700c8

Please sign in to comment.