mirror of
https://github.com/logos-messaging/logos-delivery-js.git
synced 2026-03-11 04:03:07 +00:00
* chore: make `dropConnection` to be a public function * feat: peers are maintained for protocols - passes `ConnectionManager` to ProtocolSDK to allow disconnecting from within protocol - maintains `numPeersToUse` for each protocol within BaseProtocolSDK * fix: pass options to protocols * chore: update interfaces to allow public access * chore: improve logging on protocol * fix: renew peer upon failure * chore(tests): allow DefaultPubsubTopic * feat(lightpush): write peer management tests * chore: rename test * feat: add lock to `maintainPeers()` to handle parallelisation of requests fixes parallelisation of lightpush.send() requests * fix: concurrent lightpush requests * fix: test & improve peers fetching * chore: use getter * address comments * chore: smaller improvements * feat: attempt to improve time for first lightpush.send() * chore: use `window.interval` for type-safety * chore: remove delays * feat: add autoRetry * feat: `forceUseAllPeers` to wait for all connected peers to be resoled
68 lines
2.1 KiB
TypeScript
68 lines
2.1 KiB
TypeScript
import type { Peer, PeerId, TypedEventEmitter } from "@libp2p/interface";
|
|
|
|
export enum Tags {
|
|
BOOTSTRAP = "bootstrap",
|
|
PEER_EXCHANGE = "peer-exchange",
|
|
LOCAL = "local-peer-cache"
|
|
}
|
|
|
|
export interface 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
|
|
*/
|
|
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)
|
|
*/
|
|
maxBootstrapPeersAllowed: number;
|
|
/**
|
|
* Max number of parallel dials allowed
|
|
*/
|
|
maxParallelDials: 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> {
|
|
dropConnection(peerId: PeerId): Promise<void>;
|
|
getPeersByDiscovery(): Promise<PeersByDiscoveryResult>;
|
|
stop(): void;
|
|
}
|