From 69aee6c1cc2a89c71b1c66ff2256fed1458f743c Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Mon, 1 Aug 2022 15:43:43 +1000 Subject: [PATCH 01/11] refactor: move `createWaku` to own module --- src/index.ts | 3 +- src/lib/create_waku.ts | 80 ++++++++++++++++++++++ src/lib/enr/enr.node.spec.ts | 3 +- src/lib/wait_for_remote_peer.node.spec.ts | 3 +- src/lib/waku.node.spec.ts | 3 +- src/lib/waku.spec.ts | 3 +- src/lib/waku.ts | 77 ++------------------- src/lib/waku_filter/index.node.spec.ts | 3 +- src/lib/waku_light_push/index.node.spec.ts | 3 +- src/lib/waku_message/index.node.spec.ts | 3 +- src/lib/waku_relay/index.node.spec.ts | 3 +- src/lib/waku_relay/index.ts | 19 ++++- src/lib/waku_store/index.node.spec.ts | 3 +- 13 files changed, 123 insertions(+), 83 deletions(-) create mode 100644 src/lib/create_waku.ts diff --git a/src/index.ts b/src/index.ts index 58d36d02a7..acbc51b3b1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,7 +18,7 @@ export { waitForRemotePeer } from "./lib/wait_for_remote_peer"; export * as proto_message from "./proto/message"; export * as waku from "./lib/waku"; -export { createWaku, Waku, Protocols } from "./lib/waku"; +export { Waku, Protocols } from "./lib/waku"; export * as waku_message from "./lib/waku_message"; export { WakuMessage } from "./lib/waku_message"; @@ -38,3 +38,4 @@ export { WakuRelay } from "./lib/waku_relay"; export * as waku_store from "./lib/waku_store"; export { PageDirection, WakuStore, StoreCodecs } from "./lib/waku_store"; +export { createWaku } from "./lib/create_waku"; diff --git a/src/lib/create_waku.ts b/src/lib/create_waku.ts new file mode 100644 index 0000000000..36bf6132c5 --- /dev/null +++ b/src/lib/create_waku.ts @@ -0,0 +1,80 @@ +import { Noise } from "@chainsafe/libp2p-noise"; +import { Mplex } from "@libp2p/mplex"; +import { WebSockets } from "@libp2p/websockets"; +import { all as filterAll } from "@libp2p/websockets/dist/src/filters"; +import { createLibp2p, Libp2pOptions } from "libp2p"; + +import { Bootstrap, BootstrapOptions } from "./discovery"; +import { Waku, WakuOptions } from "./waku"; +import { WakuFilter } from "./waku_filter"; +import { WakuLightPush } from "./waku_light_push"; +import { WakuRelay } from "./waku_relay"; +import { WakuStore } from "./waku_store"; + +export interface CreateOptions { + /** + * The PubSub Topic to use. Defaults to {@link DefaultPubSubTopic}. + * + * One and only one pubsub topic is used by Waku. This is used by: + * - WakuRelay to receive, route and send messages, + * - WakuLightPush to send messages, + * - WakuStore to retrieve messages. + * + * The usage of the default pubsub topic is recommended. + * See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/) for details. + * + * @default {@link DefaultPubSubTopic} + */ + pubSubTopic?: string; + /** + * You can pass options to the `Libp2p` instance used by {@link Waku} using the {@link CreateOptions.libp2p} property. + * This property is the same type than the one passed to [`Libp2p.create`](https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#create) + * apart that we made the `modules` property optional and partial, + * allowing its omission and letting Waku set good defaults. + * Notes that some values are overridden by {@link Waku} to ensure it implements the Waku protocol. + */ + libp2p?: Partial; + /** + * Byte array used as key for the noise protocol used for connection encryption + * by [`Libp2p.create`](https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#create) + * This is only used for test purposes to not run out of entropy during CI runs. + */ + staticNoiseKey?: Uint8Array; + /** + * Use libp2p-bootstrap to discover and connect to new nodes. + * + * See [[BootstrapOptions]] for available parameters. + * + * Note: It overrides any other peerDiscovery modules that may have been set via + * {@link CreateOptions.libp2p}. + */ + bootstrap?: BootstrapOptions; +} + +export async function createWaku( + options?: CreateOptions & WakuOptions +): Promise { + const peerDiscovery = []; + if (options?.bootstrap) { + peerDiscovery.push(new Bootstrap(options?.bootstrap)); + } + + const libp2pOpts = Object.assign( + { + transports: [new WebSockets({ filter: filterAll })], + streamMuxers: [new Mplex()], + pubsub: new WakuRelay(options), + connectionEncryption: [new Noise()], + peerDiscovery: peerDiscovery, + }, + options?.libp2p ?? {} + ); + + const libp2p = await createLibp2p(libp2pOpts); + + const wakuStore = new WakuStore(libp2p, options); + const wakuLightPush = new WakuLightPush(libp2p, options); + const wakuFilter = new WakuFilter(libp2p, options); + + return new Waku(options ?? {}, libp2p, wakuStore, wakuLightPush, wakuFilter); +} diff --git a/src/lib/enr/enr.node.spec.ts b/src/lib/enr/enr.node.spec.ts index 81c45c1c24..3c6415249e 100644 --- a/src/lib/enr/enr.node.spec.ts +++ b/src/lib/enr/enr.node.spec.ts @@ -1,8 +1,9 @@ import { expect } from "chai"; import { makeLogFileName, NOISE_KEY_1, Nwaku } from "../../test_utils"; +import { createWaku } from "../create_waku"; import { waitForRemotePeer } from "../wait_for_remote_peer"; -import { createWaku, Protocols, Waku } from "../waku"; +import { Protocols, Waku } from "../waku"; import { ENR } from "./enr"; diff --git a/src/lib/wait_for_remote_peer.node.spec.ts b/src/lib/wait_for_remote_peer.node.spec.ts index 92c1ea489a..859ea36244 100644 --- a/src/lib/wait_for_remote_peer.node.spec.ts +++ b/src/lib/wait_for_remote_peer.node.spec.ts @@ -3,8 +3,9 @@ import { expect } from "chai"; import { makeLogFileName, NOISE_KEY_1, Nwaku } from "../test_utils"; import { delay } from "../test_utils/delay"; +import { createWaku } from "./create_waku"; import { waitForRemotePeer } from "./wait_for_remote_peer"; -import { createWaku, Protocols, Waku } from "./waku"; +import { Protocols, Waku } from "./waku"; describe("Wait for remote peer", function () { let waku: Waku; diff --git a/src/lib/waku.node.spec.ts b/src/lib/waku.node.spec.ts index b27c5c8f37..9dc57ff3f0 100644 --- a/src/lib/waku.node.spec.ts +++ b/src/lib/waku.node.spec.ts @@ -8,9 +8,10 @@ import { Nwaku, } from "../test_utils/"; +import { createWaku } from "./create_waku"; import { generateSymmetricKey } from "./crypto"; import { waitForRemotePeer } from "./wait_for_remote_peer"; -import { createWaku, Protocols, Waku } from "./waku"; +import { Protocols, Waku } from "./waku"; import { WakuMessage } from "./waku_message"; const TestContentTopic = "/test/1/waku/utf8"; diff --git a/src/lib/waku.spec.ts b/src/lib/waku.spec.ts index 21d181a4ee..ff188b4671 100644 --- a/src/lib/waku.spec.ts +++ b/src/lib/waku.spec.ts @@ -1,7 +1,8 @@ import type { PeerId } from "@libp2p/interface-peer-id"; import { expect } from "chai"; -import { createWaku, Waku } from "./waku"; +import { createWaku } from "./create_waku"; +import { Waku } from "./waku"; describe("Waku Dial", function () { describe("Bootstrap [live data]", function () { diff --git a/src/lib/waku.ts b/src/lib/waku.ts index a23cc6dddb..da40250eb6 100644 --- a/src/lib/waku.ts +++ b/src/lib/waku.ts @@ -1,15 +1,11 @@ -import { Noise } from "@chainsafe/libp2p-noise"; import type { Stream } from "@libp2p/interface-connection"; import type { PeerId } from "@libp2p/interface-peer-id"; -import { Mplex } from "@libp2p/mplex"; import { peerIdFromString } from "@libp2p/peer-id"; -import { WebSockets } from "@libp2p/websockets"; -import { all as filterAll } from "@libp2p/websockets/filters"; -import { Multiaddr, multiaddr } from "@multiformats/multiaddr"; +import type { Multiaddr } from "@multiformats/multiaddr"; +import { multiaddr } from "@multiformats/multiaddr"; import debug from "debug"; -import { createLibp2p, Libp2p, Libp2pOptions } from "libp2p"; +import type { Libp2p } from "libp2p"; -import { Bootstrap, BootstrapOptions } from "./discovery"; import { FilterCodec, WakuFilter } from "./waku_filter"; import { LightPushCodec, WakuLightPush } from "./waku_light_push"; import { DecryptionMethod, WakuMessage } from "./waku_message"; @@ -29,21 +25,7 @@ export enum Protocols { Filter = "filter", } -export interface CreateOptions { - /** - * The PubSub Topic to use. Defaults to {@link DefaultPubSubTopic}. - * - * One and only one pubsub topic is used by Waku. This is used by: - * - WakuRelay to receive, route and send messages, - * - WakuLightPush to send messages, - * - WakuStore to retrieve messages. - * - * The usage of the default pubsub topic is recommended. - * See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/) for details. - * - * @default {@link DefaultPubSubTopic} - */ - pubSubTopic?: string; +export interface WakuOptions { /** * Set keep alive frequency in seconds: Waku will send a `/ipfs/ping/1.0.0` * request to each peer after the set number of seconds. Set to 0 to disable. @@ -58,58 +40,9 @@ export interface CreateOptions { * @default {@link DefaultRelayKeepAliveValueSecs} */ relayKeepAlive?: number; - /** - * You can pass options to the `Libp2p` instance used by {@link Waku} using the {@link CreateOptions.libp2p} property. - * This property is the same type than the one passed to [`Libp2p.create`](https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#create) - * apart that we made the `modules` property optional and partial, - * allowing its omission and letting Waku set good defaults. - * Notes that some values are overridden by {@link Waku} to ensure it implements the Waku protocol. - */ - libp2p?: Partial; - /** - * Byte array used as key for the noise protocol used for connection encryption - * by [`Libp2p.create`](https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#create) - * This is only used for test purposes to not run out of entropy during CI runs. - */ - staticNoiseKey?: Uint8Array; - /** - * Use libp2p-bootstrap to discover and connect to new nodes. - * - * See [[BootstrapOptions]] for available parameters. - * - * Note: It overrides any other peerDiscovery modules that may have been set via - * {@link CreateOptions.libp2p}. - */ - bootstrap?: BootstrapOptions; decryptionKeys?: Array; } -export async function createWaku(options?: CreateOptions): Promise { - const peerDiscovery = []; - if (options?.bootstrap) { - peerDiscovery.push(new Bootstrap(options?.bootstrap)); - } - - const libp2pOpts = Object.assign( - { - transports: [new WebSockets({ filter: filterAll })], - streamMuxers: [new Mplex()], - pubsub: new WakuRelay(options), - connectionEncryption: [new Noise()], - peerDiscovery: peerDiscovery, - }, - options?.libp2p ?? {} - ); - - const libp2p = await createLibp2p(libp2pOpts); - - const wakuStore = new WakuStore(libp2p, options); - const wakuLightPush = new WakuLightPush(libp2p, options); - const wakuFilter = new WakuFilter(libp2p, options); - - return new Waku(options ?? {}, libp2p, wakuStore, wakuLightPush, wakuFilter); -} - export class Waku { public libp2p: Libp2p; public relay: WakuRelay; @@ -125,7 +58,7 @@ export class Waku { }; constructor( - options: CreateOptions, + options: WakuOptions, libp2p: Libp2p, store: WakuStore, lightPush: WakuLightPush, diff --git a/src/lib/waku_filter/index.node.spec.ts b/src/lib/waku_filter/index.node.spec.ts index 05054e31f3..75a766253c 100644 --- a/src/lib/waku_filter/index.node.spec.ts +++ b/src/lib/waku_filter/index.node.spec.ts @@ -3,8 +3,9 @@ import debug from "debug"; import { makeLogFileName, NOISE_KEY_1, Nwaku } from "../../test_utils"; import { delay } from "../../test_utils/delay"; +import { createWaku } from "../create_waku"; import { waitForRemotePeer } from "../wait_for_remote_peer"; -import { createWaku, Protocols, Waku } from "../waku"; +import { Protocols, Waku } from "../waku"; import { WakuMessage } from "../waku_message"; const log = debug("waku:test"); diff --git a/src/lib/waku_light_push/index.node.spec.ts b/src/lib/waku_light_push/index.node.spec.ts index 1ea42c49a5..486fe3b830 100644 --- a/src/lib/waku_light_push/index.node.spec.ts +++ b/src/lib/waku_light_push/index.node.spec.ts @@ -3,8 +3,9 @@ import debug from "debug"; import { makeLogFileName, NOISE_KEY_1, Nwaku } from "../../test_utils"; import { delay } from "../../test_utils/delay"; +import { createWaku } from "../create_waku"; import { waitForRemotePeer } from "../wait_for_remote_peer"; -import { createWaku, Protocols, Waku } from "../waku"; +import { Protocols, Waku } from "../waku"; import { WakuMessage } from "../waku_message"; const dbg = debug("waku:test:lightpush"); diff --git a/src/lib/waku_message/index.node.spec.ts b/src/lib/waku_message/index.node.spec.ts index e26843b505..1bd88686d0 100644 --- a/src/lib/waku_message/index.node.spec.ts +++ b/src/lib/waku_message/index.node.spec.ts @@ -8,6 +8,7 @@ import { WakuRelayMessage, } from "../../test_utils"; import { delay } from "../../test_utils/delay"; +import { createWaku } from "../create_waku"; import { generatePrivateKey, generateSymmetricKey, @@ -15,7 +16,7 @@ import { } from "../crypto"; import { bytesToHex, bytesToUtf8, hexToBytes, utf8ToBytes } from "../utils"; import { waitForRemotePeer } from "../wait_for_remote_peer"; -import { createWaku, Protocols, Waku } from "../waku"; +import { Protocols, Waku } from "../waku"; import { DecryptionMethod, WakuMessage } from "./index"; diff --git a/src/lib/waku_relay/index.node.spec.ts b/src/lib/waku_relay/index.node.spec.ts index 1670c1f9cb..472c3d363b 100644 --- a/src/lib/waku_relay/index.node.spec.ts +++ b/src/lib/waku_relay/index.node.spec.ts @@ -11,13 +11,14 @@ import { } from "../../test_utils"; import { delay } from "../../test_utils/delay"; import { DefaultPubSubTopic } from "../constants"; +import { createWaku } from "../create_waku"; import { generatePrivateKey, generateSymmetricKey, getPublicKey, } from "../crypto"; import { waitForRemotePeer } from "../wait_for_remote_peer"; -import { createWaku, Protocols, Waku } from "../waku"; +import { Protocols, Waku } from "../waku"; import { DecryptionMethod, WakuMessage } from "../waku_message"; const log = debug("waku:test"); diff --git a/src/lib/waku_relay/index.ts b/src/lib/waku_relay/index.ts index 5d2bd454d3..aa84464226 100644 --- a/src/lib/waku_relay/index.ts +++ b/src/lib/waku_relay/index.ts @@ -12,13 +12,30 @@ import debug from "debug"; import { DefaultPubSubTopic } from "../constants"; import { hexToBytes } from "../utils"; -import { CreateOptions } from "../waku"; import { DecryptionMethod, WakuMessage } from "../waku_message"; import * as constants from "./constants"; const dbg = debug("waku:relay"); +export interface CreateOptions { + /** + * The PubSub Topic to use. Defaults to {@link DefaultPubSubTopic}. + * + * One and only one pubsub topic is used by Waku. This is used by: + * - WakuRelay to receive, route and send messages, + * - WakuLightPush to send messages, + * - WakuStore to retrieve messages. + * + * The usage of the default pubsub topic is recommended. + * See [Waku v2 Topic Usage Recommendations](https://rfc.vac.dev/spec/23/) for details. + * + * @default {@link DefaultPubSubTopic} + */ + pubSubTopic?: string; + decryptionKeys?: Array; +} + /** * Implements the [Waku v2 Relay protocol]{@link https://rfc.vac.dev/spec/11/}. * Must be passed as a `pubsub` module to a {Libp2p} instance. diff --git a/src/lib/waku_store/index.node.spec.ts b/src/lib/waku_store/index.node.spec.ts index e814819865..00b3e6925a 100644 --- a/src/lib/waku_store/index.node.spec.ts +++ b/src/lib/waku_store/index.node.spec.ts @@ -7,13 +7,14 @@ import { NOISE_KEY_2, Nwaku, } from "../../test_utils"; +import { createWaku } from "../create_waku"; import { generatePrivateKey, generateSymmetricKey, getPublicKey, } from "../crypto"; import { waitForRemotePeer } from "../wait_for_remote_peer"; -import { createWaku, Protocols, Waku } from "../waku"; +import { Protocols, Waku } from "../waku"; import { DecryptionMethod, WakuMessage } from "../waku_message"; import { PageDirection } from "./history_rpc"; From 731318fa66063736a2523dd25e6864a4b6538fa0 Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Mon, 1 Aug 2022 22:07:00 +1000 Subject: [PATCH 02/11] feat: export create_waku --- package.json | 4 ++++ typedoc.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 10ee58f7fc..6bd9c41083 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,10 @@ ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" + }, + "./lib/create_waku": { + "types": "./dist/lib/create_waku.d.ts", + "import": "./dist/lib/create_waku.js" } }, "type": "module", diff --git a/typedoc.json b/typedoc.json index 2c65e565a0..eba01ebeba 100644 --- a/typedoc.json +++ b/typedoc.json @@ -1,5 +1,5 @@ { - "entryPoints": ["./src/index.ts"], + "entryPoints": ["./src/index.ts", "./src/lib/create_waku.ts"], "out": "build/docs", "exclude": "**/*.spec.ts", "excludeInternal": true, From 080357355bd4e6a9ad94b8252d704d176f0006bc Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Mon, 1 Aug 2022 22:50:02 +1000 Subject: [PATCH 03/11] refactor: extract peer discovery static list --- src/lib/multiaddr_to_peer_info.ts | 17 ++++ src/lib/peer_discovery_static_list.ts | 119 +++++++++++++++++++++++ src/lib/{discovery => }/random_subset.ts | 0 3 files changed, 136 insertions(+) create mode 100644 src/lib/multiaddr_to_peer_info.ts create mode 100644 src/lib/peer_discovery_static_list.ts rename src/lib/{discovery => }/random_subset.ts (100%) diff --git a/src/lib/multiaddr_to_peer_info.ts b/src/lib/multiaddr_to_peer_info.ts new file mode 100644 index 0000000000..65524c4439 --- /dev/null +++ b/src/lib/multiaddr_to_peer_info.ts @@ -0,0 +1,17 @@ +import { PeerInfo } from "@libp2p/interface-peer-info"; +import { peerIdFromString } from "@libp2p/peer-id"; +import { Multiaddr } from "@multiformats/multiaddr"; + +export function multiaddrsToPeerInfo(mas: Multiaddr[]): PeerInfo[] { + return mas + .map((ma) => { + const peerIdStr = ma.getPeerId(); + const protocols: string[] = []; + return { + id: peerIdStr ? peerIdFromString(peerIdStr) : null, + multiaddrs: [ma.decapsulateCode(421)], + protocols, + }; + }) + .filter((peerInfo): peerInfo is PeerInfo => peerInfo.id !== null); +} diff --git a/src/lib/peer_discovery_static_list.ts b/src/lib/peer_discovery_static_list.ts new file mode 100644 index 0000000000..55a020a862 --- /dev/null +++ b/src/lib/peer_discovery_static_list.ts @@ -0,0 +1,119 @@ +import type { + PeerDiscovery, + PeerDiscoveryEvents, +} from "@libp2p/interface-peer-discovery"; +import { symbol } from "@libp2p/interface-peer-discovery"; +import type { PeerInfo } from "@libp2p/interface-peer-info"; +import { CustomEvent, EventEmitter } from "@libp2p/interfaces/events"; +import { Multiaddr } from "@multiformats/multiaddr"; +import debug from "debug"; + +import { multiaddrsToPeerInfo } from "./multiaddr_to_peer_info"; +import { getPseudoRandomSubset } from "./random_subset"; + +const log = debug("waku:discovery:static-list"); + +export interface Options { + /** + * The maximum of peers to connect to as part of the bootstrap process. + * + * @default The length of the passed `peers` array. + */ + maxPeers?: number; + /** + * The interval between emitting addresses in milliseconds. + * + * @default {@link PeerDiscoveryEvents.DefaultInterval} + */ + interval?: number; +} + +/** + * Parse options and expose function to return bootstrap peer addresses. + * + * @throws if an invalid combination of options is passed, see [[BootstrapOptions]] for details. + */ +export class PeerDiscoveryStaticPeers + extends EventEmitter + implements PeerDiscovery +{ + static DefaultInterval = 200; + private readonly peers: PeerInfo[]; + private timer?: ReturnType; + private readonly interval: number; + + /** + * @param peers Multiaddrs of peers to connect to. + * @param opts + */ + constructor(peers: string[] | Multiaddr[], opts?: Options) { + super(); + + this.interval = opts?.interval ?? PeerDiscoveryStaticPeers.DefaultInterval; + const maxPeers = opts?.maxPeers ?? peers?.length; + + const peerMas = peers.map((peer: string | Multiaddr) => { + if (typeof peer === "string") { + return new Multiaddr(peer); + } else { + return peer; + } + }); + this.peers = multiaddrsToPeerInfo(getPseudoRandomSubset(peerMas, maxPeers)); + log( + "Use provided list of peers (reduced to maxPeers)", + this.peers.map((ma) => ma.toString()) + ); + } + + /** + * Start emitting static peers. + */ + start(): void { + this._startTimer(); + } + + private _startTimer(): void { + if (this.peers) { + log("Starting emitting static peers for boostrap."); + if (this.timer != null) { + return; + } + + this.timer = setInterval(() => this._returnPeers(), this.interval); + + this._returnPeers(); + } + } + + _returnPeers(): void { + if (this.timer == null) { + return; + } + + this.peers.forEach((peerData) => { + this.dispatchEvent( + new CustomEvent("peer", { detail: peerData }) + ); + }); + } + + /** + * Stop emitting peers. + */ + stop(): void { + if (this.timer != null) { + clearInterval(this.timer); + } + + this.timer = undefined; + } + + get [symbol](): true { + return true; + } + + get [Symbol.toStringTag](): string { + return "@waku/peer-discovery-static-list"; + } +} diff --git a/src/lib/discovery/random_subset.ts b/src/lib/random_subset.ts similarity index 100% rename from src/lib/discovery/random_subset.ts rename to src/lib/random_subset.ts From f929be064bc10bd36312aec892f06ca83816a1b1 Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Wed, 3 Aug 2022 15:00:09 +1000 Subject: [PATCH 04/11] fix: filter import --- src/lib/create_waku.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/create_waku.ts b/src/lib/create_waku.ts index 36bf6132c5..e94d9abf11 100644 --- a/src/lib/create_waku.ts +++ b/src/lib/create_waku.ts @@ -1,7 +1,7 @@ import { Noise } from "@chainsafe/libp2p-noise"; import { Mplex } from "@libp2p/mplex"; import { WebSockets } from "@libp2p/websockets"; -import { all as filterAll } from "@libp2p/websockets/dist/src/filters"; +import { all as filterAll } from "@libp2p/websockets/filters"; import { createLibp2p, Libp2pOptions } from "libp2p"; import { Bootstrap, BootstrapOptions } from "./discovery"; From c1b158cbf0ecd6841c4ac38c9de6f0a325cfcedc Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Wed, 3 Aug 2022 15:01:35 +1000 Subject: [PATCH 05/11] feat: set tsbuildinfo file in dist directory So that when deleting the `dist` directory, the file gets deleted too. --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index b958d4581f..7b01b30897 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,7 @@ "sourceMap": true, "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, "resolveJsonModule": true /* Include modules imported with .json extension. */, - + "tsBuildInfoFile": "dist/.tsbuildinfo", "strict": true /* Enable all strict type-checking options. */, /* Strict Type-Checking Options */ From 889ec4d45c81d348ff1dcce15853bb82b13319ac Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Wed, 3 Aug 2022 15:08:12 +1000 Subject: [PATCH 06/11] feat: split bootstrap logic Split the bootstrap logic in 2 different classes that implement the libp2p peer discovery class. This enables better tree shaking when not using the heaviest version (DNS Discovery). It also means using libp2p interface directly when customizing the peer discovery logic. Finally, the `default` method is still available via the `defaultBootstrap` option. --- src/index.ts | 3 - src/lib/create_waku.ts | 49 ++-- src/lib/discovery/bootstrap.ts | 244 ------------------ src/lib/discovery/index.ts | 6 - .../dns.spec.ts | 0 .../{discovery => peer_discovery_dns}/dns.ts | 29 ++- .../dns_over_https.ts | 0 .../enrtree.spec.ts | 0 .../enrtree.ts | 0 .../fetch_nodes.spec.ts | 2 +- .../fetch_nodes.ts | 52 +++- .../index.spec.ts | 2 +- src/lib/peer_discovery_dns/index.ts | 84 ++++++ .../predefined.ts | 2 +- .../testdata.json | 0 src/lib/peer_discovery_static_list.ts | 4 +- src/lib/waku.node.spec.ts | 15 +- src/lib/waku.spec.ts | 2 +- 18 files changed, 210 insertions(+), 284 deletions(-) delete mode 100644 src/lib/discovery/bootstrap.ts delete mode 100644 src/lib/discovery/index.ts rename src/lib/{discovery => peer_discovery_dns}/dns.spec.ts (100%) rename src/lib/{discovery => peer_discovery_dns}/dns.ts (88%) rename src/lib/{discovery => peer_discovery_dns}/dns_over_https.ts (100%) rename src/lib/{discovery => peer_discovery_dns}/enrtree.spec.ts (100%) rename src/lib/{discovery => peer_discovery_dns}/enrtree.ts (100%) rename src/lib/{discovery => peer_discovery_dns}/fetch_nodes.spec.ts (98%) rename src/lib/{discovery => peer_discovery_dns}/fetch_nodes.ts (69%) rename src/lib/{discovery => peer_discovery_dns}/index.spec.ts (94%) create mode 100644 src/lib/peer_discovery_dns/index.ts rename src/lib/{discovery => peer_discovery_dns}/predefined.ts (97%) rename src/lib/{discovery => peer_discovery_dns}/testdata.json (100%) diff --git a/src/index.ts b/src/index.ts index acbc51b3b1..7deef7e4d4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,9 +6,6 @@ export { getPublicKey, } from "./lib/crypto"; -export { getPredefinedBootstrapNodes } from "./lib/discovery"; -export * as discovery from "./lib/discovery"; - export * as enr from "./lib/enr"; export * as utils from "./lib/utils"; diff --git a/src/lib/create_waku.ts b/src/lib/create_waku.ts index e94d9abf11..9c400911bc 100644 --- a/src/lib/create_waku.ts +++ b/src/lib/create_waku.ts @@ -1,10 +1,13 @@ import { Noise } from "@chainsafe/libp2p-noise"; +import type { PeerDiscovery } from "@libp2p/interface-peer-discovery"; import { Mplex } from "@libp2p/mplex"; import { WebSockets } from "@libp2p/websockets"; import { all as filterAll } from "@libp2p/websockets/filters"; import { createLibp2p, Libp2pOptions } from "libp2p"; +import type { Libp2p } from "libp2p"; -import { Bootstrap, BootstrapOptions } from "./discovery"; +import { getPredefinedBootstrapNodes } from "./peer_discovery_dns/predefined"; +import { PeerDiscoveryStaticPeers } from "./peer_discovery_static_list"; import { Waku, WakuOptions } from "./waku"; import { WakuFilter } from "./waku_filter"; import { WakuLightPush } from "./waku_light_push"; @@ -48,29 +51,20 @@ export interface CreateOptions { * Note: It overrides any other peerDiscovery modules that may have been set via * {@link CreateOptions.libp2p}. */ - bootstrap?: BootstrapOptions; + defaultBootstrap?: boolean; } export async function createWaku( options?: CreateOptions & WakuOptions ): Promise { - const peerDiscovery = []; - if (options?.bootstrap) { - peerDiscovery.push(new Bootstrap(options?.bootstrap)); + const libp2pOptions = options?.libp2p ?? {}; + const peerDiscovery = libp2pOptions.peerDiscovery ?? []; + if (options?.defaultBootstrap) { + peerDiscovery.push(defaultPeerDiscovery()); + Object.assign(libp2pOptions, { peerDiscovery }); } - const libp2pOpts = Object.assign( - { - transports: [new WebSockets({ filter: filterAll })], - streamMuxers: [new Mplex()], - pubsub: new WakuRelay(options), - connectionEncryption: [new Noise()], - peerDiscovery: peerDiscovery, - }, - options?.libp2p ?? {} - ); - - const libp2p = await createLibp2p(libp2pOpts); + const libp2p = await defaultLibp2p(new WakuRelay(options), libp2pOptions); const wakuStore = new WakuStore(libp2p, options); const wakuLightPush = new WakuLightPush(libp2p, options); @@ -78,3 +72,24 @@ export async function createWaku( return new Waku(options ?? {}, libp2p, wakuStore, wakuLightPush, wakuFilter); } + +export function defaultPeerDiscovery(): PeerDiscovery { + return new PeerDiscoveryStaticPeers(getPredefinedBootstrapNodes()); +} + +export async function defaultLibp2p( + wakuRelay: WakuRelay, + options?: Partial +): Promise { + const libp2pOpts = Object.assign( + { + transports: [new WebSockets({ filter: filterAll })], + streamMuxers: [new Mplex()], + connectionEncryption: [new Noise()], + }, + { pubsub: wakuRelay }, + options ?? {} + ); + + return createLibp2p(libp2pOpts); +} diff --git a/src/lib/discovery/bootstrap.ts b/src/lib/discovery/bootstrap.ts deleted file mode 100644 index 6bec0ac5f6..0000000000 --- a/src/lib/discovery/bootstrap.ts +++ /dev/null @@ -1,244 +0,0 @@ -import type { - PeerDiscovery, - PeerDiscoveryEvents, -} from "@libp2p/interface-peer-discovery"; -import { symbol } from "@libp2p/interface-peer-discovery"; -import type { PeerInfo } from "@libp2p/interface-peer-info"; -import { CustomEvent, EventEmitter } from "@libp2p/interfaces/events"; -import { peerIdFromString } from "@libp2p/peer-id"; -import { Multiaddr } from "@multiformats/multiaddr"; -import debug from "debug"; - -import { DnsNodeDiscovery, NodeCapabilityCount } from "./dns"; -import { getPredefinedBootstrapNodes } from "./predefined"; -import { getPseudoRandomSubset } from "./random_subset"; - -const log = debug("waku:discovery:bootstrap"); - -/** - * Setup discovery method used to bootstrap. - * - * Only one method is used. [[default]], [[peers]], [[getPeers]] and [[enrUrl]] options are mutually exclusive. - */ -export interface BootstrapOptions { - /** - * The maximum of peers to connect to as part of the bootstrap process. - * This only applies if [[peers]] or [[getPeers]] is used. - * - * @default [[Bootstrap.DefaultMaxPeers]] - */ - maxPeers?: number; - /** - * Use the default discovery method. Overrides all other options but `maxPeers` - * - * The default discovery method is likely to change overtime as new discovery - * methods are implemented. - * - * @default false - */ - default?: boolean; - /** - * Multiaddrs of peers to connect to. - */ - peers?: string[] | Multiaddr[]; - /** - * Getter that retrieve multiaddrs of peers to connect to. - * will be called once. - */ - getPeers?: () => Promise; - /** - * The interval between emitting addresses in milliseconds. - * Used if [[peers]] is passed or a sync function is passed for [[getPeers]] - */ - interval?: number; - /** - * An EIP-1459 ENR Tree URL. For example: - * "enrtree://AOFTICU2XWDULNLZGRMQS4RIZPAZEHYMV4FYHAPW563HNRAOERP7C@test.nodes.vac.dev" - * - * [[wantedNodeCapabilityCount]] MUST be passed when using this option. - */ - enrUrl?: string; - /** - * Specifies what node capabilities (protocol) must be returned. - * This only applies when [[enrUrl]] is passed (EIP-1459 DNS Discovery). - */ - wantedNodeCapabilityCount?: Partial; -} - -/** - * Parse options and expose function to return bootstrap peer addresses. - * - * @throws if an invalid combination of options is passed, see [[BootstrapOptions]] for details. - */ -export class Bootstrap - extends EventEmitter - implements PeerDiscovery -{ - static DefaultMaxPeers = 1; - - private readonly asyncGetBootstrapPeers: - | (() => Promise) - | undefined; - private peers: PeerInfo[]; - private timer?: ReturnType; - private readonly interval: number; - - constructor(opts?: BootstrapOptions) { - super(); - opts = opts ?? {}; - - const methods = [ - !!opts.default, - !!opts.peers, - !!opts.getPeers, - !!opts.enrUrl, - ].filter((x) => x); - if (methods.length > 1) { - throw new Error( - "Bootstrap does not support several discovery methods (yet)" - ); - } - - this.interval = opts.interval ?? 10000; - opts.default = - opts.default ?? (!opts.peers && !opts.getPeers && !opts.enrUrl); - const maxPeers = opts.maxPeers ?? Bootstrap.DefaultMaxPeers; - this.peers = []; - - if (opts.default) { - log("Use hosted list of peers."); - - this.peers = multiaddrsToPeerInfo( - getPredefinedBootstrapNodes(undefined, maxPeers) - ); - return; - } - - if (!!opts.peers && opts.peers.length > 0) { - const allPeers: Multiaddr[] = opts.peers.map( - (node: string | Multiaddr) => { - if (typeof node === "string") { - return new Multiaddr(node); - } else { - return node; - } - } - ); - this.peers = multiaddrsToPeerInfo( - getPseudoRandomSubset(allPeers, maxPeers) - ); - log( - "Use provided list of peers (reduced to maxPeers)", - this.peers.map((ma) => ma.toString()) - ); - return; - } - - if (typeof opts.getPeers === "function") { - log("Bootstrap: Use provided getPeers function."); - const getPeers = opts.getPeers; - - this.asyncGetBootstrapPeers = async () => { - const allPeers = await getPeers(); - return getPseudoRandomSubset( - allPeers, - maxPeers - ).map((node) => new Multiaddr(node)); - }; - return; - } - - if (opts.enrUrl) { - const wantedNodeCapabilityCount = opts.wantedNodeCapabilityCount; - if (!wantedNodeCapabilityCount) - throw "`wantedNodeCapabilityCount` must be defined when using `enrUrl`"; - const enrUrl = opts.enrUrl; - log("Use provided EIP-1459 ENR Tree URL."); - - const dns = DnsNodeDiscovery.dnsOverHttp(); - - this.asyncGetBootstrapPeers = async () => { - const enrs = await dns.getPeers([enrUrl], wantedNodeCapabilityCount); - log(`Found ${enrs.length} peers`); - return enrs.map((enr) => enr.getFullMultiaddrs()).flat(); - }; - - return; - } - } - - /** - * Start discovery process - */ - start(): void { - if (this.asyncGetBootstrapPeers) { - // TODO: This should emit the peer as they are discovered instead of having - // to wait for the full DNS discovery process to be done first. - // TODO: PeerInfo should be returned by discovery - this.asyncGetBootstrapPeers().then((peers) => { - this.peers = multiaddrsToPeerInfo(peers); - this._startTimer(); - }); - } else { - this._startTimer(); - } - } - - private _startTimer(): void { - if (this.peers) { - log("Starting bootstrap node discovery"); - if (this.timer != null) { - return; - } - - this.timer = setInterval(() => this._returnPeers(), this.interval); - - this._returnPeers(); - } - } - - _returnPeers(): void { - if (this.timer == null) { - return; - } - - this.peers.forEach((peerData) => { - this.dispatchEvent( - new CustomEvent("peer", { detail: peerData }) - ); - }); - } - - /** - * Stop emitting events - */ - stop(): void { - if (this.timer != null) { - clearInterval(this.timer); - } - - this.timer = undefined; - } - - get [symbol](): true { - return true; - } - - get [Symbol.toStringTag](): string { - return "@waku/bootstrap"; - } -} - -function multiaddrsToPeerInfo(mas: Multiaddr[]): PeerInfo[] { - return mas - .map((ma) => { - const peerIdStr = ma.getPeerId(); - const protocols: string[] = []; - return { - id: peerIdStr ? peerIdFromString(peerIdStr) : null, - multiaddrs: [ma.decapsulateCode(421)], - protocols, - }; - }) - .filter((peerInfo): peerInfo is PeerInfo => peerInfo.id !== null); -} diff --git a/src/lib/discovery/index.ts b/src/lib/discovery/index.ts deleted file mode 100644 index 6981214899..0000000000 --- a/src/lib/discovery/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -export { getPredefinedBootstrapNodes } from "./predefined"; -export * as predefined from "./predefined"; -export { Bootstrap, BootstrapOptions } from "./bootstrap"; -export * as dns from "./dns"; -export { DnsOverHttps } from "./dns_over_https"; -export { ENRTree, ENRTreeValues, ENRRootValues } from "./enrtree"; diff --git a/src/lib/discovery/dns.spec.ts b/src/lib/peer_discovery_dns/dns.spec.ts similarity index 100% rename from src/lib/discovery/dns.spec.ts rename to src/lib/peer_discovery_dns/dns.spec.ts diff --git a/src/lib/discovery/dns.ts b/src/lib/peer_discovery_dns/dns.ts similarity index 88% rename from src/lib/discovery/dns.ts rename to src/lib/peer_discovery_dns/dns.ts index 1668a4e3c0..27a528efee 100644 --- a/src/lib/discovery/dns.ts +++ b/src/lib/peer_discovery_dns/dns.ts @@ -4,7 +4,10 @@ import { ENR } from "../enr"; import { DnsOverHttps } from "./dns_over_https"; import { ENRTree } from "./enrtree"; -import fetchNodesUntilCapabilitiesFulfilled from "./fetch_nodes"; +import { + fetchNodesUntilCapabilitiesFulfilled, + yieldNodesUntilCapabilitiesFulfilled, +} from "./fetch_nodes"; const dbg = debug("waku:discovery:dns"); @@ -70,6 +73,30 @@ export class DnsNodeDiscovery { this.dns = dns; } + /** + * {@docInherit getPeers} + */ + async *getNextPeer( + enrTreeUrls: string[], + wantedNodeCapabilityCount: Partial + ): AsyncGenerator { + const networkIndex = Math.floor(Math.random() * enrTreeUrls.length); + const { publicKey, domain } = ENRTree.parseTree(enrTreeUrls[networkIndex]); + const context: SearchContext = { + domain, + publicKey, + visits: {}, + }; + + for await (const peer of yieldNodesUntilCapabilitiesFulfilled( + wantedNodeCapabilityCount, + this._errorTolerance, + () => this._search(domain, context) + )) { + yield peer; + } + } + /** * Runs a recursive, randomized descent of the DNS tree to retrieve a single * ENR record as an ENR. Returns null if parsing or DNS resolution fails. diff --git a/src/lib/discovery/dns_over_https.ts b/src/lib/peer_discovery_dns/dns_over_https.ts similarity index 100% rename from src/lib/discovery/dns_over_https.ts rename to src/lib/peer_discovery_dns/dns_over_https.ts diff --git a/src/lib/discovery/enrtree.spec.ts b/src/lib/peer_discovery_dns/enrtree.spec.ts similarity index 100% rename from src/lib/discovery/enrtree.spec.ts rename to src/lib/peer_discovery_dns/enrtree.spec.ts diff --git a/src/lib/discovery/enrtree.ts b/src/lib/peer_discovery_dns/enrtree.ts similarity index 100% rename from src/lib/discovery/enrtree.ts rename to src/lib/peer_discovery_dns/enrtree.ts diff --git a/src/lib/discovery/fetch_nodes.spec.ts b/src/lib/peer_discovery_dns/fetch_nodes.spec.ts similarity index 98% rename from src/lib/discovery/fetch_nodes.spec.ts rename to src/lib/peer_discovery_dns/fetch_nodes.spec.ts index b973a98c11..ac98e4c786 100644 --- a/src/lib/discovery/fetch_nodes.spec.ts +++ b/src/lib/peer_discovery_dns/fetch_nodes.spec.ts @@ -4,7 +4,7 @@ import { expect } from "chai"; import { ENR, Waku2 } from "../enr"; -import fetchNodesUntilCapabilitiesFulfilled from "./fetch_nodes"; +import { fetchNodesUntilCapabilitiesFulfilled } from "./fetch_nodes"; async function createEnr(waku2: Waku2): Promise { const peerId = await createSecp256k1PeerId(); diff --git a/src/lib/discovery/fetch_nodes.ts b/src/lib/peer_discovery_dns/fetch_nodes.ts similarity index 69% rename from src/lib/discovery/fetch_nodes.ts rename to src/lib/peer_discovery_dns/fetch_nodes.ts index 60d2cd3a31..95d568b2e6 100644 --- a/src/lib/discovery/fetch_nodes.ts +++ b/src/lib/peer_discovery_dns/fetch_nodes.ts @@ -11,7 +11,7 @@ const dbg = debug("waku:discovery:fetch_nodes"); * fulfilled or the number of [[getNode]] call exceeds the sum of * [[wantedNodeCapabilityCount]] plus [[errorTolerance]]. */ -export default async function fetchNodesUntilCapabilitiesFulfilled( +export async function fetchNodesUntilCapabilitiesFulfilled( wantedNodeCapabilityCount: Partial, errorTolerance: number, getNode: () => Promise @@ -57,6 +57,56 @@ export default async function fetchNodesUntilCapabilitiesFulfilled( return peers; } +/** + * Fetch nodes using passed [[getNode]] until all wanted capabilities are + * fulfilled or the number of [[getNode]] call exceeds the sum of + * [[wantedNodeCapabilityCount]] plus [[errorTolerance]]. + */ +export async function* yieldNodesUntilCapabilitiesFulfilled( + wantedNodeCapabilityCount: Partial, + errorTolerance: number, + getNode: () => Promise +): AsyncGenerator { + const wanted = { + relay: wantedNodeCapabilityCount.relay ?? 0, + store: wantedNodeCapabilityCount.store ?? 0, + filter: wantedNodeCapabilityCount.filter ?? 0, + lightPush: wantedNodeCapabilityCount.lightPush ?? 0, + }; + + const maxSearches = + wanted.relay + wanted.store + wanted.filter + wanted.lightPush; + + const actual = { + relay: 0, + store: 0, + filter: 0, + lightPush: 0, + }; + + let totalSearches = 0; + const peerNodeIds = new Set(); + + while ( + !isSatisfied(wanted, actual) && + totalSearches < maxSearches + errorTolerance + ) { + const peer = await getNode(); + if (peer && peer.nodeId && !peerNodeIds.has(peer.nodeId)) { + peerNodeIds.add(peer.nodeId); + // ENRs without a waku2 key are ignored. + if (peer.waku2) { + if (helpsSatisfyCapabilities(peer.waku2, wanted, actual)) { + addCapabilities(peer.waku2, actual); + yield peer; + } + } + dbg(`got new peer candidate from DNS address=${peer.nodeId}@${peer.ip}`); + } + totalSearches++; + } +} + function isSatisfied( wanted: NodeCapabilityCount, actual: NodeCapabilityCount diff --git a/src/lib/discovery/index.spec.ts b/src/lib/peer_discovery_dns/index.spec.ts similarity index 94% rename from src/lib/discovery/index.spec.ts rename to src/lib/peer_discovery_dns/index.spec.ts index c0eb090932..175f529dd9 100644 --- a/src/lib/discovery/index.spec.ts +++ b/src/lib/peer_discovery_dns/index.spec.ts @@ -1,6 +1,6 @@ import { expect } from "chai"; -import { getPseudoRandomSubset } from "./random_subset"; +import { getPseudoRandomSubset } from "../random_subset"; describe("Discovery", () => { it("returns all values when wanted number matches available values", function () { diff --git a/src/lib/peer_discovery_dns/index.ts b/src/lib/peer_discovery_dns/index.ts new file mode 100644 index 0000000000..2df5e00662 --- /dev/null +++ b/src/lib/peer_discovery_dns/index.ts @@ -0,0 +1,84 @@ +import type { + PeerDiscovery, + PeerDiscoveryEvents, +} from "@libp2p/interface-peer-discovery"; +import { symbol } from "@libp2p/interface-peer-discovery"; +import type { PeerInfo } from "@libp2p/interface-peer-info"; +import { CustomEvent, EventEmitter } from "@libp2p/interfaces/events"; +import debug from "debug"; + +import { ENR } from "../enr"; +import { multiaddrsToPeerInfo } from "../multiaddr_to_peer_info"; + +import { DnsNodeDiscovery, NodeCapabilityCount } from "./dns"; + +const log = debug("waku:peer-discovery-dns"); + +/** + * Parse options and expose function to return bootstrap peer addresses. + * + * @throws if an invalid combination of options is passed, see [[BootstrapOptions]] for details. + */ +export class PeerDiscoveryDns + extends EventEmitter + implements PeerDiscovery +{ + private readonly nextPeer: () => AsyncGenerator; + private _started: boolean; + + /** + * @param enrUrl An EIP-1459 ENR Tree URL. For example: + * "enrtree://AOFTICU2XWDULNLZGRMQS4RIZPAZEHYMV4FYHAPW563HNRAOERP7C@test.nodes.vac.dev" + * @param wantedNodeCapabilityCount Specifies what node capabilities + * (protocol) must be returned. + */ + constructor( + enrUrl: string, + wantedNodeCapabilityCount: Partial + ) { + super(); + this._started = false; + log("Use following EIP-1459 ENR Tree URL: ", enrUrl); + + const dns = DnsNodeDiscovery.dnsOverHttp(); + + this.nextPeer = dns.getNextPeer.bind( + {}, + [enrUrl], + wantedNodeCapabilityCount + ); + } + + /** + * Start discovery process + */ + async start(): Promise { + log("Starting peer discovery via dns"); + + this._started = true; + for await (const peer of this.nextPeer()) { + if (!this._started) return; + const peerInfos = multiaddrsToPeerInfo(peer.getFullMultiaddrs()); + peerInfos.forEach((peerInfo) => { + this.dispatchEvent( + new CustomEvent("peer", { detail: peerInfo }) + ); + }); + } + } + + /** + * Stop emitting events + */ + stop(): void { + this._started = false; + } + + get [symbol](): true { + return true; + } + + get [Symbol.toStringTag](): string { + return "@waku/bootstrap"; + } +} diff --git a/src/lib/discovery/predefined.ts b/src/lib/peer_discovery_dns/predefined.ts similarity index 97% rename from src/lib/discovery/predefined.ts rename to src/lib/peer_discovery_dns/predefined.ts index 04b662f59d..553a6a0058 100644 --- a/src/lib/discovery/predefined.ts +++ b/src/lib/peer_discovery_dns/predefined.ts @@ -1,6 +1,6 @@ import { Multiaddr } from "@multiformats/multiaddr"; -import { getPseudoRandomSubset } from "./random_subset"; +import { getPseudoRandomSubset } from "../random_subset"; export const DefaultWantedNumber = 1; diff --git a/src/lib/discovery/testdata.json b/src/lib/peer_discovery_dns/testdata.json similarity index 100% rename from src/lib/discovery/testdata.json rename to src/lib/peer_discovery_dns/testdata.json diff --git a/src/lib/peer_discovery_static_list.ts b/src/lib/peer_discovery_static_list.ts index 55a020a862..2ac2ce3e13 100644 --- a/src/lib/peer_discovery_static_list.ts +++ b/src/lib/peer_discovery_static_list.ts @@ -11,7 +11,7 @@ import debug from "debug"; import { multiaddrsToPeerInfo } from "./multiaddr_to_peer_info"; import { getPseudoRandomSubset } from "./random_subset"; -const log = debug("waku:discovery:static-list"); +const log = debug("waku:peer-discovery-static-list"); export interface Options { /** @@ -75,7 +75,7 @@ export class PeerDiscoveryStaticPeers private _startTimer(): void { if (this.peers) { - log("Starting emitting static peers for boostrap."); + log("Starting to emit static peers."); if (this.timer != null) { return; } diff --git a/src/lib/waku.node.spec.ts b/src/lib/waku.node.spec.ts index 9dc57ff3f0..c61d6b31f1 100644 --- a/src/lib/waku.node.spec.ts +++ b/src/lib/waku.node.spec.ts @@ -10,6 +10,7 @@ import { import { createWaku } from "./create_waku"; import { generateSymmetricKey } from "./crypto"; +import { PeerDiscoveryStaticPeers } from "./peer_discovery_static_list"; import { waitForRemotePeer } from "./wait_for_remote_peer"; import { Protocols, Waku } from "./waku"; import { WakuMessage } from "./waku_message"; @@ -61,7 +62,9 @@ describe("Waku Dial [node only]", function () { const multiAddrWithId = await nwaku.getMultiaddrWithId(); waku = await createWaku({ staticNoiseKey: NOISE_KEY_1, - bootstrap: { peers: [multiAddrWithId] }, + libp2p: { + peerDiscovery: [new PeerDiscoveryStaticPeers([multiAddrWithId])], + }, }); await waku.start(); @@ -77,7 +80,7 @@ describe("Waku Dial [node only]", function () { expect(connectedPeerID.toString()).to.eq(multiAddrWithId.getPeerId()); }); - it("Passing a function", async function () { + it("Using a function", async function () { this.timeout(10_000); nwaku = new Nwaku(makeLogFileName(this)); @@ -85,10 +88,10 @@ describe("Waku Dial [node only]", function () { waku = await createWaku({ staticNoiseKey: NOISE_KEY_1, - bootstrap: { - getPeers: async () => { - return [await nwaku.getMultiaddrWithId()]; - }, + libp2p: { + peerDiscovery: [ + new PeerDiscoveryStaticPeers([await nwaku.getMultiaddrWithId()]), + ], }, }); await waku.start(); diff --git a/src/lib/waku.spec.ts b/src/lib/waku.spec.ts index ff188b4671..9ac244d2c9 100644 --- a/src/lib/waku.spec.ts +++ b/src/lib/waku.spec.ts @@ -24,7 +24,7 @@ describe("Waku Dial", function () { this.timeout(20_000); waku = await createWaku({ - bootstrap: { default: true }, + defaultBootstrap: true, }); await waku.start(); From 8c27975830074b1b349ab49d91a236064c62c6e3 Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Fri, 5 Aug 2022 23:47:38 +1000 Subject: [PATCH 07/11] fix: outdated doc & links --- src/lib/create_waku.ts | 7 +------ src/lib/wait_for_remote_peer.ts | 3 ++- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/lib/create_waku.ts b/src/lib/create_waku.ts index 9c400911bc..50e9edc7c4 100644 --- a/src/lib/create_waku.ts +++ b/src/lib/create_waku.ts @@ -44,12 +44,7 @@ export interface CreateOptions { */ staticNoiseKey?: Uint8Array; /** - * Use libp2p-bootstrap to discover and connect to new nodes. - * - * See [[BootstrapOptions]] for available parameters. - * - * Note: It overrides any other peerDiscovery modules that may have been set via - * {@link CreateOptions.libp2p}. + * Use recommended bootstrap method to discovery and connect to new nodes. */ defaultBootstrap?: boolean; } diff --git a/src/lib/wait_for_remote_peer.ts b/src/lib/wait_for_remote_peer.ts index 87cd439d96..24917fa608 100644 --- a/src/lib/wait_for_remote_peer.ts +++ b/src/lib/wait_for_remote_peer.ts @@ -22,7 +22,8 @@ interface WakuGossipSubProtocol extends GossipSub { /** * Wait for a remote peer to be ready given the passed protocols. - * Useful when using the [[CreateOptions.bootstrap]] with [[createWaku]]. + * Must be used after attempting to connect to nodes, using {@link Waku.dial} or + * a bootstrap method with {@link Waku.constructor}. * * If the passed protocols is a GossipSub protocol, then it resolves only once * a peer is in a mesh, to help ensure that other peers will send and receive From d560f8ce0e313727a4be4462c747740b0f28cfc0 Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Sat, 6 Aug 2022 00:36:46 +1000 Subject: [PATCH 08/11] fix: bundling with exports map --- .gitignore | 1 + .size-limit.cjs | 21 +++-- package-lock.json | 209 +++++++++++++++++++++++++--------------------- package.json | 9 +- rollup.config.js | 8 +- src/index.ts | 1 - 6 files changed, 140 insertions(+), 109 deletions(-) diff --git a/.gitignore b/.gitignore index 450ea387c0..4e1636b837 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ coverage *.log /tsconfig.tsbuildinfo /tsconfig.dev.tsbuildinfo +/bundle/ diff --git a/.size-limit.cjs b/.size-limit.cjs index d7cef565b2..d48811ec21 100644 --- a/.size-limit.cjs +++ b/.size-limit.cjs @@ -1,37 +1,40 @@ module.exports = [ { name: "Waku core", - path: "dist/bundle.min.js", + path: "bundle/index.js", import: "{ Waku }", }, { name: "Waku default setup", - path: "dist/bundle.min.js", - import: "{ createWaku, waitForRemotePeer }", + path: ["bundle/index.js", "bundle/lib/create_waku.js"], + import: { + "./bundle/lib/create_waku.js": "{ createWaku }", + "./bundle/index.js": "{ waitForRemotePeer }", + }, }, { name: "Asymmetric, symmetric encryption and signature", - path: "dist/bundle.min.js", + path: "bundle/index.js", import: "{ waku_message }", }, { name: "DNS discovery", - path: "dist/bundle.min.js", - import: "{ discovery }", + path: "bundle/lib/peer_discovery_dns.js", + import: "{ PeerDiscoveryDns }", }, { name: "Privacy preserving protocols", - path: "dist/bundle.min.js", + path: "bundle/index.js", import: "{ WakuRelay }", }, { name: "Light protocols", - path: "dist/bundle.min.js", + path: "bundle/index.js", import: "{ WakuLightPush, WakuFilter }", }, { name: "History retrieval protocols", - path: "dist/bundle.min.js", + path: "bundle/index.js", import: "{ WakuStore }", }, ]; diff --git a/package-lock.json b/package-lock.json index 4fccdda90a..362b5a5e5c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -83,7 +83,6 @@ "rollup": "^2.75.0", "size-limit": "^8.0.0", "tail": "^2.2.0", - "terser": "^5.13.1", "ts-loader": "^9.2.6", "ts-node": "^10.4.0", "typedoc": "^0.22.10", @@ -798,6 +797,64 @@ "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", "dev": true }, + "node_modules/@jridgewell/gen-mapping": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz", + "integrity": "sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A==", + "dev": true, + "dependencies": { + "@jridgewell/set-array": "^1.0.1", + "@jridgewell/sourcemap-codec": "^1.4.10", + "@jridgewell/trace-mapping": "^0.3.9" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", + "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", + "dev": true, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/set-array": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz", + "integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==", + "dev": true, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/source-map": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.2.tgz", + "integrity": "sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw==", + "dev": true, + "dependencies": { + "@jridgewell/gen-mapping": "^0.3.0", + "@jridgewell/trace-mapping": "^0.3.9" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.4.14", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", + "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", + "dev": true + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.14", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.14.tgz", + "integrity": "sha512-bJWEfQ9lPTvm3SneWwRFVLzrh6nhjwqw7TUFFBEMzwvg7t7PCDenf2lDwqo4NQXzdpgBXyFgDWnQA+2vkruksQ==", + "dev": true, + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "node_modules/@leichtgewicht/base64-codec": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@leichtgewicht/base64-codec/-/base64-codec-1.0.0.tgz", @@ -7571,12 +7628,6 @@ "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", "dev": true }, - "node_modules/lodash.sortby": { - "version": "4.7.0", - "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", - "integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=", - "dev": true - }, "node_modules/log-symbols": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", @@ -10568,14 +10619,14 @@ } }, "node_modules/terser": { - "version": "5.13.1", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.13.1.tgz", - "integrity": "sha512-hn4WKOfwnwbYfe48NgrQjqNOH9jzLqRcIfbYytOXCOv46LBfWr9bDS17MQqOi+BWGD0sJK3Sj5NC/gJjiojaoA==", + "version": "5.14.2", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.14.2.tgz", + "integrity": "sha512-oL0rGeM/WFQCUd0y2QrWxYnq7tfSuKBiqTjRPWrRgB46WD/kiwHwF8T23z78H6Q6kGCuuHcPB+KULHRdxvVGQA==", "dev": true, "dependencies": { + "@jridgewell/source-map": "^0.3.2", "acorn": "^8.5.0", "commander": "^2.20.0", - "source-map": "~0.8.0-beta.0", "source-map-support": "~0.5.20" }, "bin": { @@ -10664,44 +10715,6 @@ "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", "dev": true }, - "node_modules/terser/node_modules/source-map": { - "version": "0.8.0-beta.0", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.8.0-beta.0.tgz", - "integrity": "sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==", - "dev": true, - "dependencies": { - "whatwg-url": "^7.0.0" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/terser/node_modules/tr46": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-1.0.1.tgz", - "integrity": "sha1-qLE/1r/SSJUZZ0zN5VujaTtwbQk=", - "dev": true, - "dependencies": { - "punycode": "^2.1.0" - } - }, - "node_modules/terser/node_modules/webidl-conversions": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz", - "integrity": "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==", - "dev": true - }, - "node_modules/terser/node_modules/whatwg-url": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-7.1.0.tgz", - "integrity": "sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==", - "dev": true, - "dependencies": { - "lodash.sortby": "^4.7.0", - "tr46": "^1.0.1", - "webidl-conversions": "^4.0.2" - } - }, "node_modules/text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", @@ -12381,6 +12394,55 @@ "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", "dev": true }, + "@jridgewell/gen-mapping": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz", + "integrity": "sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A==", + "dev": true, + "requires": { + "@jridgewell/set-array": "^1.0.1", + "@jridgewell/sourcemap-codec": "^1.4.10", + "@jridgewell/trace-mapping": "^0.3.9" + } + }, + "@jridgewell/resolve-uri": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", + "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", + "dev": true + }, + "@jridgewell/set-array": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz", + "integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==", + "dev": true + }, + "@jridgewell/source-map": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.2.tgz", + "integrity": "sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw==", + "dev": true, + "requires": { + "@jridgewell/gen-mapping": "^0.3.0", + "@jridgewell/trace-mapping": "^0.3.9" + } + }, + "@jridgewell/sourcemap-codec": { + "version": "1.4.14", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", + "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", + "dev": true + }, + "@jridgewell/trace-mapping": { + "version": "0.3.14", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.14.tgz", + "integrity": "sha512-bJWEfQ9lPTvm3SneWwRFVLzrh6nhjwqw7TUFFBEMzwvg7t7PCDenf2lDwqo4NQXzdpgBXyFgDWnQA+2vkruksQ==", + "dev": true, + "requires": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "@leichtgewicht/base64-codec": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@leichtgewicht/base64-codec/-/base64-codec-1.0.0.tgz", @@ -17593,12 +17655,6 @@ "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", "dev": true }, - "lodash.sortby": { - "version": "4.7.0", - "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", - "integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=", - "dev": true - }, "log-symbols": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", @@ -19794,14 +19850,14 @@ } }, "terser": { - "version": "5.13.1", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.13.1.tgz", - "integrity": "sha512-hn4WKOfwnwbYfe48NgrQjqNOH9jzLqRcIfbYytOXCOv46LBfWr9bDS17MQqOi+BWGD0sJK3Sj5NC/gJjiojaoA==", + "version": "5.14.2", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.14.2.tgz", + "integrity": "sha512-oL0rGeM/WFQCUd0y2QrWxYnq7tfSuKBiqTjRPWrRgB46WD/kiwHwF8T23z78H6Q6kGCuuHcPB+KULHRdxvVGQA==", "dev": true, "requires": { + "@jridgewell/source-map": "^0.3.2", "acorn": "^8.5.0", "commander": "^2.20.0", - "source-map": "~0.8.0-beta.0", "source-map-support": "~0.5.20" }, "dependencies": { @@ -19810,41 +19866,6 @@ "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", "dev": true - }, - "source-map": { - "version": "0.8.0-beta.0", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.8.0-beta.0.tgz", - "integrity": "sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==", - "dev": true, - "requires": { - "whatwg-url": "^7.0.0" - } - }, - "tr46": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-1.0.1.tgz", - "integrity": "sha1-qLE/1r/SSJUZZ0zN5VujaTtwbQk=", - "dev": true, - "requires": { - "punycode": "^2.1.0" - } - }, - "webidl-conversions": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz", - "integrity": "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==", - "dev": true - }, - "whatwg-url": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-7.1.0.tgz", - "integrity": "sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==", - "dev": true, - "requires": { - "lodash.sortby": "^4.7.0", - "tr46": "^1.0.1", - "webidl-conversions": "^4.0.2" - } } } }, diff --git a/package.json b/package.json index 6bd9c41083..e3dc5604b4 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,10 @@ "./lib/create_waku": { "types": "./dist/lib/create_waku.d.ts", "import": "./dist/lib/create_waku.js" + }, + "./lib/peer_discovery_dns": { + "types": "./dist/lib/peer_discovery_dns/index.d.ts", + "import": "./dist/lib/peer_discovery_dns/index.js" } }, "type": "module", @@ -29,8 +33,7 @@ "prepare": "husky install", "build": "run-s build:**", "build:esm": "tsc && node build-scripts/fix-imports.js", - "build:bundle": "rollup --config rollup.config.js -- dist/index.js", - "build:bundle:min": "terser --ecma 11 --compress --mangle -o dist/bundle.min.js -- dist/bundle.js && gzip -9 -c dist/bundle.min.js > dist/bundle.min.js.gz", + "build:bundle": "rollup --config rollup.config.js", "size": "npm run build && size-limit", "fix": "run-s fix:*", "fix:prettier": "prettier \"src/**/*.ts\" \"./*.json\" \"*.*js\" \".github/**/*.yml\" --write", @@ -141,7 +144,6 @@ "rollup": "^2.75.0", "size-limit": "^8.0.0", "tail": "^2.2.0", - "terser": "^5.13.1", "ts-loader": "^9.2.6", "ts-node": "^10.4.0", "typedoc": "^0.22.10", @@ -150,6 +152,7 @@ }, "files": [ "dist", + "bundle", "src/*.ts", "src/lib/**/*.ts", "src/proto/**/*.ts", diff --git a/rollup.config.js b/rollup.config.js index f9b1282164..0aee5966b2 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,10 +3,14 @@ import commonjs from "@rollup/plugin-commonjs"; import json from "@rollup/plugin-json"; export default { + input: { + index: "dist/index.js", + "lib/create_waku": "dist/lib/create_waku.js", + "lib/peer_discovery_dns": "dist/lib/peer_discovery_dns/index.js", + }, output: { - file: "dist/bundle.js", + dir: "bundle", format: "esm", - name: "waku", }, plugins: [ commonjs(), diff --git a/src/index.ts b/src/index.ts index 7deef7e4d4..6cf9c77e20 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,4 +35,3 @@ export { WakuRelay } from "./lib/waku_relay"; export * as waku_store from "./lib/waku_store"; export { PageDirection, WakuStore, StoreCodecs } from "./lib/waku_store"; -export { createWaku } from "./lib/create_waku"; From 5f1ac595b68a712d7a7a9c654ec8b3c58c1182ce Mon Sep 17 00:00:00 2001 From: "fryorcraken.eth" Date: Sat, 6 Aug 2022 00:41:41 +1000 Subject: [PATCH 09/11] fix(examples): update using new bundles --- examples/relay-js/index.html | 8 +++++--- examples/store-js/index.html | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/relay-js/index.html b/examples/relay-js/index.html index dec722d157..8dbe291b42 100644 --- a/examples/relay-js/index.html +++ b/examples/relay-js/index.html @@ -27,10 +27,12 @@ */ import { - createWaku, waitForRemotePeer, WakuMessage - } from '../../dist/bundle.js'; + } from '../../bundle/index.js'; + import { + createWaku, + } from '../../bundle/lib/create_waku.js'; const statusDiv = document.getElementById('status'); const messagesDiv = document.getElementById('messages'); @@ -56,7 +58,7 @@ // We are currently working on migrating this method to DNS Discovery. // // https://js-waku.wakuconnect.dev/classes/waku.Waku.html#create - const waku = await createWaku({ bootstrap: { default: true } }); + const waku = await createWaku({ defaultBootstrap: true }); await waku.start(); // Had a hook to process all incoming messages on a specified content topic. diff --git a/examples/store-js/index.html b/examples/store-js/index.html index cee9a3367a..a5f06d3a94 100644 --- a/examples/store-js/index.html +++ b/examples/store-js/index.html @@ -14,10 +14,12 @@