2020-07-20 12:01:49 +02:00
|
|
|
# Waku APIs
|
2020-07-07 12:54:31 +08:00
|
|
|
|
|
|
|
## Nim API
|
|
|
|
|
2020-10-06 11:33:28 +08:00
|
|
|
The Nim Waku API consist of a set of methods opearting on the Waku Node object.
|
|
|
|
Some of them have different arity depending on what privacy/bandwidth trade-off
|
|
|
|
the consumer wants to make. These methods are:
|
2020-07-07 12:54:31 +08:00
|
|
|
|
2020-10-06 11:33:28 +08:00
|
|
|
1. **Init** - create a node.
|
|
|
|
2. **Start** - start a created node.
|
|
|
|
3. **Subscribe** - to a topic or a specific content filter.
|
|
|
|
4. **Unsubscribe** - to a topic or a specific content filter.
|
|
|
|
5. **Publish** - to a topic, or a topic and a specific content filter.
|
|
|
|
6. **Query** - for historical messages.
|
|
|
|
7. **Info** - to get information about the node.
|
2020-07-20 12:01:49 +02:00
|
|
|
|
|
|
|
```Nim
|
2020-10-06 11:33:28 +08:00
|
|
|
proc init*(T: type WakuNode, nodeKey: crypto.PrivateKey,
|
|
|
|
bindIp: ValidIpAddress, bindPort: Port,
|
2020-10-22 13:12:00 +02:00
|
|
|
extIp = none[ValidIpAddress](), extPort = none[Port]()): T =
|
2020-10-06 11:33:28 +08:00
|
|
|
## Creates a Waku Node.
|
2020-07-27 17:01:06 +08:00
|
|
|
##
|
2020-07-28 16:06:00 +08:00
|
|
|
## Status: Implemented.
|
2020-07-27 17:01:06 +08:00
|
|
|
|
2020-10-06 11:33:28 +08:00
|
|
|
proc start*(node: WakuNode) {.async.} =
|
|
|
|
## Starts a created Waku Node.
|
|
|
|
##
|
|
|
|
## Status: Implemented.
|
|
|
|
|
2021-02-02 13:33:59 +02:00
|
|
|
proc subscribe*(node: WakuNode, topic: Topic, handler: TopicHandler) =
|
2020-07-27 17:01:06 +08:00
|
|
|
## Subscribes to a PubSub topic. Triggers handler when receiving messages on
|
2020-08-27 18:15:46 +08:00
|
|
|
## this topic. TopicHandler is a method that takes a topic and some data.
|
2020-07-27 17:01:06 +08:00
|
|
|
##
|
2020-08-27 18:15:46 +08:00
|
|
|
## NOTE The data field SHOULD be decoded as a WakuMessage.
|
|
|
|
## Status: Implemented.
|
2020-07-27 17:01:06 +08:00
|
|
|
|
2020-10-06 11:33:28 +08:00
|
|
|
proc subscribe*(node: WakuNode, request: FilterRequest, handler: ContentFilterHandler) {.async, gcsafe.} =
|
2020-10-02 14:48:56 +02:00
|
|
|
## Registers for messages that match a specific filter. Triggers the handler whenever a message is received.
|
|
|
|
## FilterHandler is a method that takes a MessagePush.
|
|
|
|
##
|
|
|
|
## Status: Implemented.
|
2020-07-27 17:01:06 +08:00
|
|
|
|
2021-02-02 13:33:59 +02:00
|
|
|
proc unsubscribe*(node: WakuNode, topic: Topic, handler: TopicHandler) =
|
2020-10-27 03:13:56 +02:00
|
|
|
## Unsubscribes a handler from a PubSub topic.
|
2020-07-27 17:01:06 +08:00
|
|
|
##
|
2020-10-27 03:13:56 +02:00
|
|
|
## Status: Implemented.
|
|
|
|
|
2021-02-02 13:33:59 +02:00
|
|
|
proc unsubscribeAll*(node: WakuNode, topic: Topic) =
|
2020-10-27 03:13:56 +02:00
|
|
|
## Unsubscribes all handlers registered on a specific PubSub topic.
|
|
|
|
##
|
|
|
|
## Status: Implemented.
|
2020-07-27 17:01:06 +08:00
|
|
|
|
2020-10-06 11:33:28 +08:00
|
|
|
proc unsubscribe*(w: WakuNode, contentFilter: ContentFilter) =
|
2020-07-27 17:01:06 +08:00
|
|
|
## Unsubscribe from a content filter.
|
|
|
|
##
|
|
|
|
## Status: Not yet implemented.
|
|
|
|
## TODO Implement.
|
|
|
|
|
2020-10-06 11:33:28 +08:00
|
|
|
proc publish*(node: WakuNode, topic: Topic, message: WakuMessage) =
|
2020-09-01 23:20:38 +08:00
|
|
|
## Publish a `WakuMessage` to a PubSub topic. `WakuMessage` should contain a
|
|
|
|
## `contentTopic` field for light node functionality. This field may be also
|
|
|
|
## be omitted.
|
2020-07-27 17:01:06 +08:00
|
|
|
##
|
2020-09-01 23:20:38 +08:00
|
|
|
## Status: Implemented.
|
2020-07-27 17:01:06 +08:00
|
|
|
|
2020-10-06 11:33:28 +08:00
|
|
|
proc query*(w: WakuNode, query: HistoryQuery, handler: QueryHandlerFunc) {.async, gcsafe.} =
|
2020-09-24 04:16:25 +02:00
|
|
|
## Queries known nodes for historical messages. Triggers the handler whenever a response is received.
|
|
|
|
## QueryHandlerFunc is a method that takes a HistoryResponse.
|
2020-07-27 17:01:06 +08:00
|
|
|
##
|
2020-09-24 04:16:25 +02:00
|
|
|
## Status: Implemented.
|
2020-10-06 11:33:28 +08:00
|
|
|
|
|
|
|
proc info*(node: WakuNode): WakuInfo =
|
|
|
|
## Returns information about the Node, such as what multiaddress it can be reached at.
|
|
|
|
##
|
|
|
|
## Status: Implemented.
|
|
|
|
##
|
2020-07-07 12:54:31 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
## JSON RPC
|
|
|
|
|
2020-10-06 11:33:28 +08:00
|
|
|
TODO To specify
|