Skip to content

Commit 9cb8384

Browse files
authored
add manage filter guide (#132)
1 parent 7a975c8 commit 9cb8384

8 files changed

+75
-4
lines changed

.cspell.json

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"letsencrypt",
7272
"lightpushnode",
7373
"filternode",
74+
"instanceof",
7475
],
7576
"flagWords": [],
7677
"ignorePaths": [

diagrams/_filter-ping-flow.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
```mermaid
2+
graph TD
3+
A[Start Monitoring Filter Subscriptions] --> B{Check Peer Connection}
4+
B -- Connected --> C[Send Ping]
5+
C --> D{Ping Success?}
6+
D -- Yes --> B
7+
D -- No --> E[Handle Error/Reinitiate Subscription]
8+
B -- Disconnected --> F[Check Intentional Disconnection/Unsubscription]
9+
F -- Yes --> G[Stop Monitoring]
10+
F -- No --> B
11+
E --> B
12+
```

docs/guides/js-waku/debug-waku-dapp.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: How to Debug Your Waku DApp and WebSocket
2+
title: Debug Your Waku DApp and WebSocket
33
---
44

55
This guide provides detailed steps to enable and use debug logs to troubleshoot your Waku DApp, whether in a NodeJS or browser environment and check your WebSocket connections in [nwaku](/guides/run-nwaku-node).

docs/guides/js-waku/index.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ Have a look at the quick start guide and comprehensive tutorials to learn how to
8787
| [Bootstrap DApps Using @waku/create-app](/guides/js-waku/use-waku-create-app) | Learn how to use the [@waku/create-app](https://www.npmjs.com/package/@waku/create-app) package to bootstrap your next `@waku/sdk` project from various example templates |
8888
| [Bootstrap Nodes and Discover Peers](/guides/js-waku/configure-discovery) | Learn how to bootstrap your node using [Static Peers](/overview/concepts/static-peers) and discover peers using [DNS Discovery](/overview/concepts/dns-discovery) |
8989
| [Run @waku/sdk in a NodeJS Application](/guides/js-waku/run-waku-nodejs) | Learn our suggested approach for using the `@waku/sdk` package within a NodeJS application |
90-
| [How to Debug Your Waku DApp and WebSocket](/guides/js-waku/debug-waku-dapp) | Learn how to troubleshoot your Waku DApp using debug logs and check [WebSocket](/overview/concepts/transports) connections in [nwaku](/guides/run-nwaku-node) |
90+
| [Debug Your Waku DApp and WebSocket](/guides/js-waku/debug-waku-dapp) | Learn how to troubleshoot your Waku DApp using debug logs and check [WebSocket](/overview/concepts/transports) connections in [nwaku](/guides/run-nwaku-node) |
91+
| [Manage Your Filter Subscriptions](/guides/js-waku/manage-filter) | Learn how to manage [filter subscriptions](/overview/concepts/protocols#filter) and handle node disconnections in your application |
9192

9293
:::tip
9394
Until [node incentivisation](/overview/reference/research-in-progress#prevention-of-denial-of-service-dos-and-node-incentivisation) is in place, you should [operate extra nodes](/guides/nodes-and-sdks#run-a-waku-node) alongside the ones provided by the Waku Network. When running a node, we recommend using the [DNS Discovery and Static Peers](/guides/js-waku/configure-discovery#configure-dns-discovery-and-static-peers) configuration to connect to both the Waku Network and your node.

docs/guides/js-waku/light-send-receive.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Send and Receive Messages Using Light Push and Filter
33
---
44

5-
This guide provides detailed steps to start using the `@waku/sdk` package by setting up a Light Node to send messages using the [Light Push protocol](/overview/concepts/protocols#light-push), and receive messages using the [Filter protocol](/overview/concepts/protocols#filter). Have a look at the [installation guide](/guides/js-waku/#installation) for steps on adding `@waku/sdk` to your project.
5+
This guide provides detailed steps to start using the `@waku/sdk` package by setting up a [Light Node](/overview/reference/glossary#light-node) to send messages using the [Light Push protocol](/overview/concepts/protocols#light-push), and receive messages using the [Filter protocol](/overview/concepts/protocols#filter). Have a look at the [installation guide](/guides/js-waku/#installation) for steps on adding `@waku/sdk` to your project.
66

77
## Create a Light Node
88

docs/guides/js-waku/manage-filter.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: Manage Your Filter Subscriptions
3+
---
4+
5+
This guide provides detailed steps to manage [Filter](/overview/concepts/protocols#filter) subscriptions and handle node disconnections in your application. Have a look at the [Filter guide](/guides/js-waku/light-send-receive) for receiving messages with the `Light Push and Filter protocol`.
6+
7+
## Overview
8+
9+
Occasionally, your `Filter` subscriptions might disconnect from the Waku Network, resulting in messages not being received by your application. To manage your subscriptions, periodically ping peers to check for an active connection. The error message `"peer has no subscriptions"` indicates a failed ping due to disconnection. You can stop the pings if the disconnection/unsubscription is deliberate.
10+
11+
```mdx-code-block
12+
import FilterPingFlow from "@site/diagrams/_filter-ping-flow.md";
13+
14+
<FilterPingFlow />
15+
```
16+
17+
## Pinging Filter Subscriptions
18+
19+
The `@waku/sdk` package provides a `Filter.ping()` function to ping subscriptions and check for an active connection. To begin, create a `Filter` subscription:
20+
21+
```js
22+
// Create a Filter subscription
23+
const subscription = await node.filter.createSubscription();
24+
25+
// Subscribe to content topics and process new messages
26+
await subscription.subscribe([decoder], callback);
27+
```
28+
29+
Next, create a function to ping and reinitiate the subscription:
30+
31+
```js
32+
const pingAndReinitiateSubscription = async () => {
33+
try {
34+
// Ping the subscription
35+
await subscription.ping();
36+
} catch (error) {
37+
if (
38+
// Check if the error message includes "peer has no subscriptions"
39+
error instanceof Error &&
40+
error.message.includes("peer has no subscriptions")
41+
) {
42+
// Reinitiate the subscription if the ping fails
43+
await subscription.subscribe([decoder], callback);
44+
} else {
45+
throw error;
46+
}
47+
}
48+
};
49+
50+
// Periodically ping the subscription
51+
await pingAndReinitiateSubscription();
52+
```
53+
54+
:::success Congratulations!
55+
You have successfully managed your `Filter` subscriptions to handle node disconnections in your application.
56+
:::

docs/guides/nwaku/configure-nwaku.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ For example, consider a `nwaku` node that requests lightpush of published messag
242242
./build/wakunode2 --lightpushnode=/dns4/node-01.ac-cn-hongkong-c.wakuv2.prod.statusim.net/tcp/30303/p2p/16Uiu2HAm4v86W3bmT1BiH6oSPzcsSr24iDQpSN5Qa992BCjjwgrD
243243
```
244244

245-
## Run a Node Behind a Reverse Proxy
245+
## Run Nwaku Behind a Reverse Proxy
246246

247247
When using a reverse proxy server for SSL/TLS encryption, you only want to announce the proxy server's IP or domain. Nwaku provides the `ext-multiaddr-only` and `ext-multiaddr` options for specifying published multiaddr:
248248

sidebars.js

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const sidebars = {
7878
"guides/js-waku/configure-discovery",
7979
"guides/js-waku/run-waku-nodejs",
8080
"guides/js-waku/debug-waku-dapp",
81+
"guides/js-waku/manage-filter",
8182
{
8283
type: 'html',
8384
value: '<a href="https://examples.waku.org" target="_blank" rel="noopener noreferrer" class="menu__link external-link">@waku/sdk Examples<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M11.1918 4H3.42848V2.85715H13.1428V12.5714H11.9999V4.80813L3.83254 12.9755L3.02441 12.1674L11.1918 4Z" fill="white"/></svg>',

0 commit comments

Comments
 (0)