diff --git a/docs/api/v2/node.md b/docs/api/v2/node.md index a3bc686b0..f26dcd303 100644 --- a/docs/api/v2/node.md +++ b/docs/api/v2/node.md @@ -16,8 +16,7 @@ five method are: proc init*(conf: WakuNodeConf): Future[WakuNode] ## Creates and starts a Waku node. ## - ## Status: Partially implemented. - ## TODO Take conf as a parameter and return a started WakuNode + ## Status: Implemented. method subscribe*(w: WakuNode, topic: Topic, handler: TopicHandler) ## Subscribes to a PubSub topic. Triggers handler when receiving messages on diff --git a/examples/v2/basic2.nim b/examples/v2/basic2.nim index 90e7c3760..d007e01c1 100644 --- a/examples/v2/basic2.nim +++ b/examples/v2/basic2.nim @@ -3,6 +3,7 @@ import confutils, chronicles, chronos, os +import stew/shims/net as stewNet import libp2p/crypto/crypto import libp2p/crypto/secp import eth/keys @@ -14,16 +15,18 @@ import ../../waku/node/v2/wakunode2 # Loads the config in `waku/node/v2/config.nim` let conf = WakuNodeConf.load() -# Start the node -# Running this should give you output like this: -# INF Listening on tid=5719 full=/ip4/127.0.0.1/tcp/60000/p2p/16Uiu2HAmNiAqr1cwhyntotP9fiSDyBvfKtB4ZiaDsrkipSCoKCB4 -# TODO Run this in background -# See https://github.com/status-im/nim-waku/pull/59 -proc runBackground(conf: WakuNodeConf) {.async.} = - run(conf) - runForever() +# Create and start the node +#proc runBackground(conf: WakuNodeConf) {.async.} = +# init(conf) +# runForever() -discard runBackground(conf) +discard init(conf) + +echo("Do stuff after with node") + +runForever() + +# TODO Lets start with Nim Node API first # To do more operations on this node, we can do this in two ways: # - We can use the Nim Node API, which is currently not exposed @@ -35,17 +38,17 @@ discard runBackground(conf) # Here's how to do it with JSON RPC # Get RPC call signatures in Nim -from strutils import rsplit -template sourceDir: string = currentSourcePath.parentDir().parentDir().rsplit(DirSep, 1)[0] -const sigWakuPath = sourceDir / "waku" / "node" / "v2" / "rpc" / "wakucallsigs.nim" +#from strutils import rsplit +#template sourceDir: string = currentSourcePath.parentDir().parentDir().rsplit(DirSep, 1)[0] +#const sigWakuPath = sourceDir / "waku" / "node" / "v2" / "rpc" / "wakucallsigs.nim" -createRpcSigs(RpcHttpClient, sigWakuPath) +#createRpcSigs(RpcHttpClient, sigWakuPath) # Create RPC Client and connect to it -var node = newRpcHttpClient() -waitfor node.connect("localhost", Port(8547)) +#var node = newRpcHttpClient() +#waitfor node.connect("localhost", Port(8547)) # TODO Do something with res -var res = waitFor node.wakuSubscribe("apptopic") +#var res = waitFor node.wakuSubscribe("apptopic") # TODO Use publish as well diff --git a/waku/node/v2/wakunode2.nim b/waku/node/v2/wakunode2.nim index 8cd1fcddc..b5dfb37e8 100644 --- a/waku/node/v2/wakunode2.nim +++ b/waku/node/v2/wakunode2.nim @@ -218,27 +218,12 @@ proc start*(node: WakuNode, conf: WakuNodeConf) {.async.} = addTimer(Moment.fromNow(2.seconds), logMetrics) addTimer(Moment.fromNow(2.seconds), logMetrics) -# TODO Get rid of this -# runForever() - -#proc run(conf: WakuNodeConf) {.async, gcsafe.} = - ## Public API ## -# TODO Take conf as a parameter and return a started WakuNode -proc init*() {.async.} = - let conf = WakuNodeConf.load() - let network = await createWakuNode(conf) - waitFor network.start(conf) - runForever() - -# TODO Replace init above -method init2*(conf: WakuNodeConf): Future[WakuNode] {.async.} = +method init*(conf: WakuNodeConf): Future[WakuNode] {.async.} = ## Creates and starts a Waku node. ## - ## Status: Partially implemented. - ## TODO Take conf as a parameter and return a started WakuNode let node = await createWakuNode(conf) await node.start(conf) return node @@ -316,4 +301,6 @@ method query*(w: WakuNode, query: HistoryQuery): HistoryResponse = ## TODO Implement as wrapper around `waku_protocol` and send `RPCMsg`. when isMainModule: - discard init() + let conf = WakuNodeConf.load() + discard init(conf) + runForever()