2020-07-20 10:01:49 +00:00
|
|
|
# Waku APIs
|
2020-07-07 04:54:31 +00:00
|
|
|
|
|
|
|
## Nim API
|
|
|
|
|
2020-10-06 03:33:28 +00: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 04:54:31 +00:00
|
|
|
|
2020-10-06 03:33:28 +00: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 10:01:49 +00:00
|
|
|
|
|
|
|
```Nim
|
2020-10-06 03:33:28 +00:00
|
|
|
proc init*(T: type WakuNode, nodeKey: crypto.PrivateKey,
|
|
|
|
bindIp: ValidIpAddress, bindPort: Port,
|
|
|
|
extIp = none[ValidIpAddress](), extPort = none[Port](), topics = newSeq[string]()): T =
|
|
|
|
## Creates a Waku Node.
|
2020-07-27 09:01:06 +00:00
|
|
|
##
|
2020-07-28 08:06:00 +00:00
|
|
|
## Status: Implemented.
|
2020-07-27 09:01:06 +00:00
|
|
|
|
2020-10-06 03:33:28 +00:00
|
|
|
proc start*(node: WakuNode) {.async.} =
|
|
|
|
## Starts a created Waku Node.
|
|
|
|
##
|
|
|
|
## Status: Implemented.
|
|
|
|
|
|
|
|
proc subscribe*(node: WakuNode, topic: Topic, handler: TopicHandler) {.async.} =
|
2020-07-27 09:01:06 +00:00
|
|
|
## Subscribes to a PubSub topic. Triggers handler when receiving messages on
|
2020-08-27 10:15:46 +00:00
|
|
|
## this topic. TopicHandler is a method that takes a topic and some data.
|
2020-07-27 09:01:06 +00:00
|
|
|
##
|
2020-08-27 10:15:46 +00:00
|
|
|
## NOTE The data field SHOULD be decoded as a WakuMessage.
|
|
|
|
## Status: Implemented.
|
2020-07-27 09:01:06 +00:00
|
|
|
|
2020-10-06 03:33:28 +00:00
|
|
|
proc subscribe*(node: WakuNode, request: FilterRequest, handler: ContentFilterHandler) {.async, gcsafe.} =
|
2020-10-02 12:48:56 +00: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 09:01:06 +00:00
|
|
|
|
2020-10-06 03:33:28 +00:00
|
|
|
proc unsubscribe*(w: WakuNode, topic: Topic) =
|
2020-07-27 09:01:06 +00:00
|
|
|
## Unsubscribe from a topic.
|
|
|
|
##
|
|
|
|
## Status: Not yet implemented.
|
|
|
|
## TODO Implement.
|
|
|
|
|
2020-10-06 03:33:28 +00:00
|
|
|
proc unsubscribe*(w: WakuNode, contentFilter: ContentFilter) =
|
2020-07-27 09:01:06 +00:00
|
|
|
## Unsubscribe from a content filter.
|
|
|
|
##
|
|
|
|
## Status: Not yet implemented.
|
|
|
|
## TODO Implement.
|
|
|
|
|
2020-10-06 03:33:28 +00:00
|
|
|
proc publish*(node: WakuNode, topic: Topic, message: WakuMessage) =
|
2020-09-01 15:20:38 +00: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 09:01:06 +00:00
|
|
|
##
|
2020-09-01 15:20:38 +00:00
|
|
|
## Status: Implemented.
|
2020-07-27 09:01:06 +00:00
|
|
|
|
2020-10-06 03:33:28 +00:00
|
|
|
proc query*(w: WakuNode, query: HistoryQuery, handler: QueryHandlerFunc) {.async, gcsafe.} =
|
2020-09-24 02:16:25 +00: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 09:01:06 +00:00
|
|
|
##
|
2020-09-24 02:16:25 +00:00
|
|
|
## Status: Implemented.
|
2020-10-06 03:33:28 +00: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 04:54:31 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## JSON RPC
|
|
|
|
|
2020-10-06 03:33:28 +00:00
|
|
|
TODO To specify
|