mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-03-23 07:13:14 +00:00
* up lock * make ConnectionManager use ctor * reform connection manager configurations * remove log param from peerManager * make PeerManager use only ConnectionManager, move getPeers to ConnectionManager, remove not needed code * remove allPeers and connectedPeers from BaseProtocolCore, update tests, add getPeers for IWaku * use only one peerManager from Waku object * remove IBaseProtocolSDK and merge with PeerManager * re-implement peerManager, remove ProtocolUseOptions * remove not needed test, up lock * update deps and lock * remove old test for peerManager, fix check and spell * rename to getConnectedPeers * feat: improve filter subscriptions (#2193) * add message cache to Filter * remove WakuOptions and use only ProtocolCreateOptions * move subscribe options to createLightNode Fitler protocol options * rename SubscriptionManager to Subscription * rename to CreateNodeOptions * add warning * feat: introduce subscription manager (#2202) * feat: inroduce subscription manager * fix: make pipeline succeed (#2238) * fix test * use hardcoded value * update playwright * fix test:browser * up lock * make peer retrieval probabilistic * add comments * up lightpush tests * add tests for peer_manager, improve folder structure * create named files for protocols * create named files, simplify project structure * remove only
94 lines
2.5 KiB
TypeScript
94 lines
2.5 KiB
TypeScript
import type { Peer, PeerId, TypedEventEmitter } from "@libp2p/interface";
|
|
|
|
import { PubsubTopic } from "./misc.js";
|
|
|
|
export enum Tags {
|
|
BOOTSTRAP = "bootstrap",
|
|
PEER_EXCHANGE = "peer-exchange",
|
|
LOCAL = "local-peer-cache"
|
|
}
|
|
|
|
export type ConnectionManagerOptions = {
|
|
/**
|
|
* Number of attempts before a peer is considered non-dialable.
|
|
* This is used to not spam a peer with dial attempts when it is not dialable.
|
|
*
|
|
* @default 3
|
|
*/
|
|
maxDialAttemptsForPeer: number;
|
|
|
|
/**
|
|
* Max number of bootstrap peers allowed to be connected to initially.
|
|
* This is used to increase intention of dialing non-bootstrap peers, found using other discovery mechanisms (like Peer Exchange).
|
|
*
|
|
* @default 1
|
|
*/
|
|
maxBootstrapPeersAllowed: number;
|
|
|
|
/**
|
|
* Max number of parallel dials allowed.
|
|
*
|
|
* @default 3
|
|
*/
|
|
maxParallelDials: number;
|
|
|
|
/**
|
|
* Keep alive libp2p pings interval in seconds.
|
|
*
|
|
* @default 300 seconds
|
|
*/
|
|
pingKeepAlive: number;
|
|
|
|
/**
|
|
* Gossip sub specific keep alive interval in seconds.
|
|
*
|
|
* @default 300 seconds
|
|
*/
|
|
relayKeepAlive: number;
|
|
};
|
|
|
|
export enum EPeersByDiscoveryEvents {
|
|
PEER_DISCOVERY_BOOTSTRAP = "peer:discovery:bootstrap",
|
|
PEER_DISCOVERY_PEER_EXCHANGE = "peer:discovery:peer-exchange",
|
|
PEER_CONNECT_BOOTSTRAP = "peer:connected:bootstrap",
|
|
PEER_CONNECT_PEER_EXCHANGE = "peer:connected:peer-exchange"
|
|
}
|
|
|
|
export interface IPeersByDiscoveryEvents {
|
|
[EPeersByDiscoveryEvents.PEER_DISCOVERY_BOOTSTRAP]: CustomEvent<PeerId>;
|
|
[EPeersByDiscoveryEvents.PEER_DISCOVERY_PEER_EXCHANGE]: CustomEvent<PeerId>;
|
|
[EPeersByDiscoveryEvents.PEER_CONNECT_BOOTSTRAP]: CustomEvent<PeerId>;
|
|
[EPeersByDiscoveryEvents.PEER_CONNECT_PEER_EXCHANGE]: CustomEvent<PeerId>;
|
|
}
|
|
|
|
export interface PeersByDiscoveryResult {
|
|
DISCOVERED: {
|
|
[Tags.BOOTSTRAP]: Peer[];
|
|
[Tags.PEER_EXCHANGE]: Peer[];
|
|
[Tags.LOCAL]: Peer[];
|
|
};
|
|
CONNECTED: {
|
|
[Tags.BOOTSTRAP]: Peer[];
|
|
[Tags.PEER_EXCHANGE]: Peer[];
|
|
[Tags.LOCAL]: Peer[];
|
|
};
|
|
}
|
|
|
|
export enum EConnectionStateEvents {
|
|
CONNECTION_STATUS = "waku:connection"
|
|
}
|
|
|
|
export interface IConnectionStateEvents {
|
|
// true when online, false when offline
|
|
[EConnectionStateEvents.CONNECTION_STATUS]: CustomEvent<boolean>;
|
|
}
|
|
|
|
export interface IConnectionManager
|
|
extends TypedEventEmitter<IPeersByDiscoveryEvents & IConnectionStateEvents> {
|
|
pubsubTopics: PubsubTopic[];
|
|
getConnectedPeers(codec?: string): Promise<Peer[]>;
|
|
dropConnection(peerId: PeerId): Promise<void>;
|
|
getPeersByDiscovery(): Promise<PeersByDiscoveryResult>;
|
|
stop(): void;
|
|
}
|