/** * Wrap a network node. */ import { NetworkNodeOptions } from '@streamr/network-node'; import { ProxyDirection, StreamMessage, StreamPartID } from '@streamr/protocol'; import { MetricsContext } from '@streamr/utils'; import { Authentication } from './Authentication'; import { StrictStreamrClientConfig } from './Config'; import { DestroySignal } from './DestroySignal'; /** @deprecated This in an internal interface */ export interface NetworkNodeStub { getNodeId: () => string; addMessageListener: (listener: (msg: StreamMessage) => void) => void; removeMessageListener: (listener: (msg: StreamMessage) => void) => void; subscribe: (streamPartId: StreamPartID) => void; subscribeAndWaitForJoin: (streamPart: StreamPartID, timeout?: number) => Promise; waitForJoinAndPublish: (msg: StreamMessage, timeout?: number) => Promise; unsubscribe: (streamPartId: StreamPartID) => void; publish: (streamMessage: StreamMessage) => void; getStreamParts: () => Iterable; getNeighbors: () => ReadonlyArray; getNeighborsForStreamPart: (streamPartId: StreamPartID) => ReadonlyArray; getRtt: (nodeId: string) => number | undefined; setExtraMetadata: (metadata: Record) => void; getMetricsContext: () => MetricsContext; getDiagnosticInfo: () => Record; hasStreamPart: (streamPartId: StreamPartID) => boolean; } export declare const getEthereumAddressFromNodeId: (nodeId: string) => string; export interface Events { start: () => void; } /** * The factory is used so that integration tests can replace the real network node with a fake instance */ export declare class NetworkNodeFactory { createNetworkNode(opts: NetworkNodeOptions): NetworkNodeStub; } /** * Wrap a network node. * Lazily creates & starts node on first call to getNode(). */ export declare class NetworkNodeFacade { private cachedNode?; private startNodeCalled; private startNodeComplete; private readonly networkNodeFactory; private readonly config; private readonly authentication; private readonly eventEmitter; private readonly destroySignal; constructor(networkNodeFactory: NetworkNodeFactory, config: Pick, authentication: Authentication, destroySignal: DestroySignal); private assertNotDestroyed; private getNetworkOptions; private initNode; private generateId; /** * Stop network node, or wait for it to stop if already stopping. * Subsequent calls to getNode/start will fail. */ private destroy; /** * Start network node, or wait for it to start if already started. */ private startNodeTask; startNode: () => Promise; getNode: () => Promise; getNodeId(): Promise; /** * Calls publish on node after starting it. * Basically a wrapper around: (await getNode()).publish(…) * but will be sync in case that node is already started. * Zalgo intentional. See below. */ publishToNode(streamMessage: StreamMessage): void | Promise; setProxies(streamPartId: StreamPartID, nodeIds: string[], direction: ProxyDirection, connectionCount?: number): Promise; private isStarting; once(eventName: E, listener: Events[E]): void; }