Skip to content

Commit f7ad76f

Browse files
committed
fix: replace deprecated wss filter
1 parent 35acdf8 commit f7ad76f

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

packages/sdk/src/create/libp2p.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { noise } from "@chainsafe/libp2p-noise";
22
import { bootstrap } from "@libp2p/bootstrap";
33
import { identify } from "@libp2p/identify";
4+
import type { ConnectionGater } from "@libp2p/interface";
45
import { mplex } from "@libp2p/mplex";
56
import { ping } from "@libp2p/ping";
67
import { webSockets } from "@libp2p/websockets";
7-
import { all as filterAll, wss } from "@libp2p/websockets/filters";
88
import { wakuMetadata } from "@waku/core";
99
import {
1010
type CreateLibp2pOptions,
@@ -53,16 +53,22 @@ export async function defaultLibp2p(
5353
? { metadata: wakuMetadata(pubsubTopics) }
5454
: {};
5555

56-
const filter =
57-
options?.filterMultiaddrs === false || isTestEnvironment()
58-
? filterAll
59-
: wss;
56+
const connectionGater: ConnectionGater = {
57+
denyDialMultiaddr: async (multiaddr) => {
58+
if (options?.filterMultiaddrs === false || isTestEnvironment()) {
59+
return false;
60+
}
61+
const protocols = multiaddr.protos().map((proto) => proto.name);
62+
return protocols.includes("ws") && !protocols.includes("wss");
63+
}
64+
};
6065

6166
return createLibp2p({
62-
transports: [webSockets({ filter: filter })],
67+
transports: [webSockets()],
6368
streamMuxers: [mplex()],
6469
connectionEncrypters: [noise()],
6570
...options,
71+
connectionGater,
6672
services: {
6773
identify: identify({
6874
agentVersion: userAgent ?? DefaultUserAgent

packages/sdk/src/waku/waku.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
type Stream,
55
TypedEventEmitter
66
} from "@libp2p/interface";
7+
import { peerIdFromString } from "@libp2p/peer-id";
78
import type { MultiaddrInput } from "@multiformats/multiaddr";
89
import { ConnectionManager, createDecoder, createEncoder } from "@waku/core";
910
import type {
@@ -88,8 +89,8 @@ export class WakuNode implements IWaku {
8889

8990
this.connectionManager = new ConnectionManager({
9091
libp2p,
91-
relay: this.relay,
9292
events: this.events,
93+
relay: this.relay,
9394
pubsubTopics: pubsubTopics,
9495
networkConfig: this.networkConfig,
9596
config: options?.connectionManager
@@ -213,7 +214,22 @@ export class WakuNode implements IWaku {
213214
public async hangUp(peer: PeerId | MultiaddrInput): Promise<boolean> {
214215
log.info(`Hanging up peer:${peer?.toString()}.`);
215216

216-
return this.connectionManager.hangUp(peer);
217+
let peerId: PeerId;
218+
if (typeof peer === "string") {
219+
peerId = peerIdFromString(peer);
220+
} else if (peer && "getPeerId" in peer) {
221+
// MultiaddrInput case
222+
const peerIdStr = peer.getPeerId?.();
223+
if (!peerIdStr) {
224+
throw new Error("No peer ID in multiaddr");
225+
}
226+
peerId = peerIdFromString(peerIdStr);
227+
} else {
228+
// PeerId case
229+
peerId = peer as PeerId;
230+
}
231+
232+
return await this.connectionManager.hangUp(peerId);
217233
}
218234

219235
public async start(): Promise<void> {
@@ -222,7 +238,7 @@ export class WakuNode implements IWaku {
222238
this._nodeStateLock = true;
223239

224240
await this.libp2p.start();
225-
this.connectionManager.start();
241+
// Connection manager starts automatically
226242
this.peerManager.start();
227243
this.healthIndicator.start();
228244
this.lightPush?.start();

0 commit comments

Comments
 (0)