The criteria to create subscription to a light node in JSON Format:
```ts
{
contentFilters: ContentFilter[];
pubsubTopic: string?;
}
```
Fields:
-`contentFilters`: Array of [`ContentFilter`](#contentfilter-type) being subscribed to / unsubscribed from.
-`topic`: Optional pubsub topic.
### `ContentFilter` type
```ts
{
contentTopic: string;
}
```
Fields:
-`contentTopic`: The content topic of a Waku message.
### `StoreQuery` type
Criteria used to retrieve historical messages
```ts
interface StoreQuery {
pubsubTopic?: string;
contentFilters?: ContentFilter[];
startTime?: number;
endTime?: number;
pagingOptions?: PagingOptions
}
```
Fields:
-`pubsubTopic`: The pubsub topic on which messages are published.
-`contentFilters`: Array of [`ContentFilter`](#contentfilter-type) to query for historical messages,
-`startTime`: The inclusive lower bound on the timestamp of queried messages. This field holds the Unix epoch time in nanoseconds.
-`endTime`: The inclusive upper bound on the timestamp of queried messages. This field holds the Unix epoch time in nanoseconds.
-`pagingOptions`: Paging information in [`PagingOptions`](#pagingoptions-type) format.
### `StoreResponse` type
The response received after doing a query to a store node:
```ts
interface StoreResponse {
messages: JsonMessage[];
pagingOptions?: PagingOptions;
}
```
Fields:
-`messages`: Array of retrieved historical messages in [`JsonMessage`](#jsonmessage-type) format.
-`pagingOption`: Paging information in [`PagingOptions`](#pagingoptions-type) format from which to resume further historical queries
### `PagingOptions` type
```ts
interface PagingOptions {
pageSize: number;
cursor?: Index;
forward: bool;
}
```
Fields:
-`pageSize`: Number of messages to retrieve per page.
-`cursor`: Message Index from which to perform pagination. If not included and forward is set to true, paging will be performed from the beginning of the list. If not included and forward is set to false, paging will be performed from the end of the list.
-`forward`: `true` if paging forward, `false` if paging backward
### `Index` type
```ts
interface Index {
digest: string;
receiverTime: number;
senderTime: number;
pubsubTopic: string;
}
```
Fields:
-`digest`: Hash of the message at this [`Index`](#index-type).
-`receiverTime`: UNIX timestamp in nanoseconds at which the message at this [`Index`](#index-type) was received.
-`senderTime`: UNIX timestamp in nanoseconds at which the message is generated by its sender.
-`pubsubTopic`: The pubsub topic of the message at this [`Index`](#index-type).
If a key is `undefined`, or `null`, a default value will be set.
-`d`: optimal degree for a GossipSub topic mesh.
Default `6`
-`dLow`: lower bound on the number of peers we keep in a GossipSub topic mesh
Default `5`
-`dHigh`: upper bound on the number of peers we keep in a GossipSub topic mesh.
Default `12`
-`dScore`: affects how peers are selected when pruning a mesh due to over subscription.
Default `4`
-`dOut`: sets the quota for the number of outbound connections to maintain in a topic mesh.
Default `2`
-`historyLength`: controls the size of the message cache used for gossip.
Default `5`
-`historyGossip`: controls how many cached message ids we will advertise in IHAVE gossip messages.
Default `3`
-`dLazy`: affects how many peers we will emit gossip to at each heartbeat.
Default `6`
-`gossipFactor`: affects how many peers we will emit gossip to at each heartbeat.
Default `0.25`
-`gossipRetransmission`: controls how many times we will allow a peer to request the same message id through IWANT gossip before we start ignoring them.
Default `3`
-`heartbeatInitialDelayMs`: short delay in milliseconds before the heartbeat timer begins after the router is initialized.
Default `100` milliseconds
-`heartbeatIntervalSeconds`: controls the time between heartbeats.
Default `1` second
-`slowHeartbeatWarning`: duration threshold for heartbeat processing before emitting a warning.
Default `0.1`
-`fanoutTTLSeconds`: controls how long we keep track of the fanout state.
Default `60` seconds
-`prunePeers`: controls the number of peers to include in prune Peer eXchange.
Default `16`
-`pruneBackoffSeconds`: controls the backoff time for pruned peers.
Default `60` seconds
-`unsubscribeBackoffSeconds`: controls the backoff time to use when unsuscribing from a topic.
Default `10` seconds
-`connectors`: number of active connection attempts for peers obtained through PX.
Default `8`
-`maxPendingConnections`: maximum number of pending connections for peers attempted through px.
Default `128`
-`connectionTimeoutSeconds`: timeout in seconds for connection attempts.
Default `30` seconds
-`directConnectTicks`: the number of heartbeat ticks for attempting to reconnect direct peers that are not currently connected.
Default `300`
-`directConnectInitialDelaySeconds`: initial delay before opening connections to direct peers.
Default `1` second
-`opportunisticGraftTicks`: number of heartbeat ticks for attempting to improve the mesh with opportunistic grafting.
Default `60`
-`opportunisticGraftPeers`: the number of peers to opportunistically graft.
Default `2`
-`graftFloodThresholdSeconds`: If a GRAFT comes before GraftFloodThresholdSeconds has elapsed since the last PRUNE, then there is an extra score penalty applied to the peer through P7.
Default `10` seconds
-`maxIHaveLength`: max number of messages to include in an IHAVE message, also controls the max number of IHAVE ids we will accept and request with IWANT from a peer within a heartbeat.
Default `5000`
-`maxIHaveMessages`: max number of IHAVE messages to accept from a peer within a heartbeat.
Default `10`
-`iWantFollowupTimeSeconds`: Time to wait for a message requested through IWANT following an IHAVE advertisement.
Default `3` seconds
-`seenMessagesTTLSeconds`: configures when a previously seen message ID can be forgotten about.
### `extern char* waku_filter_subscribe(char* filterJSON, char* peerID, int timeoutMs)`
Creates a subscription in a lightnode for messages that matches a content filter and optionally a [PubSub `topic`](https://github.com/libp2p/specs/blob/master/pubsub/README.md#the-topic-descriptor).
**Parameters**
1.`char* filterJSON`: JSON string containing the [`FilterSubscription`](#filtersubscription-type) to subscribe to.
2.`char* peerID`: Peer ID to subscribe to.
The peer must be already known.
It must have been added before with [`waku_add_peer`](#extern-char-waku_add_peerchar-address-char-protocolid)
or previously dialed with [`waku_connect_peer`](#extern-char-waku_connect_peerchar-address-int-timeoutms).
Use `NULL` to automatically select a node.
3.`int timeoutMs`: Timeout value in milliseconds to execute the call.
If the function execution takes longer than this value,
the execution will be canceled and an error returned.
Use `0` for no timeout.
**Returns**
A [`JsonResponse`](#jsonresponse-type).
If the execution is successful, the `result` field is set to `true`.
For example:
```json
{
"result": true
}
```
**Events**
When a message is received, a ``"message"` event` is emitted containing the message, pubsub topic, and node ID in which
the message was received.
The `event` type is [`JsonMessageEvent`](#jsonmessageevent-type).
### `extern char* waku_filter_unsubscribe(char* filterJSON, int timeoutMs)`
Removes subscriptions in a light node matching a content filter and, optionally, a [PubSub `topic`](https://github.com/libp2p/specs/blob/master/pubsub/README.md#the-topic-descriptor).
**Parameters**
1.`char* filterJSON`: JSON string containing the [`FilterSubscription`](#filtersubscription-type).
2.`int timeoutMs`: Timeout value in milliseconds to execute the call.
If the function execution takes longer than this value,
the execution will be canceled and an error returned.
Use `0` for no timeout.
**Returns**
A [`JsonResponse`](#jsonresponse-type).
If the execution is successful, the `result` field is set to `true`.
1.`char* messageJson`: JSON string containing the [Waku Message](https://rfc.vac.dev/spec/14/) as [`JsonMessage`](#jsonmessage-type).
2.`char* pubsubTopic`: pubsub topic on which to publish the message.
If `NULL`, it uses the default pubsub topic.
3.`char* peerID`: Peer ID supporting the lightpush protocol.
The peer must be already known.
It must have been added before with [`waku_add_peer`](#extern-char-waku_add_peerchar-address-char-protocolid)
or previously dialed with [`waku_connect_peer`](#extern-char-waku_connect_peerchar-address-int-timeoutms).
4.`char* symmetricKey`: hex encoded secret key to be used for encryption.
5.`char* optionalSigningKey`: hex encoded private key to be used to sign the message.
6.`int timeoutMs`: Timeout value in milliseconds to execute the call.
If the function execution takes longer than this value,
the execution will be canceled and an error returned.
Use `0` for no timeout.
Note: `messageJson.version` is overwritten to `1`.
**Returns**
A [`JsonResponse`](#jsonresponse-type).
If the execution is successful, the `result` field contains the message ID.
## Waku Store
### `extern char* waku_store_query(char* queryJSON, char* peerID, int timeoutMs)`
Retrieves historical messages on specific content topics. This method may be called with [`PagingOptions`](#pagingoptions-type),
to retrieve historical messages on a per-page basis. If the request included [`PagingOptions`](#pagingoptions-type), the node
must return messages on a per-page basis and include [`PagingOptions`](#pagingoptions-type) in the response. These [`PagingOptions`](#pagingoptions-type)
must contain a cursor pointing to the Index from which a new page can be requested.
**Parameters**
1.`char* queryJSON`: JSON string containing the [`StoreQuery`](#storequery-type).
2.`char* peerID`: Peer ID supporting the store protocol.
The peer must be already known.
It must have been added before with [`waku_add_peer`](#extern-char-waku_add_peerchar-address-char-protocolid)
or previously dialed with [`waku_connect_peer`](#extern-char-waku_connect_peerchar-address-int-timeoutms).
3.`int timeoutMs`: Timeout value in milliseconds to execute the call.
If the function execution takes longer than this value,
the execution will be canceled and an error returned.
Use `0` for no timeout.
**Returns**
A [`JsonResponse`](#jsonresponse-type).
If the execution is successful, the `result` field contains a [`StoreResponse`](#storeresponse-type)..
Useful for creating the payload of a Waku Message in the format understood by [`waku_relay_publish`](#extern-char-waku_relay_publishchar-messagejson-char-pubsubtopic-int-timeoutms)
**Parameters**
1.`char* data`: Byte array to encode
**Returns**
A `char *` containing the base64 encoded byte array.