add js-waku discovery (#100)

* add js-waku discovery

* implement feedback

* update logos preset
This commit is contained in:
LordGhostX 2023-08-03 06:40:57 +01:00 committed by GitHub
parent 11f3ae9037
commit 146949f7a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 213 additions and 22 deletions

View File

@ -0,0 +1,189 @@
---
title: Bootstrap Nodes and Discover Peers
---
This guide provides detailed steps to bootstrap your your node using [Static Peers](/overview/concepts/static-peers) and discover peers in the Waku Network using [DNS Discovery](/overview/concepts/dns-discovery).
:::tip
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.
:::
## Default Bootstrap Method
The `@waku/sdk` package provides a built-in bootstrapping method that uses [DNS Discovery](/overview/concepts/dns-discovery) to locate peers from the `waku v2.prod` `ENR` tree.
```js
import { createLightNode } from "@waku/sdk";
// Bootstrap node using the default bootstrap method
const node = await createLightNode({ defaultBootstrap: true });
```
## Configure Static Peers
To bootstrap a node using [static peers](/overview/concepts/static-peers), first install the `@libp2p/bootstrap` package:
```mdx-code-block
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
```
<Tabs groupId="package-manager">
<TabItem value="npm" label="npm">
```shell
npm install @libp2p/bootstrap
```
</TabItem>
<TabItem value="yarn" label="Yarn">
```shell
yarn add @libp2p/bootstrap
```
</TabItem>
</Tabs>
Then, use the `bootstrap()` function to provide a list of `multiaddr` to bootstrap the node:
```js
import { createLightNode } from "@waku/sdk";
import { bootstrap } from "@libp2p/bootstrap";
// Bootstrap node using static peers
const node = await createLightNode({
libp2p: {
peerDiscovery: [
bootstrap({ list: ["[PEER MULTIADDR]"] }),
],
},
});
```
For example, consider a node that connects to two static peers on the same local host (IP: `0.0.0.0`) using TCP ports `60002` and `60003`:
```js
// Define the list of static peers to bootstrap
const peers = [
"/ip4/0.0.0.0/tcp/60002/p2p/16Uiu2HAkzjwwgEAXfeGNMKFPSpc6vGBRqCdTLG5q3Gmk2v4pQw7H",
"/ip4/0.0.0.0/tcp/60003/p2p/16Uiu2HAmFBA7LGtwY5WVVikdmXVo3cKLqkmvVtuDu63fe8safeQJ",
];
// Bootstrap node using the static peers
const node = await createLightNode({
libp2p: {
peerDiscovery: [
bootstrap({ list: peers }),
],
},
});
```
## Configure DNS Discovery
To bootstrap a node using [DNS Discovery](/overview/concepts/dns-discovery), first install the `@waku/dns-discovery` package:
<Tabs groupId="package-manager">
<TabItem value="npm" label="npm">
```shell
npm install @waku/dns-discovery
```
</TabItem>
<TabItem value="yarn" label="Yarn">
```shell
yarn add @waku/dns-discovery
```
</TabItem>
</Tabs>
Then, use the `wakuDnsDiscovery()` function to provide a list of URLs for DNS node list in the format `enrtree://<key>@<fqdn>`:
```js
import { createLightNode } from "@waku/sdk";
import { wakuDnsDiscovery } from "@waku/dns-discovery";
// Define DNS node list
const enrTree = "enrtree://[PUBLIC KEY]@[DOMAIN NAME]";
// Define node requirements
const NODE_REQUIREMENTS = {
store: 3,
lightPush: 3,
filter: 3,
};
// Bootstrap node using DNS Discovery
const node = await createLightNode({
libp2p: {
peerDiscovery: [
wakuDnsDiscovery(
[enrTree],
NODE_REQUIREMENTS,
),
],
},
});
```
For example, consider a node that uses the `waku v2.prod` and `waku v2.test` `ENR` trees for `DNS Discovery`:
```js
import { enrTree } from "@waku/dns-discovery";
// Bootstrap node using DNS Discovery
const node = await createLightNode({
libp2p: {
peerDiscovery: [
wakuDnsDiscovery(
[enrTree["PROD"], enrTree["TEST"]],
NODE_REQUIREMENTS,
),
],
},
});
```
## Configure DNS Discovery and Static Peers
You can also bootstrap your node using [DNS Discovery](/overview/concepts/dns-discovery) and [Static Peers](/overview/concepts/static-peers) simultaneously:
```js
import { createLightNode } from "@waku/sdk";
import { bootstrap } from "@libp2p/bootstrap";
import { enrTree, wakuDnsDiscovery } from "@waku/dns-discovery";
// Define the list of static peers to bootstrap
const peers = [
"/ip4/0.0.0.0/tcp/60002/p2p/16Uiu2HAkzjwwgEAXfeGNMKFPSpc6vGBRqCdTLG5q3Gmk2v4pQw7H",
"/ip4/0.0.0.0/tcp/60003/p2p/16Uiu2HAmFBA7LGtwY5WVVikdmXVo3cKLqkmvVtuDu63fe8safeQJ",
];
// Define node requirements
const NODE_REQUIREMENTS = {
store: 3,
lightPush: 3,
filter: 3,
};
// Bootstrap node using DNS Discovery
const node = await createLightNode({
libp2p: {
peerDiscovery: [
bootstrap({ list: peers }),
wakuDnsDiscovery(
[enrTree["PROD"]],
NODE_REQUIREMENTS,
),
],
},
});
```
:::info
If you do not set up a bootstrap node or discovery mechanism, your node will not connect to any remote peer.
:::

View File

@ -13,7 +13,7 @@ import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
```
<Tabs>
<Tabs groupId="package-manager">
<TabItem value="npm" label="npm">
```shell
@ -46,7 +46,7 @@ We recommend creating a message structure for your application using [Protocol B
To get started, install the `protobufjs` package using your preferred package manager:
<Tabs>
<Tabs groupId="package-manager">
<TabItem value="npm" label="npm">
```shell
@ -82,8 +82,9 @@ Have a look at the quick start guide and comprehensive tutorials to learn how to
| Guide | Description |
| - | - |
| [Send and Receive Messages Using Light Push and Filter](/guides/js-waku/light-send-receive) | Learn how to send and receive messages on light nodes using the [Light Push](/overview/concepts/protocols#light-push) and [Filter](/overview/concepts/protocols#filter) protocols |
| [Retrieve Messages Using Store](/guides/js-waku/store-retrieve-messages) | Learn how to retrieve and filter historical messages on light nodes using the [Store](/overview/concepts/protocols#store) protocol |
| [Retrieve Messages Using Store Protocol](/guides/js-waku/store-retrieve-messages) | Learn how to retrieve and filter historical messages on light nodes using the [Store protocol](/overview/concepts/protocols#store) |
| [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 |
| [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) |
<!-- | [Build React DApps Using @waku/react](/guides/js-waku/use-waku-react) | Learn how to use the [@waku/react](https://www.npmjs.com/package/@waku/react) package seamlessly integrate `@waku/sdk` into a React application | -->

View File

@ -20,7 +20,7 @@ await node.start();
```
:::info
When the `defaultBootstrap` flag is set to `true`, your node will be bootstrapped using [DNS Discovery](/overview/concepts/dns-discovery). The node does not connect to any remote peer or bootstrap node if omitted.
When the `defaultBootstrap` option is set to `true`, your node will be bootstrapped using the [default bootstrap method](/guides/js-waku/configure-discovery#default-bootstrap-method). Have a look at the [Bootstrap Nodes and Discover Peers](/guides/js-waku/configure-discovery) guide to learn more methods to bootstrap nodes.
:::
## Connect to Remote Peers

View File

@ -1,5 +1,5 @@
---
title: Retrieve Messages Using Store
title: Retrieve Messages Using Store Protocol
---
This guide provides detailed steps to create a Light Node for retrieving and filtering historical messages using the [Store protocol](/overview/concepts/protocols#store).

View File

@ -10,7 +10,7 @@ You can configure a `nwaku` node to use multiple peer discovery mechanisms simul
## Configure Static Peers
You can provide static peers to a `nwaku` node during startup using the `staticnode` configuration option. To connect to multiple peers on startup, repeat the `staticnode` option:
You can provide [static peers](/overview/concepts/static-peers) to a `nwaku` node during startup using the `staticnode` configuration option. To connect to multiple peers on startup, repeat the `staticnode` option:
```bash
./build/wakunode2 \
@ -37,7 +37,7 @@ To enable [DNS Discovery](/overview/concepts/dns-discovery) in a `nwaku` node, u
```bash
./build/wakunode2 \
--dns-discovery=true \
--dns-discovery-url=[DNS NODE LIST] \
--dns-discovery-url=enrtree://[PUBLIC KEY]@[DOMAIN NAME] \
--dns-discovery-name-server=[DNS NAME SERVER IP]
```

View File

@ -17,7 +17,7 @@
},
"dependencies": {
"@acid-info/docusaurus-fathom": "^1.0.0-alpha.61",
"@acid-info/logos-docusaurus-preset": "^1.0.0-alpha.81",
"@acid-info/logos-docusaurus-preset": "^1.0.0-alpha.97",
"@docusaurus/core": "^2.4.1",
"@docusaurus/preset-classic": "^2.4.1",
"@docusaurus/theme-mermaid": "^2.4.1",

View File

@ -74,6 +74,7 @@ const sidebars = {
"guides/js-waku/light-send-receive",
"guides/js-waku/store-retrieve-messages",
"guides/js-waku/use-waku-create-app",
"guides/js-waku/configure-discovery",
{
type: 'html',
value: '<a href="https://examples.waku.org" target="_blank" rel="noopener noreferrer" class="menu__link external-link">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>',

View File

@ -33,14 +33,14 @@
"@easyops-cn/docusaurus-search-local" "^0.33.6"
lodash "^4.17.21"
"@acid-info/logos-docusaurus-preset@^1.0.0-alpha.81":
version "1.0.0-alpha.81"
resolved "https://registry.yarnpkg.com/@acid-info/logos-docusaurus-preset/-/logos-docusaurus-preset-1.0.0-alpha.81.tgz#8a654fd676dd2bfacf42ec39f850bfa4ccbbe507"
integrity sha512-pZNWhiTdaHWyJlncBL37xjaoOMd76FXFcAq0glqPGKqcRLbyq+tBBuSh0JRo86SKNkFW8ZAgGl3XlmSDwCAgyQ==
"@acid-info/logos-docusaurus-preset@^1.0.0-alpha.97":
version "1.0.0-alpha.97"
resolved "https://registry.yarnpkg.com/@acid-info/logos-docusaurus-preset/-/logos-docusaurus-preset-1.0.0-alpha.97.tgz#96d29bd2f75cf427de8e537616c7f8852e52d760"
integrity sha512-Cs0w3pFfrE2jmroaleedGakb8LoEyH8iN5q0Q+WsDLt2qz3xFIXvIW4fiQc5eM37NbHpGgGgvrm7YcB2Fp0ySg==
dependencies:
"@acid-info/docusaurus-og" "^1.0.0-alpha.76"
"@acid-info/logos-docusaurus-search-local" "^1.0.0-alpha.47"
"@acid-info/logos-docusaurus-theme" "^1.0.0-alpha.81"
"@acid-info/logos-docusaurus-theme" "^1.0.0-alpha.97"
"@docusaurus/core" "^2.4.1"
"@docusaurus/module-type-aliases" "^2.4.1"
"@docusaurus/preset-classic" "^2.4.1"
@ -70,13 +70,13 @@
satori "^0.10.1"
sharp "^0.32.1"
"@acid-info/logos-docusaurus-theme@^1.0.0-alpha.81":
version "1.0.0-alpha.81"
resolved "https://registry.yarnpkg.com/@acid-info/logos-docusaurus-theme/-/logos-docusaurus-theme-1.0.0-alpha.81.tgz#34ec1cd51f8ec827ae653d24fb92267069bd6a0d"
integrity sha512-cbCcVShPmEW5k+jyYnVGIttDOtHG9ohH5HKjXMc+kXUl2WJN1hUxt4oTo/TJD16b+Rlbe2RuTT+yorzdKyGHlA==
"@acid-info/logos-docusaurus-theme@^1.0.0-alpha.97":
version "1.0.0-alpha.97"
resolved "https://registry.yarnpkg.com/@acid-info/logos-docusaurus-theme/-/logos-docusaurus-theme-1.0.0-alpha.97.tgz#8b7366238cc0cb177f400af82c0086f88f8f0a45"
integrity sha512-iBbH8enlSIhhGZuWWNxRSV5z8rQrO7uxBUq+xjA4PiCrjpbQb90YSuChuTizRUKkawzpswzkcukIdhzIGfc/Eg==
dependencies:
"@acid-info/docusaurus-og" "^1.0.0-alpha.76"
"@acid-info/lsd-react" "^0.1.0-alpha.15"
"@acid-info/lsd-react" "^0.1.0-alpha.17"
"@docusaurus/core" "^2.4.1"
"@docusaurus/mdx-loader" "^2.4.1"
"@docusaurus/module-type-aliases" "^2.4.1"
@ -117,10 +117,10 @@
three-stdlib "^2.23.4"
utility-types "^3.10.0"
"@acid-info/lsd-react@^0.1.0-alpha.15":
version "0.1.0-alpha.16"
resolved "https://registry.yarnpkg.com/@acid-info/lsd-react/-/lsd-react-0.1.0-alpha.16.tgz#cf635df44bc6ec63990d16fee38908d646a47701"
integrity sha512-U91Hp3Km/tAeExsMhAJvsocg37wImXlNN4Xo4R+lVJD3oTTF0cTLsB+32IbyimqELyXluUv2gwsyo2nHtEcY4Q==
"@acid-info/lsd-react@^0.1.0-alpha.17":
version "0.1.0-alpha.17"
resolved "https://registry.yarnpkg.com/@acid-info/lsd-react/-/lsd-react-0.1.0-alpha.17.tgz#4a0da00ad779717bcd6c5771863ec94937c701a0"
integrity sha512-qDnDr4uK7xXulf3StBLhCdq+0zT+6NT1TstQ+qAw3/kLonE2wiQx+w+aRlyaRobSevhtyC+bfR+QDvfFwkG8Rw==
dependencies:
"@emotion/react" "^11.10.5"
"@emotion/styled" "^11.10.5"