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

View File

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

View File

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