mirror of
https://github.com/waku-org/js-waku.git
synced 2025-02-22 09:08:19 +00:00
fix: build
This commit is contained in:
parent
3384b875a9
commit
557ee96b52
@ -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.
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -16,6 +16,8 @@ export enum Protocols {
|
||||
|
||||
export type IBaseProtocolCore = {
|
||||
multicodec: string;
|
||||
allPeers: () => Promise<Peer[]>;
|
||||
connectedPeers: () => Promise<Peer[]>;
|
||||
addLibp2pEventListener: Libp2p["addEventListener"];
|
||||
removeLibp2pEventListener: Libp2p["removeEventListener"];
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user