mirror of https://github.com/waku-org/nwaku.git
Waku v2: Update docs and API with current state (#110)
* Waku v2: Update docs and API with current state - Publish and subscribe implemented - Three protocol split * Update docs/api/v2/node.md Co-authored-by: Kim De Mey <kim.demey@gmail.com> * Update waku/node/v2/wakunode2.nim Co-authored-by: Kim De Mey <kim.demey@gmail.com> Co-authored-by: Kim De Mey <kim.demey@gmail.com>
This commit is contained in:
parent
e875dfd1d7
commit
bab0e12d68
|
@ -20,11 +20,10 @@ proc init*(T: type WakuNode, conf: WakuNodeConf): Future[T]
|
|||
|
||||
method subscribe*(w: 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 a `Message`.
|
||||
## this topic. TopicHandler is a method that takes a topic and some data.
|
||||
##
|
||||
## Status: Not yet implemented.
|
||||
## TODO Implement as wrapper around `waku_protocol`, and ensure Message is
|
||||
## passed, not `data` field.
|
||||
## NOTE The data field SHOULD be decoded as a WakuMessage.
|
||||
## Status: Implemented.
|
||||
|
||||
method subscribe*(w: WakuNode, contentFilter: ContentFilter, handler: ContentFilterHandler)
|
||||
## Subscribes to a ContentFilter. Triggers handler when receiving messages on
|
||||
|
@ -33,8 +32,7 @@ method subscribe*(w: WakuNode, contentFilter: ContentFilter, handler: ContentFil
|
|||
## has to match the `ContentTopic`.
|
||||
|
||||
## Status: Not yet implemented.
|
||||
## TODO Implement as wrapper around `waku_protocol` and `subscribe` above, and
|
||||
## ensure Message is passed, not `data` field.
|
||||
## TODO Implement as wrapper around `waku_filter` and `subscribe` above.
|
||||
|
||||
method unsubscribe*(w: WakuNode, topic: Topic)
|
||||
## Unsubscribe from a topic.
|
||||
|
@ -51,24 +49,22 @@ method unsubscribe*(w: WakuNode, contentFilter: ContentFilter)
|
|||
method publish*(w: WakuNode, topic: Topic, message: Message)
|
||||
## Publish a `Message` to a PubSub topic.
|
||||
##
|
||||
## Status: Not yet implemented.
|
||||
## TODO Implement as wrapper around `waku_protocol`, and ensure Message is
|
||||
## passed, not `data` field.
|
||||
## Status: Partially implemented.
|
||||
## TODO WakuMessage OR seq[byte]. NOT PubSub Message.
|
||||
|
||||
method publish*(w: WakuNode, topic: Topic, contentFilter: ContentFilter, message: Message)
|
||||
## Publish a `Message` to a PubSub topic with a specific content filter.
|
||||
## Currently this means a `contentTopic`.
|
||||
##
|
||||
## Status: Not yet implemented.
|
||||
## TODO Implement as wrapper around `waku_protocol` and `publish`, and ensure
|
||||
## Message is passed, not `data` field. Also ensure content filter is in
|
||||
## Message.
|
||||
## TODO Implement as wrapper around `waku_relay` and `publish`.
|
||||
## TODO WakuMessage. Ensure content filter is in it.
|
||||
|
||||
method query*(w: WakuNode, query: HistoryQuery): HistoryResponse
|
||||
## Queries for historical messages.
|
||||
##
|
||||
## Status: Not yet implemented.
|
||||
## TODO Implement as wrapper around `waku_protocol` and send `RPCMsg`.
|
||||
## TODO Implement as wrapper around `waku_store` and send RPC.
|
||||
```
|
||||
|
||||
## JSON RPC
|
||||
|
|
|
@ -33,30 +33,3 @@ proc runBackground(conf: WakuNodeConf) {.async.} =
|
|||
discard runBackground(conf)
|
||||
|
||||
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
|
||||
# - We can use JSON RPC
|
||||
|
||||
# TODO Subscribe and publish to topic via Node API
|
||||
# Requires https://github.com/status-im/nim-waku/issues/53
|
||||
|
||||
# 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"
|
||||
|
||||
#createRpcSigs(RpcHttpClient, sigWakuPath)
|
||||
|
||||
# Create RPC Client and connect to it
|
||||
#var node = newRpcHttpClient()
|
||||
#waitfor node.connect("localhost", Port(8547))
|
||||
|
||||
# TODO Do something with res
|
||||
#var res = waitFor node.wakuSubscribe("apptopic")
|
||||
|
||||
# TODO Use publish as well
|
||||
|
|
|
@ -243,24 +243,21 @@ method init*(T: type WakuNode, conf: WakuNodeConf): Future[T] {.async.} =
|
|||
await node.start(conf)
|
||||
return node
|
||||
|
||||
# TODO Update TopicHandler to take Message, not seq[byte] data
|
||||
#type TopicHandler* = proc(topic: Topic, message: Message)
|
||||
# Currently this is using the one in pubsub.nim, roughly:
|
||||
# NOTE TopicHandler is defined in pubsub.nim, roughly:
|
||||
#type TopicHandler* = proc(topic: string, data: seq[byte])
|
||||
|
||||
type ContentFilterHandler* = proc(contentFilter: ContentFilter, message: Message)
|
||||
|
||||
method subscribe*(w: 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 a `Message`.
|
||||
## this topic. TopicHandler is a method that takes a topic and some data.
|
||||
##
|
||||
## Status: Partially implemented.
|
||||
## TODO Ensure Message is passed, not `data` field. This means modifying
|
||||
## TopicHandler.
|
||||
## NOTE The data field SHOULD be decoded as a WakuMessage.
|
||||
## Status: Implemented.
|
||||
|
||||
let wakuSub = w.switch.pubSub.get()
|
||||
let wakuRelay = w.switch.pubSub.get()
|
||||
# XXX Consider awaiting here
|
||||
discard wakuSub.subscribe(topic, handler)
|
||||
discard wakuRelay.subscribe(topic, handler)
|
||||
|
||||
method subscribe*(w: WakuNode, contentFilter: ContentFilter, handler: ContentFilterHandler) =
|
||||
echo "NYI"
|
||||
|
@ -270,8 +267,7 @@ method subscribe*(w: WakuNode, contentFilter: ContentFilter, handler: ContentFil
|
|||
## has to match the `ContentTopic`.
|
||||
|
||||
## Status: Not yet implemented.
|
||||
## TODO Implement as wrapper around `waku_protocol` and `subscribe` above, and
|
||||
## ensure Message is passed, not `data` field.
|
||||
## TODO Implement as wrapper around `waku_filter` and `subscribe` above.
|
||||
|
||||
method unsubscribe*(w: WakuNode, topic: Topic) =
|
||||
echo "NYI"
|
||||
|
@ -291,7 +287,8 @@ method publish*(w: WakuNode, topic: Topic, message: Message) =
|
|||
## Publish a `Message` to a PubSub topic.
|
||||
##
|
||||
## Status: Partially implemented.
|
||||
## TODO: Esure Message is passed, not seq[byte] `data` field.
|
||||
##
|
||||
## TODO WakuMessage OR seq[byte]. NOT PubSub Message.
|
||||
let wakuSub = w.switch.pubSub.get()
|
||||
# XXX Consider awaiting here
|
||||
discard wakuSub.publish(topic, message)
|
||||
|
@ -301,24 +298,21 @@ method publish*(w: WakuNode, topic: Topic, contentFilter: ContentFilter, message
|
|||
## Currently this means a `contentTopic`.
|
||||
##
|
||||
## Status: Not yet implemented.
|
||||
## TODO Implement as wrapper around `waku_protocol` and `publish`, and ensure
|
||||
## Message is passed, not `data` field. Also ensure content filter is in
|
||||
## Message.
|
||||
##
|
||||
## TODO Implement as wrapper around `waku_relay` and `publish`.
|
||||
## TODO WakuMessage. Ensure content filter is in it.
|
||||
|
||||
w.messages.insert((contentFilter.contentTopic, message))
|
||||
|
||||
let wakuSub = w.switch.pubSub.get()
|
||||
# XXX Consider awaiting here
|
||||
|
||||
# @TODO MAKE SURE WE PASS CONTENT FILTER
|
||||
discard wakuSub.publish(topic, message)
|
||||
|
||||
method query*(w: WakuNode, query: HistoryQuery): HistoryResponse =
|
||||
## Queries for historical messages.
|
||||
##
|
||||
## Status: Not yet implemented.
|
||||
## TODO Implement as wrapper around `waku_protocol` and send `RPCMsg`.
|
||||
## TODO Implement as wrapper around `waku_store` and send RPC.
|
||||
result.messages = newSeq[Message]()
|
||||
|
||||
for msg in w.messages:
|
||||
|
|
Loading…
Reference in New Issue