fix: replace deprecated wss filter

This commit is contained in:
Arseniy Klempner 2025-07-14 15:28:31 -07:00
parent 35acdf8fa5
commit f7ad76fc1b
No known key found for this signature in database
GPG Key ID: 51653F18863BD24B
2 changed files with 31 additions and 9 deletions

View File

@ -1,10 +1,10 @@
import { noise } from "@chainsafe/libp2p-noise";
import { bootstrap } from "@libp2p/bootstrap";
import { identify } from "@libp2p/identify";
import type { ConnectionGater } from "@libp2p/interface";
import { mplex } from "@libp2p/mplex";
import { ping } from "@libp2p/ping";
import { webSockets } from "@libp2p/websockets";
import { all as filterAll, wss } from "@libp2p/websockets/filters";
import { wakuMetadata } from "@waku/core";
import {
type CreateLibp2pOptions,
@ -53,16 +53,22 @@ export async function defaultLibp2p(
? { metadata: wakuMetadata(pubsubTopics) }
: {};
const filter =
options?.filterMultiaddrs === false || isTestEnvironment()
? filterAll
: wss;
const connectionGater: ConnectionGater = {
denyDialMultiaddr: async (multiaddr) => {
if (options?.filterMultiaddrs === false || isTestEnvironment()) {
return false;
}
const protocols = multiaddr.protos().map((proto) => proto.name);
return protocols.includes("ws") && !protocols.includes("wss");
}
};
return createLibp2p({
transports: [webSockets({ filter: filter })],
transports: [webSockets()],
streamMuxers: [mplex()],
connectionEncrypters: [noise()],
...options,
connectionGater,
services: {
identify: identify({
agentVersion: userAgent ?? DefaultUserAgent

View File

@ -4,6 +4,7 @@ import {
type Stream,
TypedEventEmitter
} from "@libp2p/interface";
import { peerIdFromString } from "@libp2p/peer-id";
import type { MultiaddrInput } from "@multiformats/multiaddr";
import { ConnectionManager, createDecoder, createEncoder } from "@waku/core";
import type {
@ -88,8 +89,8 @@ export class WakuNode implements IWaku {
this.connectionManager = new ConnectionManager({
libp2p,
relay: this.relay,
events: this.events,
relay: this.relay,
pubsubTopics: pubsubTopics,
networkConfig: this.networkConfig,
config: options?.connectionManager
@ -213,7 +214,22 @@ export class WakuNode implements IWaku {
public async hangUp(peer: PeerId | MultiaddrInput): Promise<boolean> {
log.info(`Hanging up peer:${peer?.toString()}.`);
return this.connectionManager.hangUp(peer);
let peerId: PeerId;
if (typeof peer === "string") {
peerId = peerIdFromString(peer);
} else if (peer && "getPeerId" in peer) {
// MultiaddrInput case
const peerIdStr = peer.getPeerId?.();
if (!peerIdStr) {
throw new Error("No peer ID in multiaddr");
}
peerId = peerIdFromString(peerIdStr);
} else {
// PeerId case
peerId = peer as PeerId;
}
return await this.connectionManager.hangUp(peerId);
}
public async start(): Promise<void> {
@ -222,7 +238,7 @@ export class WakuNode implements IWaku {
this._nodeStateLock = true;
await this.libp2p.start();
this.connectionManager.start();
// Connection manager starts automatically
this.peerManager.start();
this.healthIndicator.start();
this.lightPush?.start();