fix: build

This commit is contained in:
Danish Arora 2024-09-24 11:27:15 +05:30
parent 3384b875a9
commit 557ee96b52
No known key found for this signature in database
GPG Key ID: 1C6EF37CDAE1426E
4 changed files with 20 additions and 17 deletions

View File

@ -8,6 +8,7 @@ import type {
import { Logger, pubsubTopicsToShardInfo } from "@waku/utils";
import {
getConnectedPeersForProtocolAndShard,
getPeersForProtocol,
sortPeersByLatency
} from "@waku/utils/libp2p";
@ -25,7 +26,7 @@ export class BaseProtocol implements IBaseProtocolCore {
protected constructor(
public multicodec: string,
private components: Libp2pComponents,
protected components: Libp2pComponents,
private log: Logger,
public readonly pubsubTopics: PubsubTopic[]
) {
@ -55,21 +56,21 @@ export class BaseProtocol implements IBaseProtocolCore {
* the class protocol. Waku may or may not be currently connected to these
* peers.
*/
// public async allPeers(): Promise<Peer[]> {
// return getPeersForProtocol(this.peerStore, [this.multicodec]);
// }
public async allPeers(): Promise<Peer[]> {
return getPeersForProtocol(this.components.peerStore, [this.multicodec]);
}
// public async connectedPeers(): Promise<Peer[]> {
// const peers = await this.allPeers();
// return peers.filter((peer) => {
// const connections = this.components.connectionManager.getConnections(
// peer.id
// );
// return connections.some((c) =>
// c.streams.some((s) => s.protocol === this.multicodec)
// );
// });
// }
public async connectedPeers(): Promise<Peer[]> {
const peers = await this.allPeers();
return peers.filter((peer) => {
const connections = this.components.connectionManager.getConnections(
peer.id
);
return connections.some((c) =>
c.streams.some((s) => s.protocol === this.multicodec)
);
});
}
/**
* Retrieves a list of connected peers that support the protocol. The list is sorted by latency.

View File

@ -45,7 +45,7 @@ class Metadata extends BaseProtocol implements IMetadata {
pubsubTopicsToShardInfo(this.pubsubTopics)
);
const peer = await this.peerStore.get(peerId);
const peer = await this.libp2pComponents.peerStore.get(peerId);
if (!peer) {
return {
shardInfo: null,

View File

@ -47,7 +47,7 @@ export class WakuPeerExchange extends BaseProtocol implements IPeerExchange {
numPeers: BigInt(numPeers)
});
const peer = await this.peerStore.get(peerId);
const peer = await this.components.peerStore.get(peerId);
if (!peer) {
return {
peerInfos: null,

View File

@ -16,6 +16,8 @@ export enum Protocols {
export type IBaseProtocolCore = {
multicodec: string;
allPeers: () => Promise<Peer[]>;
connectedPeers: () => Promise<Peer[]>;
addLibp2pEventListener: Libp2p["addEventListener"];
removeLibp2pEventListener: Libp2p["removeEventListener"];
};