import type { X509Certificate } from '@peculiar/x509'; import type { ContextTimedInput } from '@matrixai/contexts'; import type { PromiseCancellable } from '@matrixai/async-cancellable'; import type { QUICSocket, QUICConnection } from '@matrixai/quic'; import type { ClientManifest } from '@matrixai/rpc'; import type { Host, Hostname, Port, TLSConfig } from '../network/types.js'; import type { Certificate } from '../keys/types.js'; import type { NodeId } from './types.js'; import Logger from '@matrixai/logger'; import { createDestroy } from '@matrixai/async-init'; import { EventAll } from '@matrixai/events'; import { QUICClient, events as quicEvents } from '@matrixai/quic'; import { RPCClient } from '@matrixai/rpc'; import * as nodesEvents from './events.js'; /** * Encapsulates the unidirectional client-side connection of one node to another. */ interface NodeConnection extends createDestroy.CreateDestroy { } declare class NodeConnection { /** * Hostname is defined if the target's host was resolved from this hostname * Undefined if a Host was directly provided */ readonly hostname?: Hostname; /** * The NodeId that it was validated on when verifying the peer */ readonly validatedNodeId: NodeId; /** * The most current NodeId of the peer's cert chain */ readonly nodeId: NodeId; readonly host: Host; readonly port: Port; readonly localHost: Host; readonly localPort: Port; readonly certChain: Readonly[]; protected logger: Logger; readonly quicClient: QUICClient | undefined; readonly quicConnection: QUICConnection; readonly connectionId: string; readonly rpcClient: RPCClient; /** * Dispatches a `EventNodeConnectionClose` in response to any `NodeConnection` * error event. Will trigger destruction of the `NodeConnection` via the * `EventNodeConnectionError` -> `EventNodeConnectionClose` event path. */ protected handleEventNodeConnectionError: (evt: nodesEvents.EventNodeConnectionError) => void; /** * Triggers the destruction of the `NodeConnection`. Since this is only in * response to an underlying problem or close it will force destroy. * Dispatched by the `EventNodeConnectionError` event as the * `EventNodeConnectionError` -> `EventNodeConnectionClose` event path. */ protected handleEventNodeConnectionClose: (_evt: nodesEvents.EventNodeConnectionClose) => Promise; /** * Redispatches a `QUICStream` from a `EventQUICConnectionStream` event with * a `EventNodeConnectionStream` event. Should bubble upwards through the * `NodeConnectionManager`. */ protected handleEventQUICConnectionStream: (evt: quicEvents.EventQUICConnectionStream) => void; /** * Redispatches `QUICConnection` or `QUICClient` error events as `NodeConnection` error events. * This should trigger the destruction of the `NodeConnection` through the * `EventNodeConnectionError` -> `EventNodeConnectionClose` event path. */ protected handleEventQUICError: (evt: quicEvents.EventQUICConnectionError) => void; protected handleEventQUICClientDestroyed: (_evt: quicEvents.EventQUICClientDestroyed) => void; protected handleEventQUICConnectionStopped: (_evt: quicEvents.EventQUICConnectionStopped) => void; /** * Propagates all events from the `QUICClient` or `QUICConnection` upwards. * If the `QUICClient` exists then it is just registered to that, otherwise just * the `QUICConnection`. * Will only re-dispatch the event if it's an `AbstractEvent`. */ protected handleEventAll: (evt: EventAll) => void; static createNodeConnection({ targetNodeIds, targetHost, targetPort, targetHostname, tlsConfig, connectionKeepAliveIntervalTime, connectionKeepAliveTimeoutTime, connectionInitialMaxStreamsBidi, connectionInitialMaxStreamsUni, quicSocket, manifest, logger, }: { targetNodeIds: Array; targetHost: Host; targetPort: Port; targetHostname?: Hostname; tlsConfig: TLSConfig; connectionKeepAliveIntervalTime?: number; connectionKeepAliveTimeoutTime?: number; connectionInitialMaxStreamsBidi?: number; connectionInitialMaxStreamsUni?: number; quicSocket?: QUICSocket; manifest: Manifest; logger?: Logger; }, ctx?: Partial): PromiseCancellable>; static createNodeConnectionReverse({ certChain, nodeId, quicConnection, manifest, logger, }: { certChain: Array; nodeId: NodeId; quicConnection: QUICConnection; manifest: Manifest; logger?: Logger; }): NodeConnection; constructor({ validatedNodeId, nodeId, host, port, localHost, localPort, certChain, hostname, quicClient, quicConnection, connectionId, rpcClient, logger, }: { validatedNodeId: NodeId; nodeId: NodeId; host: Host; port: Port; localHost: Host; localPort: Port; certChain: Readonly[]; hostname?: Hostname; quicClient?: QUICClient; quicConnection: QUICConnection; connectionId: string; rpcClient: RPCClient; logger: Logger; }); destroy({ force, }?: { force?: boolean; }): Promise; /** * Gets RPCClient for this node connection */ getClient(): RPCClient; } export default NodeConnection;