diff --git a/package-lock.json b/package-lock.json index b5b9be952a..295b489d6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26984,32 +26984,36 @@ }, "packages/tests/node_modules/ansi-colors": { "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, - "license": "MIT", "engines": { "node": ">=6" } }, "packages/tests/node_modules/ansi-regex": { "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", "dev": true, - "license": "MIT", "engines": { "node": ">=8" } }, "packages/tests/node_modules/brace-expansion": { "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", "dev": true, - "license": "MIT", "dependencies": { "balanced-match": "^1.0.0" } }, "packages/tests/node_modules/cliui": { "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, - "license": "ISC", "dependencies": { "string-width": "^4.2.0", "strip-ansi": "^6.0.0", @@ -27018,21 +27022,24 @@ }, "packages/tests/node_modules/diff": { "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, - "license": "BSD-3-Clause", "engines": { "node": ">=0.3.1" } }, "packages/tests/node_modules/emoji-regex": { "version": "8.0.0", - "dev": true, - "license": "MIT" + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true }, "packages/tests/node_modules/find-up": { "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, - "license": "MIT", "dependencies": { "locate-path": "^6.0.0", "path-exists": "^4.0.0" @@ -27046,8 +27053,9 @@ }, "packages/tests/node_modules/glob": { "version": "7.2.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", + "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", "dev": true, - "license": "ISC", "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -27065,16 +27073,18 @@ }, "packages/tests/node_modules/is-fullwidth-code-point": { "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, - "license": "MIT", "engines": { "node": ">=8" } }, "packages/tests/node_modules/is-unicode-supported": { "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, - "license": "MIT", "engines": { "node": ">=10" }, @@ -27084,8 +27094,9 @@ }, "packages/tests/node_modules/locate-path": { "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, - "license": "MIT", "dependencies": { "p-locate": "^5.0.0" }, @@ -27098,8 +27109,9 @@ }, "packages/tests/node_modules/log-symbols": { "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, - "license": "MIT", "dependencies": { "chalk": "^4.1.0", "is-unicode-supported": "^0.1.0" @@ -27113,8 +27125,9 @@ }, "packages/tests/node_modules/mocha": { "version": "10.2.0", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.2.0.tgz", + "integrity": "sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg==", "dev": true, - "license": "MIT", "dependencies": { "ansi-colors": "4.1.1", "browser-stdout": "1.3.1", @@ -27152,8 +27165,9 @@ }, "packages/tests/node_modules/mocha/node_modules/minimatch": { "version": "5.0.1", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.0.1.tgz", + "integrity": "sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g==", "dev": true, - "license": "ISC", "dependencies": { "brace-expansion": "^2.0.1" }, @@ -27163,13 +27177,15 @@ }, "packages/tests/node_modules/ms": { "version": "2.1.3", - "dev": true, - "license": "MIT" + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true }, "packages/tests/node_modules/nanoid": { "version": "3.3.3", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.3.tgz", + "integrity": "sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w==", "dev": true, - "license": "MIT", "bin": { "nanoid": "bin/nanoid.cjs" }, @@ -27179,8 +27195,9 @@ }, "packages/tests/node_modules/p-limit": { "version": "3.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", "dev": true, - "license": "MIT", "dependencies": { "yocto-queue": "^0.1.0" }, @@ -27193,8 +27210,9 @@ }, "packages/tests/node_modules/p-locate": { "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, - "license": "MIT", "dependencies": { "p-limit": "^3.0.2" }, @@ -27207,16 +27225,18 @@ }, "packages/tests/node_modules/serialize-javascript": { "version": "6.0.0", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz", + "integrity": "sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==", "dev": true, - "license": "BSD-3-Clause", "dependencies": { "randombytes": "^2.1.0" } }, "packages/tests/node_modules/string-width": { "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, - "license": "MIT", "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -27228,8 +27248,9 @@ }, "packages/tests/node_modules/strip-ansi": { "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", "dev": true, - "license": "MIT", "dependencies": { "ansi-regex": "^5.0.1" }, @@ -27239,8 +27260,9 @@ }, "packages/tests/node_modules/strip-json-comments": { "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, - "license": "MIT", "engines": { "node": ">=8" }, @@ -27250,13 +27272,15 @@ }, "packages/tests/node_modules/workerpool": { "version": "6.2.1", - "dev": true, - "license": "Apache-2.0" + "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.1.tgz", + "integrity": "sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==", + "dev": true }, "packages/tests/node_modules/yargs": { "version": "16.2.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", + "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", "dev": true, - "license": "MIT", "dependencies": { "cliui": "^7.0.2", "escalade": "^3.1.1", @@ -27272,8 +27296,9 @@ }, "packages/tests/node_modules/yargs-parser": { "version": "20.2.4", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.4.tgz", + "integrity": "sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==", "dev": true, - "license": "ISC", "engines": { "node": ">=10" } diff --git a/packages/core/src/lib/wait_for_remote_peer.ts b/packages/core/src/lib/wait_for_remote_peer.ts index 28a40e9de3..af79cd94ca 100644 --- a/packages/core/src/lib/wait_for_remote_peer.ts +++ b/packages/core/src/lib/wait_for_remote_peer.ts @@ -60,14 +60,6 @@ export async function waitForRemotePeer( 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) { await rejectOnTimeout( Promise.all(promises), diff --git a/packages/core/src/lib/waku.ts b/packages/core/src/lib/waku.ts index ec8aa23da1..62eaa11c42 100644 --- a/packages/core/src/lib/waku.ts +++ b/packages/core/src/lib/waku.ts @@ -6,10 +6,8 @@ import type { Multiaddr } from "@multiformats/multiaddr"; import type { IFilter, ILightPush, - IPeerExchange, IRelay, IStore, - PeerExchangeComponents, Waku, } from "@waku/interfaces"; import { Protocols } from "@waku/interfaces"; @@ -53,7 +51,6 @@ export class WakuNode implements Waku { public store?: IStore; public filter?: IFilter; public lightPush?: ILightPush; - public peerExchange?: IPeerExchange; private pingKeepAliveTimers: { [peer: string]: ReturnType; @@ -67,8 +64,7 @@ export class WakuNode implements Waku { libp2p: Libp2p, store?: (libp2p: Libp2p) => IStore, lightPush?: (libp2p: Libp2p) => ILightPush, - filter?: (libp2p: Libp2p) => IFilter, - peerExchange?: (components: PeerExchangeComponents) => IPeerExchange + filter?: (libp2p: Libp2p) => IFilter ) { this.libp2p = libp2p; @@ -82,13 +78,6 @@ export class WakuNode implements Waku { 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)) { this.relay = libp2p.pubsub; } @@ -97,8 +86,7 @@ export class WakuNode implements Waku { "Waku node created", this.libp2p.peerId.toString(), `relay: ${!!this.relay}, store: ${!!this.store}, light push: ${!!this - .lightPush}, filter: ${!!this.filter}, peer exchange: ${!!this - .peerExchange} ` + .lightPush}, filter: ${!!this.filter}} ` ); this.pingKeepAliveTimers = {}; @@ -156,7 +144,6 @@ export class WakuNode implements Waku { this.store && _protocols.push(Protocols.Store); this.filter && _protocols.push(Protocols.Filter); this.lightPush && _protocols.push(Protocols.LightPush); - this.peerExchange && _protocols.push(Protocols.PeerExchange); } 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}`); return this.libp2p.dialProtocol(peer, codecs); diff --git a/packages/create/src/index.ts b/packages/create/src/index.ts index 928b8c2126..51999d6516 100644 --- a/packages/create/src/index.ts +++ b/packages/create/src/index.ts @@ -5,6 +5,7 @@ import { mplex } from "@libp2p/mplex"; import { webSockets } from "@libp2p/websockets"; import { all as filterAll } from "@libp2p/websockets/filters"; import { + DefaultUserAgent, RelayCreateOptions, wakuFilter, wakuLightPush, @@ -13,7 +14,6 @@ import { wakuRelay, wakuStore, } from "@waku/core"; -import { DefaultUserAgent } from "@waku/core"; import { enrTree, wakuDnsDiscovery } from "@waku/dns-discovery"; import type { FullNode, @@ -22,7 +22,6 @@ import type { ProtocolCreateOptions, RelayNode, } from "@waku/interfaces"; -import { wakuPeerExchange } from "@waku/peer-exchange"; import { createLibp2p, Libp2pOptions } from "libp2p"; import type { Libp2pComponents } from "./libp2p_components.js"; @@ -62,15 +61,12 @@ export async function createLightNode( const lightPush = wakuLightPush(options); const filter = wakuFilter(options); - const peerExchange = wakuPeerExchange(); - return new WakuNode( options ?? {}, libp2p, store, lightPush, - filter, - peerExchange + filter ) as LightNode; } @@ -130,15 +126,12 @@ export async function createFullNode( const lightPush = wakuLightPush(options); const filter = wakuFilter(options); - const peerExchange = wakuPeerExchange(); - return new WakuNode( options ?? {}, libp2p, store, lightPush, - filter, - peerExchange + filter ) as FullNode; } diff --git a/packages/interfaces/src/protocols.ts b/packages/interfaces/src/protocols.ts index 6a94872e44..5aa197a0a9 100644 --- a/packages/interfaces/src/protocols.ts +++ b/packages/interfaces/src/protocols.ts @@ -9,7 +9,6 @@ export enum Protocols { Store = "store", LightPush = "lightpush", Filter = "filter", - PeerExchange = "peer-exchange", } export interface PointToPointProtocol { diff --git a/packages/interfaces/src/waku.ts b/packages/interfaces/src/waku.ts index f7bcb89d58..c03652dbd1 100644 --- a/packages/interfaces/src/waku.ts +++ b/packages/interfaces/src/waku.ts @@ -5,7 +5,6 @@ import type { Multiaddr } from "@multiformats/multiaddr"; import type { IFilter } from "./filter.js"; import type { ILightPush } from "./light_push.js"; -import type { IPeerExchange } from "./peer_exchange.js"; import { Protocols } from "./protocols.js"; import type { IRelay } from "./relay.js"; import type { IStore } from "./store.js"; @@ -16,7 +15,6 @@ export interface Waku { store?: IStore; filter?: IFilter; lightPush?: ILightPush; - peerExchange?: IPeerExchange; dial(peer: PeerId | Multiaddr, protocols?: Protocols[]): Promise; @@ -32,7 +30,6 @@ export interface LightNode extends Waku { store: IStore; filter: IFilter; lightPush: ILightPush; - peerExchange: IPeerExchange; } export interface RelayNode extends Waku { @@ -40,7 +37,6 @@ export interface RelayNode extends Waku { store: undefined; filter: undefined; lightPush: undefined; - peerExchange: undefined; } export interface FullNode extends Waku { @@ -48,5 +44,4 @@ export interface FullNode extends Waku { store: IStore; filter: IFilter; lightPush: ILightPush; - peerExchange: IPeerExchange; } diff --git a/packages/peer-exchange/src/index.ts b/packages/peer-exchange/src/index.ts index 7fab198dd1..c06f8db0b7 100644 --- a/packages/peer-exchange/src/index.ts +++ b/packages/peer-exchange/src/index.ts @@ -7,4 +7,5 @@ export { wakuPeerExchangeDiscovery, PeerExchangeDiscovery, Options, + DEFAULT_PEER_EXCHANGE_TAG_NAME, } from "./waku_peer_exchange_discovery.js"; diff --git a/packages/peer-exchange/src/waku_peer_exchange_discovery.ts b/packages/peer-exchange/src/waku_peer_exchange_discovery.ts index 63967a66b9..9fc63e5793 100644 --- a/packages/peer-exchange/src/waku_peer_exchange_discovery.ts +++ b/packages/peer-exchange/src/waku_peer_exchange_discovery.ts @@ -48,9 +48,9 @@ export interface Options { maxRetries?: number; } -const DEFAULT_BOOTSTRAP_TAG_NAME = "peer-exchange"; -const DEFAULT_BOOTSTRAP_TAG_VALUE = 50; -const DEFAULT_BOOTSTRAP_TAG_TTL = 120000; +export const DEFAULT_PEER_EXCHANGE_TAG_NAME = "peer-exchange"; +const DEFAULT_PEER_EXCHANGE_BOOTSTRAP_TAG_VALUE = 50; +const DEFAULT_PEER_EXCHANGE_BOOTSTRAP_TAG_TTL = 120000; export class PeerExchangeDiscovery extends EventEmitter @@ -174,17 +174,20 @@ export class PeerExchangeDiscovery if ( (await this.components.peerStore.getTags(peerId)).find( - ({ name }) => name === DEFAULT_BOOTSTRAP_TAG_NAME + ({ name }) => name === DEFAULT_PEER_EXCHANGE_TAG_NAME ) ) continue; await this.components.peerStore.tagPeer( peerId, - DEFAULT_BOOTSTRAP_TAG_NAME, + DEFAULT_PEER_EXCHANGE_TAG_NAME, { - value: this.options.tagValue ?? DEFAULT_BOOTSTRAP_TAG_VALUE, - ttl: this.options.tagTTL ?? DEFAULT_BOOTSTRAP_TAG_TTL, + value: + this.options.tagValue ?? + DEFAULT_PEER_EXCHANGE_BOOTSTRAP_TAG_VALUE, + ttl: + this.options.tagTTL ?? DEFAULT_PEER_EXCHANGE_BOOTSTRAP_TAG_TTL, } ); diff --git a/packages/tests/tests/peer_exchange.node.spec.ts b/packages/tests/tests/peer_exchange.node.spec.ts index 10e0f5f0aa..9106a17133 100644 --- a/packages/tests/tests/peer_exchange.node.spec.ts +++ b/packages/tests/tests/peer_exchange.node.spec.ts @@ -1,16 +1,17 @@ import { bootstrap } from "@libp2p/bootstrap"; -import { waitForRemotePeer } from "@waku/core"; import { Fleet, getPredefinedBootstrapNodes, } from "@waku/core/lib/predefined_bootstrap_nodes"; import { createLightNode } from "@waku/create"; import type { LightNode, PeerExchangeResponse } from "@waku/interfaces"; -import { Protocols } from "@waku/interfaces"; -import { wakuPeerExchangeDiscovery } from "@waku/peer-exchange"; +import { + PeerExchangeCodec, + WakuPeerExchange, + wakuPeerExchangeDiscovery, +} from "@waku/peer-exchange"; import { expect } from "chai"; -import { delay } from "../src/delay.js"; import { makeLogFileName } from "../src/log_file.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)); }); - it("Auto discovery", async function () { + it.only("Auto discovery", async function () { this.timeout(60_000); waku = await createLightNode({ libp2p: { peerDiscovery: [ - bootstrap({ list: getPredefinedBootstrapNodes(Fleet.Test) }), + bootstrap({ list: getPredefinedBootstrapNodes(Fleet.Test, 3) }), wakuPeerExchangeDiscovery(), ], }, }); 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 pxPeers = await waku.peerExchange.peers(); - expect(pxPeers.length).to.be.greaterThan(0); - }); - - it("Manual query on test fleet", async function () { - this.timeout(60_000); - - const waku = await createLightNode({ - libp2p: { - peerDiscovery: [ - bootstrap({ list: getPredefinedBootstrapNodes(Fleet.Test) }), - ], - }, + const foundPxPeer = await new Promise((resolve) => { + const testNodes = getPredefinedBootstrapNodes(Fleet.Test, 3); + waku.libp2p.addEventListener("peer:discovery", (evt) => { + const { multiaddrs } = evt.detail; + multiaddrs.forEach((ma) => { + const isBootstrapNode = testNodes.find((n) => n === ma.toString()); + if (!isBootstrapNode) { + resolve(true); + } + }); + }); }); - await waku.start(); - - 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; + expect(foundPxPeer).to.be.true; }); describe("Locally run nodes", () => { @@ -124,11 +97,28 @@ describe("Peer Exchange", () => { waku = await createLightNode(); await waku.start(); - await waku.dial(nwaku2Ma); + await waku.libp2p.dialProtocol(nwaku2Ma, PeerExchangeCodec); - await waitForRemotePeer(waku, [Protocols.PeerExchange]); + await new Promise((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; @@ -156,7 +146,7 @@ describe("Peer Exchange", () => { receivedCallback = true; }; - await waku.peerExchange.query( + await peerExchange.query( { numPeers: numPeersToRequest, },