mirror of https://github.com/waku-org/js-waku.git
chore: remove `@waku/peer-exchange` dependency
As per its name, `@waku/core` aims to contain, and only contains, the minimal set of core functionalities needed for a developer to use Waku in their webapp. Hence, `@waku/core` should avoid depending on other Waku packages. If a developer wishes to use functionality from other packages, they should explicitly import such packages.
This commit is contained in:
parent
a5ff788eed
commit
372ff6454f
|
@ -26317,7 +26317,6 @@
|
|||
"@waku/byte-utils": "*",
|
||||
"@waku/interfaces": "*",
|
||||
"@waku/libp2p-utils": "*",
|
||||
"@waku/peer-exchange": "*",
|
||||
"@waku/proto": "*",
|
||||
"debug": "^4.3.4",
|
||||
"it-all": "^1.0.6",
|
||||
|
@ -29834,7 +29833,6 @@
|
|||
"@waku/byte-utils": "*",
|
||||
"@waku/interfaces": "*",
|
||||
"@waku/libp2p-utils": "*",
|
||||
"@waku/peer-exchange": "*",
|
||||
"@waku/proto": "*",
|
||||
"app-root-path": "^3.0.0",
|
||||
"chai": "^4.3.4",
|
||||
|
|
|
@ -91,7 +91,6 @@
|
|||
"@waku/byte-utils": "*",
|
||||
"@waku/interfaces": "*",
|
||||
"@waku/libp2p-utils": "*",
|
||||
"@waku/peer-exchange": "*",
|
||||
"@waku/proto": "*",
|
||||
"debug": "^4.3.4",
|
||||
"it-all": "^1.0.6",
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
import { PeerProtocolsChangeData } from "@libp2p/interface-peer-store";
|
||||
import type { IRelay, PointToPointProtocol, Waku } from "@waku/interfaces";
|
||||
import { Protocols } from "@waku/interfaces";
|
||||
import { PeerExchangeCodec } from "@waku/peer-exchange";
|
||||
import debug from "debug";
|
||||
import { pEvent } from "p-event";
|
||||
|
||||
import { FilterCodec } from "./filter/index.js";
|
||||
import { LightPushCodec } from "./light_push/index.js";
|
||||
import { StoreCodec } from "./store/index.js";
|
||||
|
||||
const log = debug("waku:wait-for-remote-peer");
|
||||
|
||||
/**
|
||||
|
@ -50,19 +45,19 @@ export async function waitForRemotePeer(
|
|||
if (protocols.includes(Protocols.Store)) {
|
||||
if (!waku.store)
|
||||
throw new Error("Cannot wait for Store peer: protocol not mounted");
|
||||
promises.push(waitForConnectedPeer(waku.store, [StoreCodec]));
|
||||
promises.push(waitForConnectedPeer(waku.store));
|
||||
}
|
||||
|
||||
if (protocols.includes(Protocols.LightPush)) {
|
||||
if (!waku.lightPush)
|
||||
throw new Error("Cannot wait for LightPush peer: protocol not mounted");
|
||||
promises.push(waitForConnectedPeer(waku.lightPush, [LightPushCodec]));
|
||||
promises.push(waitForConnectedPeer(waku.lightPush));
|
||||
}
|
||||
|
||||
if (protocols.includes(Protocols.Filter)) {
|
||||
if (!waku.filter)
|
||||
throw new Error("Cannot wait for Filter peer: protocol not mounted");
|
||||
promises.push(waitForConnectedPeer(waku.filter, [FilterCodec]));
|
||||
promises.push(waitForConnectedPeer(waku.filter));
|
||||
}
|
||||
|
||||
if (protocols.includes(Protocols.PeerExchange)) {
|
||||
|
@ -70,7 +65,7 @@ export async function waitForRemotePeer(
|
|||
throw new Error(
|
||||
"Cannot wait for Peer Exchange peer: protocol not mounted"
|
||||
);
|
||||
promises.push(waitForConnectedPeer(waku.peerExchange, [PeerExchangeCodec]));
|
||||
promises.push(waitForConnectedPeer(waku.peerExchange));
|
||||
}
|
||||
|
||||
if (timeoutMs) {
|
||||
|
@ -88,28 +83,25 @@ export async function waitForRemotePeer(
|
|||
* Wait for a peer with the given protocol to be connected.
|
||||
*/
|
||||
async function waitForConnectedPeer(
|
||||
waku: PointToPointProtocol,
|
||||
codecs: string[]
|
||||
protocol: PointToPointProtocol
|
||||
): Promise<void> {
|
||||
const peers = await waku.peers();
|
||||
const codec = protocol.multicodec;
|
||||
const peers = await protocol.peers();
|
||||
|
||||
if (peers.length) {
|
||||
log(`${codecs} peer found: `, peers[0].id.toString());
|
||||
log(`${codec} peer found: `, peers[0].id.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
await new Promise<void>((resolve) => {
|
||||
const cb = (evt: CustomEvent<PeerProtocolsChangeData>): void => {
|
||||
for (const codec of codecs) {
|
||||
if (evt.detail.protocols.includes(codec)) {
|
||||
log("Resolving for", codec, evt.detail.protocols);
|
||||
waku.peerStore.removeEventListener("change:protocols", cb);
|
||||
protocol.peerStore.removeEventListener("change:protocols", cb);
|
||||
resolve();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
waku.peerStore.addEventListener("change:protocols", cb);
|
||||
protocol.peerStore.addEventListener("change:protocols", cb);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -12,16 +12,15 @@ import type {
|
|||
Waku,
|
||||
} from "@waku/interfaces";
|
||||
import { Protocols } from "@waku/interfaces";
|
||||
import { PeerExchangeCodec } from "@waku/peer-exchange";
|
||||
import debug from "debug";
|
||||
import type { Libp2p } from "libp2p";
|
||||
|
||||
import { FilterCodec, FilterComponents } from "./filter/index.js";
|
||||
import { LightPushCodec, LightPushComponents } from "./light_push/index.js";
|
||||
import { FilterComponents } from "./filter/index.js";
|
||||
import { LightPushComponents } from "./light_push/index.js";
|
||||
import { createEncoder } from "./message/version_0.js";
|
||||
import * as relayConstants from "./relay/constants.js";
|
||||
import { RelayCodecs, RelayPingContentTopic } from "./relay/constants.js";
|
||||
import { StoreCodec, StoreComponents } from "./store/index.js";
|
||||
import { RelayPingContentTopic } from "./relay/constants.js";
|
||||
import { StoreComponents } from "./store/index.js";
|
||||
|
||||
export const DefaultPingKeepAliveValueSecs = 0;
|
||||
export const DefaultRelayKeepAliveValueSecs = 5 * 60;
|
||||
|
@ -165,20 +164,50 @@ export class WakuNode implements Waku {
|
|||
|
||||
const codecs: string[] = [];
|
||||
if (_protocols.includes(Protocols.Relay)) {
|
||||
RelayCodecs.forEach((codec) => codecs.push(codec));
|
||||
if (this.relay) {
|
||||
this.relay.multicodecs.forEach((codec) => codecs.push(codec));
|
||||
} else {
|
||||
log(
|
||||
"Relay codec not included in dial codec: protocol not mounted locally"
|
||||
);
|
||||
}
|
||||
}
|
||||
if (_protocols.includes(Protocols.Store)) {
|
||||
codecs.push(StoreCodec);
|
||||
if (this.store) {
|
||||
codecs.push(this.store.multicodec);
|
||||
} else {
|
||||
log(
|
||||
"Store codec not included in dial codec: protocol not mounted locally"
|
||||
);
|
||||
}
|
||||
}
|
||||
if (_protocols.includes(Protocols.LightPush)) {
|
||||
codecs.push(LightPushCodec);
|
||||
if (this.lightPush) {
|
||||
codecs.push(this.lightPush.multicodec);
|
||||
} else {
|
||||
log(
|
||||
"Light Push codec not included in dial codec: protocol not mounted locally"
|
||||
);
|
||||
}
|
||||
}
|
||||
if (_protocols.includes(Protocols.Filter)) {
|
||||
codecs.push(FilterCodec);
|
||||
if (this.filter) {
|
||||
codecs.push(this.filter.multicodec);
|
||||
} else {
|
||||
log(
|
||||
"Filter codec not included in dial codec: protocol not mounted locally"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (_protocols.includes(Protocols.PeerExchange)) {
|
||||
codecs.push(PeerExchangeCodec);
|
||||
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}`);
|
||||
|
|
Loading…
Reference in New Issue