add: peerId to ping and unsubscribeAll

This commit is contained in:
danisharora099 2023-05-02 18:08:10 +05:30
parent c5a9f19a84
commit d0090e8a0c
No known key found for this signature in database
GPG Key ID: FBD2BF500037F135
3 changed files with 11 additions and 8 deletions

View File

@ -1,4 +1,5 @@
import type { Libp2p } from "@libp2p/interface-libp2p";
import { PeerId } from "@libp2p/interface-peer-id";
import type { Peer } from "@libp2p/interface-peer-store";
import { IncomingStreamData } from "@libp2p/interface-registrar";
import type {
@ -143,12 +144,12 @@ class FilterV2 extends BaseProtocol implements IFilterV2 {
};
}
public async unsubscribeAll(): Promise<void> {
public async unsubscribeAll(peerId: PeerId): Promise<void> {
const { pubSubTopic = DefaultPubSubTopic } = this.options;
const request = FilterSubscribeRpc.createUnsubscribeAllRequest(pubSubTopic);
const peer = await this.getPeer();
const peer = await this.getPeer(peerId);
const stream = await this.newStream(peer);
try {
@ -177,12 +178,12 @@ class FilterV2 extends BaseProtocol implements IFilterV2 {
}
}
public async ping(): Promise<void> {
public async ping(peerId: PeerId): Promise<void> {
const { pubSubTopic = DefaultPubSubTopic } = this.options;
const request = FilterSubscribeRpc.createSubscriberPingRequest(pubSubTopic);
const peer = await this.getPeer();
const peer = await this.getPeer(peerId);
const stream = await this.newStream(peer);
try {

View File

@ -1,3 +1,5 @@
import { PeerId } from "@libp2p/interface-peer-id";
import type { IDecodedMessage, IDecoder } from "./message.js";
import type { Callback, ProtocolOptions } from "./protocols.js";
@ -17,6 +19,6 @@ export interface IReceiverV1 {
}
export interface IReceiverV2 extends IReceiverV1 {
ping: () => Promise<void>;
unsubscribeAll: () => Promise<void>;
ping: (peerId: PeerId) => Promise<void>;
unsubscribeAll: (peerId: PeerId) => Promise<void>;
}

View File

@ -172,14 +172,14 @@ describe("Waku Filter: V2", () => {
const callback = (): void => {
messageCount++;
};
await waku.filter.subscribe([TestDecoder], callback);
const peerId = await waku.filter.subscribe([TestDecoder], callback);
await delay(200);
await waku.lightPush.send(TestEncoder, {
payload: utf8ToBytes("This should be received"),
});
await delay(100);
await waku.filter.ping();
await waku.filter.ping(peerId);
await waku.lightPush.send(TestEncoder, {
payload: utf8ToBytes("This should be received"),
});