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.
|
2021-05-26 19:33:22 +00:00
|
|
|
8. **Resume** - to retrieve and persist the message history since the node's last online time.
|
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,
|
2020-10-22 11:12:00 +00:00
|
|
|
extIp = none[ValidIpAddress](), extPort = none[Port]()): T =
|
2020-10-06 03:33:28 +00:00
|
|
|
## 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.
|
|
|
|
|
2021-02-02 11:33:59 +00:00
|
|
|
proc subscribe*(node: WakuNode, topic: Topic, handler: TopicHandler) =
|
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
|
|
|
|
2021-02-02 11:33:59 +00:00
|
|
|
proc unsubscribe*(node: WakuNode, topic: Topic, handler: TopicHandler) =
|
2020-10-27 01:13:56 +00:00
|
|
|
## Unsubscribes a handler from a PubSub topic.
|
2020-07-27 09:01:06 +00:00
|
|
|
##
|
2020-10-27 01:13:56 +00:00
|
|
|
## Status: Implemented.
|
|
|
|
|
2021-02-02 11:33:59 +00:00
|
|
|
proc unsubscribeAll*(node: WakuNode, topic: Topic) =
|
2020-10-27 01:13:56 +00:00
|
|
|
## Unsubscribes all handlers registered on a specific PubSub topic.
|
|
|
|
##
|
|
|
|
## Status: Implemented.
|
2020-07-27 09:01:06 +00:00
|
|
|
|
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.
|
|
|
|
##
|
2021-05-26 19:33:22 +00:00
|
|
|
|
|
|
|
proc resume*(node: WakuNode, peerList: Option[seq[PeerInfo]]) =
|
|
|
|
## Retrieves and persists the history of waku messages published on the default waku pubsub topic since the last time the waku node has been online.
|
|
|
|
## It requires the waku node to have the store protocol mounted in the full mode (i.e., persisting messages).
|
2022-01-18 22:05:41 +00:00
|
|
|
## `peerList` indicates the list of peers to query from.
|
|
|
|
## The history is fetched from all available peers in this list and then consolidated into one deduplicated list.
|
2021-05-26 19:33:22 +00:00
|
|
|
## If no peerList is passed, the history is fetched from one of the known peers.
|
|
|
|
## It retrieves the history successfully given that the dialed peer has been online during the queried time window.
|
|
|
|
##
|
|
|
|
## Status: Implemented.
|
|
|
|
##
|
2020-07-07 04:54:31 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## JSON RPC
|
|
|
|
|
2020-10-06 03:33:28 +00:00
|
|
|
TODO To specify
|
2022-06-28 10:22:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
## REST API
|
|
|
|
|
|
|
|
[Here](./rest-api.md) you can find more details on the Node HTTP REST API.
|