Merge 1361cf57e1139c44f0d9aa427e79c10fccbfdb20 into f2ad23ad4354fb3440ca369ed91ba4d882bbacf6

This commit is contained in:
Sasha 2025-12-02 13:39:45 +02:00 committed by GitHub
commit f130857d4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 22 deletions

View File

@ -1,5 +1,4 @@
import type { PeerId } from "@libp2p/interface";
import type { IncomingStreamData } from "@libp2p/interface-internal";
import type { PeerId, StreamHandler } from "@libp2p/interface";
import {
type ContentTopic,
type FilterCoreResult,
@ -52,7 +51,7 @@ export class FilterCore {
public async start(): Promise<void> {
try {
await this.libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this), {
await this.libp2p.handle(FilterCodecs.PUSH, this.onRequest, {
maxInboundStreams: 100
});
} catch (e) {
@ -305,7 +304,7 @@ export class FilterCore {
};
}
private onRequest(streamData: IncomingStreamData): void {
private onRequest: StreamHandler = (streamData) => {
const { connection, stream } = streamData;
const { remotePeer } = connection;
log.info(`Received message from ${remotePeer.toString()}`);
@ -346,5 +345,5 @@ export class FilterCore {
} catch (e) {
log.error("Error decoding message", e);
}
}
};
}

View File

@ -38,7 +38,7 @@ describe("StreamManager", () => {
createMockStream({ id: "1", protocol: MULTICODEC, writeStatus })
];
streamManager["libp2p"]["connectionManager"]["getConnections"] = (
(streamManager["libp2p"]["connectionManager"] as any).getConnections = (
_peerId: PeerId | undefined
) => [con1];
@ -50,7 +50,7 @@ describe("StreamManager", () => {
});
it("should return undefined if no connection provided", async () => {
streamManager["libp2p"]["connectionManager"]["getConnections"] = (
(streamManager["libp2p"]["connectionManager"] as any).getConnections = (
_peerId: PeerId | undefined
) => [];
@ -74,7 +74,7 @@ describe("StreamManager", () => {
);
con1.newStream = newStreamSpy;
streamManager["libp2p"]["connectionManager"]["getConnections"] = (
(streamManager["libp2p"]["connectionManager"] as any).getConnections = (
_peerId: PeerId | undefined
) => [con1];
@ -101,7 +101,7 @@ describe("StreamManager", () => {
);
con1.newStream = newStreamSpy;
streamManager["libp2p"]["connectionManager"]["getConnections"] = (
(streamManager["libp2p"]["connectionManager"] as any).getConnections = (
_peerId: PeerId | undefined
) => [con1];
@ -152,7 +152,7 @@ describe("StreamManager", () => {
writeStatus: "writable"
})
];
streamManager["libp2p"]["connectionManager"]["getConnections"] = (
(streamManager["libp2p"]["connectionManager"] as any).getConnections = (
_id: PeerId | undefined
) => [con1];
@ -182,7 +182,6 @@ function createMockConnection(options: MockConnectionOptions = {}): Connection {
}
} as Connection;
}
type MockStreamOptions = {
id?: string;
protocol?: string;

View File

@ -25,10 +25,12 @@ export type CreateEncoderParams = CreateDecoderParams & {
ephemeral?: boolean;
};
export enum WakuEvent {
Connection = "waku:connection",
Health = "waku:health"
}
export const WakuEvent = {
Connection: "waku:connection",
Health: "waku:health"
} as const;
export type WakuEvent = (typeof WakuEvent)[keyof typeof WakuEvent];
export interface IWakuEvents {
/**
@ -36,22 +38,22 @@ export interface IWakuEvents {
*
* @example
* ```typescript
* waku.addEventListener(WakuEvent.Connection, (event) => {
* waku.events.addEventListener("waku:connection", (event) => {
* console.log(event.detail); // true if connected, false if disconnected
* });
*/
[WakuEvent.Connection]: CustomEvent<boolean>;
"waku:connection": CustomEvent<boolean>;
/**
* Emitted when the health status changes.
*
* @example
* ```typescript
* waku.addEventListener(WakuEvent.Health, (event) => {
* waku.events.addEventListener("waku:health", (event) => {
* console.log(event.detail); // 'Unhealthy', 'MinimallyHealthy', or 'SufficientlyHealthy'
* });
*/
[WakuEvent.Health]: CustomEvent<HealthStatus>;
"waku:health": CustomEvent<HealthStatus>;
}
export type IWakuEventEmitter = TypedEventEmitter<IWakuEvents>;
@ -66,12 +68,12 @@ export interface IWaku {
/**
* Emits events related to the Waku node.
* Those are:
* - WakuEvent.Connection
* - WakuEvent.Health
* - "waku:connection"
* - "waku:health"
*
* @example
* ```typescript
* waku.events.addEventListener(WakuEvent.Connection, (event) => {
* waku.events.addEventListener("waku:connection", (event) => {
* console.log(event.detail); // true if connected, false if disconnected
* });
* ```