mirror of
https://github.com/logos-messaging/docs.waku.org.git
synced 2026-01-03 21:33:05 +00:00
1 line
12 KiB
JavaScript
1 line
12 KiB
JavaScript
"use strict";(self.webpackChunkwaku_guide=self.webpackChunkwaku_guide||[]).push([[16],{4865:(e,n,s)=>{s.d(n,{A:()=>h});var t=s(96540),r=s(34164),o=s(23104),i=s(47751),a=s(92303);const c={tabList:"tabList__CuJ",tabItem:"tabItem_LNqP"};var d=s(74848);function l({className:e,block:n,selectedValue:s,selectValue:t,tabValues:i}){const a=[],{blockElementScrollPositionUntilNextRender:l}=(0,o.a_)(),u=e=>{const n=e.currentTarget,r=a.indexOf(n),o=i[r].value;o!==s&&(l(n),t(o))},p=e=>{let n=null;switch(e.key){case"Enter":u(e);break;case"ArrowRight":{const s=a.indexOf(e.currentTarget)+1;n=a[s]??a[0];break}case"ArrowLeft":{const s=a.indexOf(e.currentTarget)-1;n=a[s]??a[a.length-1];break}}n?.focus()};return(0,d.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":n},e),children:i.map(({value:e,label:n,attributes:t})=>(0,d.jsx)("li",{role:"tab",tabIndex:s===e?0:-1,"aria-selected":s===e,ref:e=>{a.push(e)},onKeyDown:p,onClick:u,...t,className:(0,r.A)("tabs__item",c.tabItem,t?.className,{"tabs__item--active":s===e}),children:n??e},e))})}function u({lazy:e,children:n,selectedValue:s}){const o=(Array.isArray(n)?n:[n]).filter(Boolean);if(e){const e=o.find(e=>e.props.value===s);return e?(0,t.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,d.jsx)("div",{className:"margin-top--md",children:o.map((e,n)=>(0,t.cloneElement)(e,{key:n,hidden:e.props.value!==s}))})}function p(e){const n=(0,i.u)(e);return(0,d.jsxs)("div",{className:(0,r.A)("tabs-container",c.tabList),children:[(0,d.jsx)(l,{...n,...e}),(0,d.jsx)(u,{...n,...e})]})}function h(e){const n=(0,a.default)();return(0,d.jsx)(p,{...e,children:(0,i.v)(e.children)},String(n))}},4933:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>l,contentTitle:()=>d,default:()=>h,frontMatter:()=>c,metadata:()=>t,toc:()=>u});const t=JSON.parse('{"id":"guides/js-waku/configure-discovery","title":"Bootstrap Nodes and Discover Peers","description":"This guide provides detailed steps to bootstrap your your node using Static Peers and discover peers in the Waku Network using DNS Discovery.","source":"@site/docs/guides/js-waku/configure-discovery.mdx","sourceDirName":"guides/js-waku","slug":"/guides/js-waku/configure-discovery","permalink":"/guides/js-waku/configure-discovery","draft":false,"unlisted":false,"editUrl":"https://github.com/waku-org/docs.waku.org/tree/develop/docs/guides/js-waku/configure-discovery.mdx","tags":[],"version":"current","lastUpdatedAt":null,"frontMatter":{"title":"Bootstrap Nodes and Discover Peers","hide_table_of_contents":true},"sidebar":"guides","previous":{"title":"Scaffold DApps Using @waku/create-app","permalink":"/guides/js-waku/use-waku-create-app"},"next":{"title":"Run @waku/sdk in a NodeJS Application","permalink":"/guides/js-waku/run-waku-nodejs"}}');var r=s(74848),o=s(28453),i=s(4865),a=s(19365);const c={title:"Bootstrap Nodes and Discover Peers",hide_table_of_contents:!0},d=void 0,l={},u=[{value:"Default bootstrap method",id:"default-bootstrap-method",level:2},{value:"Configure static peers",id:"configure-static-peers",level:2},{value:"Configure DNS discovery",id:"configure-dns-discovery",level:2},{value:"Configure DNS discovery and static peers",id:"configure-dns-discovery-and-static-peers",level:2},{value:"Retrieving connected peers",id:"retrieving-connected-peers",level:2}];function p(e){const n={a:"a",admonition:"admonition",code:"code",h2:"h2",p:"p",pre:"pre",...(0,o.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(n.p,{children:["This guide provides detailed steps to bootstrap your your node using ",(0,r.jsx)(n.a,{href:"/learn/concepts/static-peers",children:"Static Peers"})," and discover peers in the Waku Network using ",(0,r.jsx)(n.a,{href:"/learn/concepts/dns-discovery",children:"DNS Discovery"}),"."]}),"\n",(0,r.jsx)(n.admonition,{type:"info",children:(0,r.jsx)(n.p,{children:"If you do not set up a bootstrap node or discovery mechanism, your node will not connect to any remote peer."})}),"\n",(0,r.jsx)(n.admonition,{type:"tip",children:(0,r.jsxs)(n.p,{children:["Until ",(0,r.jsx)(n.a,{href:"/learn/research#prevention-of-denial-of-service-dos-and-node-incentivisation",children:"node incentivisation"})," is in place, you should ",(0,r.jsx)(n.a,{href:"/#run-a-waku-node",children:"operate extra nodes"})," alongside the ones provided by the Waku Network. When running a node, we recommend using the ",(0,r.jsx)(n.a,{href:"#configure-dns-discovery-and-static-peers",children:"DNS Discovery and Static Peers"})," configuration to connect to both the Waku Network and your node."]})}),"\n",(0,r.jsx)(n.h2,{id:"default-bootstrap-method",children:"Default bootstrap method"}),"\n",(0,r.jsxs)(n.p,{children:["The ",(0,r.jsx)(n.code,{children:"@waku/sdk"})," package provides a built-in bootstrapping method that uses ",(0,r.jsx)(n.a,{href:"/learn/concepts/dns-discovery",children:"DNS Discovery"})," to locate peers from the ",(0,r.jsx)(n.code,{children:"waku v2.prod"})," ",(0,r.jsx)(n.code,{children:"ENR"})," tree."]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:'import { createLightNode } from "@waku/sdk";\n\n// Bootstrap node using the default bootstrap method\nconst node = await createLightNode({ defaultBootstrap: true });\n'})}),"\n",(0,r.jsx)(n.h2,{id:"configure-static-peers",children:"Configure static peers"}),"\n",(0,r.jsxs)(n.p,{children:["To set ",(0,r.jsx)(n.a,{href:"/learn/concepts/static-peers",children:"static peers"}),", a list of ",(0,r.jsx)(n.code,{children:"multiaddr"})," to bootstrap the node should be passed to the ",(0,r.jsx)(n.code,{children:"bootstrapPeers"})," parameter of the ",(0,r.jsx)(n.code,{children:"createLightNode()"})," function:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:'import { createLightNode } from "@waku/sdk";\n\n// Bootstrap node using static peers\nconst node = await createLightNode({\n bootstrapPeers: ["[PEER MULTIADDR]"],\n});\n'})}),"\n",(0,r.jsxs)(n.p,{children:["For example, consider a node that connects to two static peers on the same local host (IP: ",(0,r.jsx)(n.code,{children:"0.0.0.0"}),") using TCP ports ",(0,r.jsx)(n.code,{children:"60002"})," and ",(0,r.jsx)(n.code,{children:"60003"})," with WebSocket enabled:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:'// Define the list of static peers to bootstrap\nconst peers = [\n "/ip4/0.0.0.0/tcp/60002/ws/p2p/16Uiu2HAkzjwwgEAXfeGNMKFPSpc6vGBRqCdTLG5q3Gmk2v4pQw7H",\n "/ip4/0.0.0.0/tcp/60003/ws/p2p/16Uiu2HAmFBA7LGtwY5WVVikdmXVo3cKLqkmvVtuDu63fe8safeQJ",\n];\n\n// Bootstrap node using the static peers\nconst node = await createLightNode({\n bootstrapPeers: peers,\n});\n'})}),"\n",(0,r.jsx)(n.p,{children:"Alternatively, you can dial a particular node like this:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:'// Define the list of static peers to bootstrap\nconst peers = [\n "/ip4/0.0.0.0/tcp/60002/ws/p2p/16Uiu2HAkzjwwgEAXfeGNMKFPSpc6vGBRqCdTLG5q3Gmk2v4pQw7H",\n "/ip4/0.0.0.0/tcp/60003/ws/p2p/16Uiu2HAmFBA7LGtwY5WVVikdmXVo3cKLqkmvVtuDu63fe8safeQJ",\n];\n\nconst node = await createLightNode();\n\n// In case nodes are using IP address and / or `ws` protocol - additional configuration is needed:\n/*\nconst node = await createLightNode({\n\tlibp2p: {\n\t\tfilterMultiaddrs: false,\n\t},\n});\n*/\n\nconst promises = peers.map((multiaddr) => node.dial(multiaddr));\n\nawait Promise.all(promises);\n'})}),"\n",(0,r.jsx)(n.admonition,{type:"tip",children:(0,r.jsxs)(n.p,{children:["For local development using a ",(0,r.jsx)(n.code,{children:"nwaku"})," node, use a ",(0,r.jsx)(n.code,{children:"ws"})," address instead of ",(0,r.jsx)(n.code,{children:"wss"}),". Remember that this setup is functional only when your web server is running locally. You can check how to get multi address of your locally run node in ",(0,r.jsx)(n.a,{href:"/guides/nwaku/find-node-address",children:"Find node address"}),"."]})}),"\n",(0,r.jsx)(n.h2,{id:"configure-dns-discovery",children:"Configure DNS discovery"}),"\n",(0,r.jsxs)(n.p,{children:["To bootstrap a node using ",(0,r.jsx)(n.a,{href:"/learn/concepts/dns-discovery",children:"DNS Discovery"}),", first install the ",(0,r.jsx)(n.code,{children:"@waku/dns-discovery"})," package:"]}),"\n",(0,r.jsxs)(i.A,{groupId:"package-manager",children:[(0,r.jsx)(a.A,{value:"npm",label:"NPM",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-shell",children:"npm install @waku/dns-discovery\n"})})}),(0,r.jsx)(a.A,{value:"yarn",label:"Yarn",children:(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-shell",children:"yarn add @waku/dns-discovery\n"})})})]}),"\n",(0,r.jsxs)(n.p,{children:["Then, use the ",(0,r.jsx)(n.code,{children:"wakuDnsDiscovery()"})," function to provide a list of URLs for DNS node list in the format ",(0,r.jsx)(n.code,{children:"enrtree://<key>@<fqdn>"}),":"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:'import { createLightNode } from "@waku/sdk";\nimport { wakuDnsDiscovery } from "@waku/dns-discovery";\n\n// Define DNS node list\nconst enrTree = "enrtree://[PUBLIC KEY]@[DOMAIN NAME]";\n\n// Define node requirements\nconst NODE_REQUIREMENTS = {\n store: 3,\n lightPush: 3,\n filter: 3,\n};\n\n// Bootstrap node using DNS Discovery\nconst node = await createLightNode({\n libp2p: {\n peerDiscovery: [wakuDnsDiscovery([enrTree], NODE_REQUIREMENTS)],\n },\n});\n'})}),"\n",(0,r.jsxs)(n.p,{children:["For example, consider a node that uses the ",(0,r.jsx)(n.code,{children:"waku v2.prod"})," and ",(0,r.jsx)(n.code,{children:"waku v2.test"})," ",(0,r.jsx)(n.code,{children:"ENR"})," trees for ",(0,r.jsx)(n.code,{children:"DNS Discovery"}),":"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:'import { enrTree } from "@waku/dns-discovery";\n\n// Bootstrap node using DNS Discovery\nconst node = await createLightNode({\n libp2p: {\n peerDiscovery: [\n wakuDnsDiscovery([enrTree["PROD"], enrTree["TEST"]], NODE_REQUIREMENTS),\n ],\n },\n});\n'})}),"\n",(0,r.jsx)(n.h2,{id:"configure-dns-discovery-and-static-peers",children:"Configure DNS discovery and static peers"}),"\n",(0,r.jsxs)(n.p,{children:["You can also bootstrap your node using ",(0,r.jsx)(n.a,{href:"/learn/concepts/dns-discovery",children:"DNS Discovery"})," and ",(0,r.jsx)(n.a,{href:"/learn/concepts/static-peers",children:"Static Peers"})," simultaneously:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:'import { createLightNode } from "@waku/sdk";\nimport { bootstrap } from "@libp2p/bootstrap";\nimport { enrTree, wakuDnsDiscovery } from "@waku/dns-discovery";\n\n// Define the list of static peers to bootstrap\nconst peers = [\n "/ip4/0.0.0.0/tcp/60002/ws/p2p/16Uiu2HAkzjwwgEAXfeGNMKFPSpc6vGBRqCdTLG5q3Gmk2v4pQw7H",\n "/ip4/0.0.0.0/tcp/60003/ws/p2p/16Uiu2HAmFBA7LGtwY5WVVikdmXVo3cKLqkmvVtuDu63fe8safeQJ",\n];\n\n// Define node requirements\nconst NODE_REQUIREMENTS = {\n store: 3,\n lightPush: 3,\n filter: 3,\n};\n\n// Bootstrap node using DNS Discovery and static peers\nconst node = await createLightNode({\n libp2p: {\n bootstrapPeers: peers,\n peerDiscovery: [wakuDnsDiscovery([enrTree["PROD"]], NODE_REQUIREMENTS)],\n },\n});\n'})}),"\n",(0,r.jsx)(n.h2,{id:"retrieving-connected-peers",children:"Retrieving connected peers"}),"\n",(0,r.jsxs)(n.p,{children:["You can retrieve the array of peers connected to a node using the ",(0,r.jsx)(n.code,{children:"libp2p.getPeers()"})," function within the ",(0,r.jsx)(n.code,{children:"@waku/sdk"})," package:"]}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-js",children:'import { createLightNode } from "@waku/sdk";\n\nconst node = await createLightNode({ defaultBootstrap: true });\nawait node.waitForPeers();\n\n// Retrieve array of peers connected to the node\nconsole.log(node.libp2p.getPeers());\n'})})]})}function h(e={}){const{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},19365:(e,n,s)=>{s.d(n,{A:()=>i});s(96540);var t=s(34164);const r={tabItem:"tabItem_Ymn6"};var o=s(74848);function i({children:e,hidden:n,className:s}){return(0,o.jsx)("div",{role:"tabpanel",className:(0,t.A)(r.tabItem,s),hidden:n,children:e})}},28453:(e,n,s)=>{s.d(n,{R:()=>i,x:()=>a});var t=s(96540);const r={},o=t.createContext(r);function i(e){const n=t.useContext(o);return t.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function a(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),t.createElement(o.Provider,{value:n},e.children)}}}]); |