Make basic Waku v2 examples run again (#123)

* Make basic Waku v2 examples run again

Regression introduced in https://github.com/status-im/nim-waku/pull/117

Happened due to example not being run on CI.

- Add wakuexample to all target
- Fix example2 to run
- Basic formatting

* Update examples/v2/basic2.nim

Co-authored-by: Kim De Mey <kim.demey@gmail.com>

* Update examples/v2/basic2.nim

* Update examples/v2/basic2.nim

* Update examples/v2/basic2.nim

Co-authored-by: Kim De Mey <kim.demey@gmail.com>
This commit is contained in:
Oskar Thorén 2020-09-01 16:32:19 +08:00 committed by GitHub
parent 67a964be28
commit e8d3156571
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 22 deletions

View File

@ -47,7 +47,7 @@ GIT_SUBMODULE_UPDATE := git submodule update --init --recursive
else # "variables.mk" was included. Business as usual until the end of this file.
# default target, because it's the first one that doesn't start with '.'
all: | wakunode wakusim wakuexample wakunode2 wakusim2
all: | wakunode wakusim wakuexample wakunode2 wakusim2 wakuexample2
# must be included after the default target
-include $(BUILD_SYSTEM_DIR)/makefiles/targets.mk

View File

@ -1,25 +1,27 @@
# Here's an example of how you would start a Waku node, subscribe to topics, and
# publish to them
## Here's a basic example of how you would start a Waku node, subscribe to
## topics, and publish to them.
import confutils, chronicles, chronos, os
import stew/shims/net as stewNet
import libp2p/crypto/crypto
import libp2p/crypto/secp
import eth/keys
import json_rpc/[rpcclient, rpcserver]
import ../../waku/node/v2/config
import ../../waku/node/v2/wakunode2
import ../../waku/node/v2/waku_types
# Loads the config in `waku/node/v2/config.nim`
let conf = WakuNodeConf.load()
import
std/os,
confutils, chronicles, chronos,
stew/shims/net as stewNet,
libp2p/crypto/[crypto,secp],
eth/keys,
json_rpc/[rpcclient, rpcserver],
../../waku/node/v2/[config, wakunode2, waku_types],
../../waku/node/common
# Node operations happens asynchronously
proc runBackground(conf: WakuNodeConf) {.async.} =
# Create and start the node
let node = await WakuNode.init(conf)
proc runBackground() {.async.} =
let
conf = WakuNodeConf.load()
(extIp, extTcpPort, extUdpPort) = setupNat(conf.nat, clientId,
Port(uint16(conf.tcpPort) + conf.portsShift),
Port(uint16(conf.udpPort) + conf.portsShift))
node = WakuNode.init(conf.nodeKey, conf.libp2pAddress,
Port(uint16(conf.tcpPort) + conf.portsShift), extIp, extTcpPort)
await node.start()
# Subscribe to a topic
let topic = "foobar"
@ -31,6 +33,7 @@ proc runBackground(conf: WakuNodeConf) {.async.} =
let message = cast[seq[byte]]("hello world")
node.publish(topic, message)
discard runBackground(conf)
# TODO Await with try/except here
discard runBackground()
runForever()

View File

@ -30,7 +30,7 @@ type
HistoryResponse* = object
messages*: seq[Message]
const clientId = "Nimbus Waku v2 node"
const clientId* = "Nimbus Waku v2 node"
# NOTE Any difference here in Waku vs Eth2?
# E.g. Devp2p/Libp2p support, etc.