mirror of
https://github.com/waku-org/nwaku.git
synced 2025-02-10 05:55:08 +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
@ -140,6 +140,11 @@ type
|
|||||||
defaultValue: false
|
defaultValue: false
|
||||||
name: "log-metrics" }: bool
|
name: "log-metrics" }: bool
|
||||||
|
|
||||||
|
topics* {.
|
||||||
|
desc: "Default topics to subscribe to (space seperated list)."
|
||||||
|
defaultValue: "waku"
|
||||||
|
name: "topics" .}: string
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
# - discv5 + topic register
|
# - discv5 + topic register
|
||||||
# - mailserver functionality
|
# - mailserver functionality
|
||||||
|
@ -55,7 +55,7 @@ template tcpEndPoint(address, port): auto =
|
|||||||
|
|
||||||
proc init*(T: type WakuNode, nodeKey: crypto.PrivateKey,
|
proc init*(T: type WakuNode, nodeKey: crypto.PrivateKey,
|
||||||
bindIp: ValidIpAddress, bindPort: Port,
|
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.
|
## Creates and starts a Waku node.
|
||||||
let
|
let
|
||||||
hostAddress = tcpEndPoint(bindIp, bindPort)
|
hostAddress = tcpEndPoint(bindIp, bindPort)
|
||||||
@ -69,7 +69,13 @@ proc init*(T: type WakuNode, nodeKey: crypto.PrivateKey,
|
|||||||
|
|
||||||
var switch = newStandardSwitch(some(nodekey), hostAddress, triggerSelf = true)
|
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.} =
|
proc start*(node: WakuNode) {.async.} =
|
||||||
node.libp2pTransportLoops = await node.switch.start()
|
node.libp2pTransportLoops = await node.switch.start()
|
||||||
@ -226,7 +232,7 @@ when isMainModule:
|
|||||||
Port(uint16(conf.tcpPort) + conf.portsShift),
|
Port(uint16(conf.tcpPort) + conf.portsShift),
|
||||||
Port(uint16(conf.udpPort) + conf.portsShift))
|
Port(uint16(conf.udpPort) + conf.portsShift))
|
||||||
node = WakuNode.init(conf.nodeKey, conf.libp2pAddress,
|
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()
|
waitFor node.start()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user