import { EventEmitter } from '../utils/EventEmitter'; import { GunDataProvider } from '../data/GunDataProvider'; import { NetworkGraph, PeerInfo, TopologyAnalysis } from '../Types'; export declare class PeerManager extends EventEmitter { private gunDataProvider; private peers; private logger; private errorHandler; constructor(gunDataProvider: GunDataProvider); generateNetworkGraph(): NetworkGraph; analyzeTopology(): TopologyAnalysis; private findCentralPeers; measureLatency(peerId: string): Promise; connectToPeer(peerId: string, peerUrl: string): void; disconnectFromPeer(peerId: string): void; sendToPeer(peerId: string, message: any): void; broadcast(message: any): void; getCurrentPeerId(): string; executeInPeerContext(peerId: string, callback: (peer: any) => void): void; private setupGunListeners; /** * Handles a new peer connection * @param peer The connected peer */ private handlePeerConnected; /** * Handles a peer disconnection * @param peer The disconnected peer */ private handlePeerDisconnected; /** * Adds a new peer to the connected peers list * @param peerId The ID of the peer * @param peerUrl The URL of the peer */ private addPeer; /** * Removes a peer from the connected peers list * @param peerId The ID of the peer to remove */ private removePeer; /** * Gets the latency for a specific peer * @param peerId The ID of the peer * @returns The latency in milliseconds, or -1 if the peer is not found */ getPeerLatency(peerId: string): number; /** * Gets the IDs of all connected peers * @returns An array of peer IDs */ getConnectedPeerIds(): string[]; /** * Gets information about all connected peers * @returns An array of PeerInfo objects */ getPeers(): PeerInfo[]; /** * Sends a message to a specific peer * @param peerId The ID of the peer * @param message The message to send */ sendMessage(peerId: string, message: any): void; /** * Broadcasts a message to all connected peers * @param message The message to broadcast */ broadcastMessage(message: any): void; /** * Listens for messages from a specific peer * @param peerId The ID of the peer to listen to * @param callback The function to call when a message is received */ listenToPeer(peerId: string, callback: (message: any) => void): void; /** * Listens for broadcast messages * @param callback The function to call when a broadcast message is received */ listenToBroadcasts(callback: (message: any) => void): void; /** * Authenticates the current peer * @param alias The alias for the peer * @param password The password for authentication * @returns A promise that resolves when authentication is complete */ authenticate(alias: string, password: string): Promise; /** * Creates a new peer account * @param alias The alias for the new peer * @param password The password for the new peer * @returns A promise that resolves when account creation is complete */ createAccount(alias: string, password: string): Promise; /** * Gets the current authenticated peer's public key * @returns The public key of the current peer, or null if not authenticated */ getCurrentPeerPublicKey(): string | null; /** * Stops the PeerManager and cleans up resources */ stop(): void; }