fix: remove initialising peer-exchange while creating a node (#1158)

* remove peer-exchange from @waku/core
- also removes the manual test for peer-exchange (assumption is that the
only way to initialise peer-exchange is through libp2p's peerDiscovery and
not manually) (ref:
https://github.com/waku-org/js-waku/pull/1158#discussion_r1108055234)

 # Please enter the commit message for your changes. Lines
starting

* fix: build

* update interop test

* decrease test duration for px auto discovery

* rm: only for tests

* address comment
This commit is contained in:
Danish Arora 2023-02-17 13:27:37 +05:30 committed by GitHub
parent fa6ecd6e93
commit 1b41569023
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 109 additions and 134 deletions

81
package-lock.json generated
View File

@ -26984,32 +26984,36 @@
}, },
"packages/tests/node_modules/ansi-colors": { "packages/tests/node_modules/ansi-colors": {
"version": "4.1.1", "version": "4.1.1",
"resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz",
"integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==",
"dev": true, "dev": true,
"license": "MIT",
"engines": { "engines": {
"node": ">=6" "node": ">=6"
} }
}, },
"packages/tests/node_modules/ansi-regex": { "packages/tests/node_modules/ansi-regex": {
"version": "5.0.1", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"dev": true, "dev": true,
"license": "MIT",
"engines": { "engines": {
"node": ">=8" "node": ">=8"
} }
}, },
"packages/tests/node_modules/brace-expansion": { "packages/tests/node_modules/brace-expansion": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
"integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
"dev": true, "dev": true,
"license": "MIT",
"dependencies": { "dependencies": {
"balanced-match": "^1.0.0" "balanced-match": "^1.0.0"
} }
}, },
"packages/tests/node_modules/cliui": { "packages/tests/node_modules/cliui": {
"version": "7.0.4", "version": "7.0.4",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz",
"integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==",
"dev": true, "dev": true,
"license": "ISC",
"dependencies": { "dependencies": {
"string-width": "^4.2.0", "string-width": "^4.2.0",
"strip-ansi": "^6.0.0", "strip-ansi": "^6.0.0",
@ -27018,21 +27022,24 @@
}, },
"packages/tests/node_modules/diff": { "packages/tests/node_modules/diff": {
"version": "5.0.0", "version": "5.0.0",
"resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz",
"integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==",
"dev": true, "dev": true,
"license": "BSD-3-Clause",
"engines": { "engines": {
"node": ">=0.3.1" "node": ">=0.3.1"
} }
}, },
"packages/tests/node_modules/emoji-regex": { "packages/tests/node_modules/emoji-regex": {
"version": "8.0.0", "version": "8.0.0",
"dev": true, "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
"license": "MIT" "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
"dev": true
}, },
"packages/tests/node_modules/find-up": { "packages/tests/node_modules/find-up": {
"version": "5.0.0", "version": "5.0.0",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz",
"integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==",
"dev": true, "dev": true,
"license": "MIT",
"dependencies": { "dependencies": {
"locate-path": "^6.0.0", "locate-path": "^6.0.0",
"path-exists": "^4.0.0" "path-exists": "^4.0.0"
@ -27046,8 +27053,9 @@
}, },
"packages/tests/node_modules/glob": { "packages/tests/node_modules/glob": {
"version": "7.2.0", "version": "7.2.0",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz",
"integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==",
"dev": true, "dev": true,
"license": "ISC",
"dependencies": { "dependencies": {
"fs.realpath": "^1.0.0", "fs.realpath": "^1.0.0",
"inflight": "^1.0.4", "inflight": "^1.0.4",
@ -27065,16 +27073,18 @@
}, },
"packages/tests/node_modules/is-fullwidth-code-point": { "packages/tests/node_modules/is-fullwidth-code-point": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
"dev": true, "dev": true,
"license": "MIT",
"engines": { "engines": {
"node": ">=8" "node": ">=8"
} }
}, },
"packages/tests/node_modules/is-unicode-supported": { "packages/tests/node_modules/is-unicode-supported": {
"version": "0.1.0", "version": "0.1.0",
"resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz",
"integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==",
"dev": true, "dev": true,
"license": "MIT",
"engines": { "engines": {
"node": ">=10" "node": ">=10"
}, },
@ -27084,8 +27094,9 @@
}, },
"packages/tests/node_modules/locate-path": { "packages/tests/node_modules/locate-path": {
"version": "6.0.0", "version": "6.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz",
"integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==",
"dev": true, "dev": true,
"license": "MIT",
"dependencies": { "dependencies": {
"p-locate": "^5.0.0" "p-locate": "^5.0.0"
}, },
@ -27098,8 +27109,9 @@
}, },
"packages/tests/node_modules/log-symbols": { "packages/tests/node_modules/log-symbols": {
"version": "4.1.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz",
"integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==",
"dev": true, "dev": true,
"license": "MIT",
"dependencies": { "dependencies": {
"chalk": "^4.1.0", "chalk": "^4.1.0",
"is-unicode-supported": "^0.1.0" "is-unicode-supported": "^0.1.0"
@ -27113,8 +27125,9 @@
}, },
"packages/tests/node_modules/mocha": { "packages/tests/node_modules/mocha": {
"version": "10.2.0", "version": "10.2.0",
"resolved": "https://registry.npmjs.org/mocha/-/mocha-10.2.0.tgz",
"integrity": "sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg==",
"dev": true, "dev": true,
"license": "MIT",
"dependencies": { "dependencies": {
"ansi-colors": "4.1.1", "ansi-colors": "4.1.1",
"browser-stdout": "1.3.1", "browser-stdout": "1.3.1",
@ -27152,8 +27165,9 @@
}, },
"packages/tests/node_modules/mocha/node_modules/minimatch": { "packages/tests/node_modules/mocha/node_modules/minimatch": {
"version": "5.0.1", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.0.1.tgz",
"integrity": "sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g==",
"dev": true, "dev": true,
"license": "ISC",
"dependencies": { "dependencies": {
"brace-expansion": "^2.0.1" "brace-expansion": "^2.0.1"
}, },
@ -27163,13 +27177,15 @@
}, },
"packages/tests/node_modules/ms": { "packages/tests/node_modules/ms": {
"version": "2.1.3", "version": "2.1.3",
"dev": true, "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"license": "MIT" "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
"dev": true
}, },
"packages/tests/node_modules/nanoid": { "packages/tests/node_modules/nanoid": {
"version": "3.3.3", "version": "3.3.3",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.3.tgz",
"integrity": "sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==",
"dev": true, "dev": true,
"license": "MIT",
"bin": { "bin": {
"nanoid": "bin/nanoid.cjs" "nanoid": "bin/nanoid.cjs"
}, },
@ -27179,8 +27195,9 @@
}, },
"packages/tests/node_modules/p-limit": { "packages/tests/node_modules/p-limit": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz",
"integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==",
"dev": true, "dev": true,
"license": "MIT",
"dependencies": { "dependencies": {
"yocto-queue": "^0.1.0" "yocto-queue": "^0.1.0"
}, },
@ -27193,8 +27210,9 @@
}, },
"packages/tests/node_modules/p-locate": { "packages/tests/node_modules/p-locate": {
"version": "5.0.0", "version": "5.0.0",
"resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz",
"integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==",
"dev": true, "dev": true,
"license": "MIT",
"dependencies": { "dependencies": {
"p-limit": "^3.0.2" "p-limit": "^3.0.2"
}, },
@ -27207,16 +27225,18 @@
}, },
"packages/tests/node_modules/serialize-javascript": { "packages/tests/node_modules/serialize-javascript": {
"version": "6.0.0", "version": "6.0.0",
"resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz",
"integrity": "sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==",
"dev": true, "dev": true,
"license": "BSD-3-Clause",
"dependencies": { "dependencies": {
"randombytes": "^2.1.0" "randombytes": "^2.1.0"
} }
}, },
"packages/tests/node_modules/string-width": { "packages/tests/node_modules/string-width": {
"version": "4.2.3", "version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
"dev": true, "dev": true,
"license": "MIT",
"dependencies": { "dependencies": {
"emoji-regex": "^8.0.0", "emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0", "is-fullwidth-code-point": "^3.0.0",
@ -27228,8 +27248,9 @@
}, },
"packages/tests/node_modules/strip-ansi": { "packages/tests/node_modules/strip-ansi": {
"version": "6.0.1", "version": "6.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
"dev": true, "dev": true,
"license": "MIT",
"dependencies": { "dependencies": {
"ansi-regex": "^5.0.1" "ansi-regex": "^5.0.1"
}, },
@ -27239,8 +27260,9 @@
}, },
"packages/tests/node_modules/strip-json-comments": { "packages/tests/node_modules/strip-json-comments": {
"version": "3.1.1", "version": "3.1.1",
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz",
"integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==",
"dev": true, "dev": true,
"license": "MIT",
"engines": { "engines": {
"node": ">=8" "node": ">=8"
}, },
@ -27250,13 +27272,15 @@
}, },
"packages/tests/node_modules/workerpool": { "packages/tests/node_modules/workerpool": {
"version": "6.2.1", "version": "6.2.1",
"dev": true, "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.1.tgz",
"license": "Apache-2.0" "integrity": "sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==",
"dev": true
}, },
"packages/tests/node_modules/yargs": { "packages/tests/node_modules/yargs": {
"version": "16.2.0", "version": "16.2.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz",
"integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==",
"dev": true, "dev": true,
"license": "MIT",
"dependencies": { "dependencies": {
"cliui": "^7.0.2", "cliui": "^7.0.2",
"escalade": "^3.1.1", "escalade": "^3.1.1",
@ -27272,8 +27296,9 @@
}, },
"packages/tests/node_modules/yargs-parser": { "packages/tests/node_modules/yargs-parser": {
"version": "20.2.4", "version": "20.2.4",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.4.tgz",
"integrity": "sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==",
"dev": true, "dev": true,
"license": "ISC",
"engines": { "engines": {
"node": ">=10" "node": ">=10"
} }

View File

@ -60,14 +60,6 @@ export async function waitForRemotePeer(
promises.push(waitForConnectedPeer(waku.filter)); promises.push(waitForConnectedPeer(waku.filter));
} }
if (protocols.includes(Protocols.PeerExchange)) {
if (!waku.peerExchange)
throw new Error(
"Cannot wait for Peer Exchange peer: protocol not mounted"
);
promises.push(waitForConnectedPeer(waku.peerExchange));
}
if (timeoutMs) { if (timeoutMs) {
await rejectOnTimeout( await rejectOnTimeout(
Promise.all(promises), Promise.all(promises),

View File

@ -6,10 +6,8 @@ import type { Multiaddr } from "@multiformats/multiaddr";
import type { import type {
IFilter, IFilter,
ILightPush, ILightPush,
IPeerExchange,
IRelay, IRelay,
IStore, IStore,
PeerExchangeComponents,
Waku, Waku,
} from "@waku/interfaces"; } from "@waku/interfaces";
import { Protocols } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces";
@ -53,7 +51,6 @@ export class WakuNode implements Waku {
public store?: IStore; public store?: IStore;
public filter?: IFilter; public filter?: IFilter;
public lightPush?: ILightPush; public lightPush?: ILightPush;
public peerExchange?: IPeerExchange;
private pingKeepAliveTimers: { private pingKeepAliveTimers: {
[peer: string]: ReturnType<typeof setInterval>; [peer: string]: ReturnType<typeof setInterval>;
@ -67,8 +64,7 @@ export class WakuNode implements Waku {
libp2p: Libp2p, libp2p: Libp2p,
store?: (libp2p: Libp2p) => IStore, store?: (libp2p: Libp2p) => IStore,
lightPush?: (libp2p: Libp2p) => ILightPush, lightPush?: (libp2p: Libp2p) => ILightPush,
filter?: (libp2p: Libp2p) => IFilter, filter?: (libp2p: Libp2p) => IFilter
peerExchange?: (components: PeerExchangeComponents) => IPeerExchange
) { ) {
this.libp2p = libp2p; this.libp2p = libp2p;
@ -82,13 +78,6 @@ export class WakuNode implements Waku {
this.lightPush = lightPush(libp2p); this.lightPush = lightPush(libp2p);
} }
if (peerExchange) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: Libp2p is now hiding internal components but peer discovery
// implementation still expect to receive said components.
this.peerExchange = peerExchange(libp2p.components);
}
if (isRelay(libp2p.pubsub)) { if (isRelay(libp2p.pubsub)) {
this.relay = libp2p.pubsub; this.relay = libp2p.pubsub;
} }
@ -97,8 +86,7 @@ export class WakuNode implements Waku {
"Waku node created", "Waku node created",
this.libp2p.peerId.toString(), this.libp2p.peerId.toString(),
`relay: ${!!this.relay}, store: ${!!this.store}, light push: ${!!this `relay: ${!!this.relay}, store: ${!!this.store}, light push: ${!!this
.lightPush}, filter: ${!!this.filter}, peer exchange: ${!!this .lightPush}, filter: ${!!this.filter}} `
.peerExchange} `
); );
this.pingKeepAliveTimers = {}; this.pingKeepAliveTimers = {};
@ -156,7 +144,6 @@ export class WakuNode implements Waku {
this.store && _protocols.push(Protocols.Store); this.store && _protocols.push(Protocols.Store);
this.filter && _protocols.push(Protocols.Filter); this.filter && _protocols.push(Protocols.Filter);
this.lightPush && _protocols.push(Protocols.LightPush); this.lightPush && _protocols.push(Protocols.LightPush);
this.peerExchange && _protocols.push(Protocols.PeerExchange);
} }
const codecs: string[] = []; const codecs: string[] = [];
@ -197,16 +184,6 @@ export class WakuNode implements Waku {
} }
} }
if (_protocols.includes(Protocols.PeerExchange)) {
if (this.peerExchange) {
codecs.push(this.peerExchange.multicodec);
} else {
log(
"Peer Exchange codec not included in dial codec: protocol not mounted locally"
);
}
}
log(`Dialing to ${peer.toString()} with protocols ${_protocols}`); log(`Dialing to ${peer.toString()} with protocols ${_protocols}`);
return this.libp2p.dialProtocol(peer, codecs); return this.libp2p.dialProtocol(peer, codecs);

View File

@ -5,6 +5,7 @@ import { mplex } from "@libp2p/mplex";
import { webSockets } from "@libp2p/websockets"; import { webSockets } from "@libp2p/websockets";
import { all as filterAll } from "@libp2p/websockets/filters"; import { all as filterAll } from "@libp2p/websockets/filters";
import { import {
DefaultUserAgent,
RelayCreateOptions, RelayCreateOptions,
wakuFilter, wakuFilter,
wakuLightPush, wakuLightPush,
@ -13,7 +14,6 @@ import {
wakuRelay, wakuRelay,
wakuStore, wakuStore,
} from "@waku/core"; } from "@waku/core";
import { DefaultUserAgent } from "@waku/core";
import { enrTree, wakuDnsDiscovery } from "@waku/dns-discovery"; import { enrTree, wakuDnsDiscovery } from "@waku/dns-discovery";
import type { import type {
FullNode, FullNode,
@ -22,7 +22,6 @@ import type {
ProtocolCreateOptions, ProtocolCreateOptions,
RelayNode, RelayNode,
} from "@waku/interfaces"; } from "@waku/interfaces";
import { wakuPeerExchange } from "@waku/peer-exchange";
import { createLibp2p, Libp2pOptions } from "libp2p"; import { createLibp2p, Libp2pOptions } from "libp2p";
import type { Libp2pComponents } from "./libp2p_components.js"; import type { Libp2pComponents } from "./libp2p_components.js";
@ -62,15 +61,12 @@ export async function createLightNode(
const lightPush = wakuLightPush(options); const lightPush = wakuLightPush(options);
const filter = wakuFilter(options); const filter = wakuFilter(options);
const peerExchange = wakuPeerExchange();
return new WakuNode( return new WakuNode(
options ?? {}, options ?? {},
libp2p, libp2p,
store, store,
lightPush, lightPush,
filter, filter
peerExchange
) as LightNode; ) as LightNode;
} }
@ -130,15 +126,12 @@ export async function createFullNode(
const lightPush = wakuLightPush(options); const lightPush = wakuLightPush(options);
const filter = wakuFilter(options); const filter = wakuFilter(options);
const peerExchange = wakuPeerExchange();
return new WakuNode( return new WakuNode(
options ?? {}, options ?? {},
libp2p, libp2p,
store, store,
lightPush, lightPush,
filter, filter
peerExchange
) as FullNode; ) as FullNode;
} }

View File

@ -9,7 +9,6 @@ export enum Protocols {
Store = "store", Store = "store",
LightPush = "lightpush", LightPush = "lightpush",
Filter = "filter", Filter = "filter",
PeerExchange = "peer-exchange",
} }
export interface PointToPointProtocol { export interface PointToPointProtocol {

View File

@ -5,7 +5,6 @@ import type { Multiaddr } from "@multiformats/multiaddr";
import type { IFilter } from "./filter.js"; import type { IFilter } from "./filter.js";
import type { ILightPush } from "./light_push.js"; import type { ILightPush } from "./light_push.js";
import type { IPeerExchange } from "./peer_exchange.js";
import { Protocols } from "./protocols.js"; import { Protocols } from "./protocols.js";
import type { IRelay } from "./relay.js"; import type { IRelay } from "./relay.js";
import type { IStore } from "./store.js"; import type { IStore } from "./store.js";
@ -16,7 +15,6 @@ export interface Waku {
store?: IStore; store?: IStore;
filter?: IFilter; filter?: IFilter;
lightPush?: ILightPush; lightPush?: ILightPush;
peerExchange?: IPeerExchange;
dial(peer: PeerId | Multiaddr, protocols?: Protocols[]): Promise<Stream>; dial(peer: PeerId | Multiaddr, protocols?: Protocols[]): Promise<Stream>;
@ -32,7 +30,6 @@ export interface LightNode extends Waku {
store: IStore; store: IStore;
filter: IFilter; filter: IFilter;
lightPush: ILightPush; lightPush: ILightPush;
peerExchange: IPeerExchange;
} }
export interface RelayNode extends Waku { export interface RelayNode extends Waku {
@ -40,7 +37,6 @@ export interface RelayNode extends Waku {
store: undefined; store: undefined;
filter: undefined; filter: undefined;
lightPush: undefined; lightPush: undefined;
peerExchange: undefined;
} }
export interface FullNode extends Waku { export interface FullNode extends Waku {
@ -48,5 +44,4 @@ export interface FullNode extends Waku {
store: IStore; store: IStore;
filter: IFilter; filter: IFilter;
lightPush: ILightPush; lightPush: ILightPush;
peerExchange: IPeerExchange;
} }

View File

@ -7,4 +7,5 @@ export {
wakuPeerExchangeDiscovery, wakuPeerExchangeDiscovery,
PeerExchangeDiscovery, PeerExchangeDiscovery,
Options, Options,
DEFAULT_PEER_EXCHANGE_TAG_NAME,
} from "./waku_peer_exchange_discovery.js"; } from "./waku_peer_exchange_discovery.js";

View File

@ -48,9 +48,9 @@ export interface Options {
maxRetries?: number; maxRetries?: number;
} }
const DEFAULT_BOOTSTRAP_TAG_NAME = "peer-exchange"; export const DEFAULT_PEER_EXCHANGE_TAG_NAME = "peer-exchange";
const DEFAULT_BOOTSTRAP_TAG_VALUE = 50; const DEFAULT_PEER_EXCHANGE_BOOTSTRAP_TAG_VALUE = 50;
const DEFAULT_BOOTSTRAP_TAG_TTL = 120000; const DEFAULT_PEER_EXCHANGE_BOOTSTRAP_TAG_TTL = 120000;
export class PeerExchangeDiscovery export class PeerExchangeDiscovery
extends EventEmitter<PeerDiscoveryEvents> extends EventEmitter<PeerDiscoveryEvents>
@ -174,17 +174,20 @@ export class PeerExchangeDiscovery
if ( if (
(await this.components.peerStore.getTags(peerId)).find( (await this.components.peerStore.getTags(peerId)).find(
({ name }) => name === DEFAULT_BOOTSTRAP_TAG_NAME ({ name }) => name === DEFAULT_PEER_EXCHANGE_TAG_NAME
) )
) )
continue; continue;
await this.components.peerStore.tagPeer( await this.components.peerStore.tagPeer(
peerId, peerId,
DEFAULT_BOOTSTRAP_TAG_NAME, DEFAULT_PEER_EXCHANGE_TAG_NAME,
{ {
value: this.options.tagValue ?? DEFAULT_BOOTSTRAP_TAG_VALUE, value:
ttl: this.options.tagTTL ?? DEFAULT_BOOTSTRAP_TAG_TTL, this.options.tagValue ??
DEFAULT_PEER_EXCHANGE_BOOTSTRAP_TAG_VALUE,
ttl:
this.options.tagTTL ?? DEFAULT_PEER_EXCHANGE_BOOTSTRAP_TAG_TTL,
} }
); );

View File

@ -1,16 +1,17 @@
import { bootstrap } from "@libp2p/bootstrap"; import { bootstrap } from "@libp2p/bootstrap";
import { waitForRemotePeer } from "@waku/core";
import { import {
Fleet, Fleet,
getPredefinedBootstrapNodes, getPredefinedBootstrapNodes,
} from "@waku/core/lib/predefined_bootstrap_nodes"; } from "@waku/core/lib/predefined_bootstrap_nodes";
import { createLightNode } from "@waku/create"; import { createLightNode } from "@waku/create";
import type { LightNode, PeerExchangeResponse } from "@waku/interfaces"; import type { LightNode, PeerExchangeResponse } from "@waku/interfaces";
import { Protocols } from "@waku/interfaces"; import {
import { wakuPeerExchangeDiscovery } from "@waku/peer-exchange"; PeerExchangeCodec,
WakuPeerExchange,
wakuPeerExchangeDiscovery,
} from "@waku/peer-exchange";
import { expect } from "chai"; import { expect } from "chai";
import { delay } from "../src/delay.js";
import { makeLogFileName } from "../src/log_file.js"; import { makeLogFileName } from "../src/log_file.js";
import { Nwaku } from "../src/nwaku.js"; import { Nwaku } from "../src/nwaku.js";
@ -29,62 +30,34 @@ describe("Peer Exchange", () => {
!!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e)); !!waku && waku.stop().catch((e) => console.log("Waku failed to stop", e));
}); });
it("Auto discovery", async function () { it.only("Auto discovery", async function () {
this.timeout(60_000); this.timeout(60_000);
waku = await createLightNode({ waku = await createLightNode({
libp2p: { libp2p: {
peerDiscovery: [ peerDiscovery: [
bootstrap({ list: getPredefinedBootstrapNodes(Fleet.Test) }), bootstrap({ list: getPredefinedBootstrapNodes(Fleet.Test, 3) }),
wakuPeerExchangeDiscovery(), wakuPeerExchangeDiscovery(),
], ],
}, },
}); });
await waku.start(); await waku.start();
// we want to ensure that there is enough time for discv5 to discover peers
await delay(40000);
await waitForRemotePeer(waku, [Protocols.PeerExchange]); const foundPxPeer = await new Promise<boolean>((resolve) => {
const pxPeers = await waku.peerExchange.peers(); const testNodes = getPredefinedBootstrapNodes(Fleet.Test, 3);
expect(pxPeers.length).to.be.greaterThan(0); waku.libp2p.addEventListener("peer:discovery", (evt) => {
}); const { multiaddrs } = evt.detail;
multiaddrs.forEach((ma) => {
it("Manual query on test fleet", async function () { const isBootstrapNode = testNodes.find((n) => n === ma.toString());
this.timeout(60_000); if (!isBootstrapNode) {
resolve(true);
const waku = await createLightNode({ }
libp2p: { });
peerDiscovery: [ });
bootstrap({ list: getPredefinedBootstrapNodes(Fleet.Test) }),
],
},
}); });
await waku.start(); expect(foundPxPeer).to.be.true;
await waitForRemotePeer(waku, [Protocols.PeerExchange]);
let receivedCallback = false;
const numPeersToRequest = 3;
const callback = (response: PeerExchangeResponse): void => {
receivedCallback = true;
expect(response.peerInfos.length).to.be.greaterThan(0);
expect(response.peerInfos.length).to.be.lessThanOrEqual(
numPeersToRequest
);
expect(response.peerInfos[0].ENR).to.not.be.null;
};
await waku.peerExchange.query(
{
numPeers: numPeersToRequest,
},
callback
);
expect(receivedCallback).to.be.true;
}); });
describe("Locally run nodes", () => { describe("Locally run nodes", () => {
@ -124,11 +97,28 @@ describe("Peer Exchange", () => {
waku = await createLightNode(); waku = await createLightNode();
await waku.start(); await waku.start();
await waku.dial(nwaku2Ma); await waku.libp2p.dialProtocol(nwaku2Ma, PeerExchangeCodec);
await waitForRemotePeer(waku, [Protocols.PeerExchange]); await new Promise<void>((resolve) => {
waku.libp2p.peerStore.addEventListener("change:protocols", (evt) => {
if (evt.detail.protocols.includes(PeerExchangeCodec)) {
resolve();
}
});
});
await nwaku2.waitForLog("Discovered px peers via discv5", 1); await nwaku2.waitForLog("Discovered px peers via discv5", 10);
// the ts-ignores are added ref: https://github.com/libp2p/js-libp2p-interfaces/issues/338#issuecomment-1431643645
const peerExchange = new WakuPeerExchange({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
connectionManager: waku.libp2p.connectionManager,
peerStore: waku.libp2p.peerStore,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
registrar: waku.libp2p.registrar,
});
let receivedCallback = false; let receivedCallback = false;
@ -156,7 +146,7 @@ describe("Peer Exchange", () => {
receivedCallback = true; receivedCallback = true;
}; };
await waku.peerExchange.query( await peerExchange.query(
{ {
numPeers: numPeersToRequest, numPeers: numPeersToRequest,
}, },