Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 54 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions packages/core/src/lib/wait_for_remote_peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
27 changes: 2 additions & 25 deletions packages/core/src/lib/waku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<typeof setInterval>;
Expand All @@ -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;

Expand All @@ -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;
}
Expand All @@ -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 = {};
Expand Down Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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);
Expand Down
Loading