mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-26 14:51:49 +00:00
feature/subscribe-to-waku (#152)
* sub by default * added * fmt * fix * moved * removed * fix
This commit is contained in:
parent
4447a93884
commit
03895ffaf5
@ -139,6 +139,11 @@ type
|
||||
desc: "Enable metrics logging."
|
||||
defaultValue: false
|
||||
name: "log-metrics" }: bool
|
||||
|
||||
topics* {.
|
||||
desc: "Default topics to subscribe to (space seperated list)."
|
||||
defaultValue: "waku"
|
||||
name: "topics" .}: string
|
||||
|
||||
# TODO:
|
||||
# - discv5 + topic register
|
||||
|
@ -55,7 +55,7 @@ template tcpEndPoint(address, port): auto =
|
||||
|
||||
proc init*(T: type WakuNode, nodeKey: crypto.PrivateKey,
|
||||
bindIp: ValidIpAddress, bindPort: Port,
|
||||
extIp = none[ValidIpAddress](), extPort = none[Port]()): T =
|
||||
extIp = none[ValidIpAddress](), extPort = none[Port](), topics = newSeq[string]()): T =
|
||||
## Creates and starts a Waku node.
|
||||
let
|
||||
hostAddress = tcpEndPoint(bindIp, bindPort)
|
||||
@ -69,7 +69,13 @@ proc init*(T: type WakuNode, nodeKey: crypto.PrivateKey,
|
||||
|
||||
var switch = newStandardSwitch(some(nodekey), hostAddress, triggerSelf = true)
|
||||
|
||||
return WakuNode(switch: switch, peerInfo: peerInfo)
|
||||
result = WakuNode(switch: switch, peerInfo: peerInfo)
|
||||
|
||||
for topic in topics:
|
||||
proc handler(topic: string, data: seq[byte]) {.async, gcsafe.} =
|
||||
debug "Hit handler", topic=topic, data=data
|
||||
|
||||
result.subscribe(topic, handler)
|
||||
|
||||
proc start*(node: WakuNode) {.async.} =
|
||||
node.libp2pTransportLoops = await node.switch.start()
|
||||
@ -226,7 +232,7 @@ when isMainModule:
|
||||
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)
|
||||
Port(uint16(conf.tcpPort) + conf.portsShift), extIp, extTcpPort, conf.topics.split(" "))
|
||||
|
||||
waitFor node.start()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user