lotus-sdk
Version:
Central repository for several classes of tools for integrating with, and building for, the Lotusia ecosystem
66 lines • 2.92 kB
TypeScript
import { EventEmitter } from 'events';
import { Libp2p } from 'libp2p';
import { Multiaddr } from '@multiformats/multiaddr';
import { P2PConfig, P2PMessage, PeerInfo, IProtocolHandler, ResourceAnnouncement, BroadcastOptions, DHTStats, P2PStats } from './types.js';
import { CoreSecurityManager } from './security.js';
export declare class P2PCoordinator extends EventEmitter {
protected readonly config: P2PConfig;
protected node?: Libp2p;
private protocol;
private protocolHandlers;
private seenMessages;
private peerInfo;
private dhtValues;
private cleanupIntervalId?;
protected coreSecurityManager: CoreSecurityManager;
private lastAdvertisedMultiaddrs;
private topicHandlers;
constructor(config: P2PConfig);
getCoreSecurityManager(): CoreSecurityManager;
private startDHTCleanup;
start(): Promise<void>;
stop(): Promise<void>;
get peerId(): string;
get libp2pNode(): Libp2p;
registerProtocol(handler: IProtocolHandler): void;
unregisterProtocol(protocolName: string): void;
connectToPeer(peerAddr: string | Multiaddr): Promise<void>;
disconnectFromPeer(peerId: string): Promise<void>;
sendTo(peerId: string, message: P2PMessage, protocolId?: string): Promise<void>;
broadcast(message: P2PMessage, options?: BroadcastOptions): Promise<void>;
announceResource<T = unknown>(resourceType: string, resourceId: string, data: T, options?: {
ttl?: number;
expiresAt?: number;
}): Promise<void>;
getLocalResources(resourceType: string, filters?: Record<string, unknown>): Array<ResourceAnnouncement<unknown>>;
getResource(resourceType: string, resourceId: string): ResourceAnnouncement | null;
discoverResource(resourceType: string, resourceId: string, timeoutMs?: number): Promise<ResourceAnnouncement | null>;
private _queryDHT;
private _putDHT;
getConnectedPeers(): PeerInfo[];
getPeer(peerId: string): PeerInfo | undefined;
isConnected(peerId: string): boolean;
getStats(): P2PStats;
getReachableAddresses(): Promise<string[]>;
private _constructRelayCircuitAddresses;
hasRelayAddresses(): Promise<boolean>;
getRelayAddresses(): Promise<string[]>;
getConnectionStats(): {
totalConnections: number;
connectedPeers: string[];
};
private _checkAndNotifyRelayAddresses;
getDHTStats(): DHTStats;
cleanup(): void;
shutdown(): Promise<void>;
private _setupEventHandlers;
private _registerProtocolStreamHandlers;
private _handleIncomingStream;
private _matchesFilters;
private _makeResourceKey;
subscribeToTopic(topic: string, handler: (message: Uint8Array) => void): Promise<void>;
unsubscribeFromTopic(topic: string): Promise<void>;
publishToTopic(topic: string, message: unknown): Promise<void>;
getTopicPeers(topic: string): string[];
}
//# sourceMappingURL=coordinator.d.ts.map