Class NodeConnectionManager

Hierarchy

  • StartStop
    • NodeConnectionManager

Constructors

Properties

[initLock]: RWLockWriter
connectionConnectTimeoutTime: number

Time used to establish NodeConnection

connectionFindConcurrencyLimit: number

Alpha constant for kademlia The number of the closest nodes to contact initially

connectionHolePunchIntervalTime: number

Initial delay between punch packets, delay doubles each attempt.

connectionIdleTimeoutTime: number

Time to wait to garbage collect un-used node connections.

connectionKeepAliveIntervalTime: number

Time interval for sending keep alive messages.

connectionKeepAliveTimeoutTime: number

Time to keep alive node connection.

connectionLocks: LockBox<Lock> = ...
connections: Map<NodeIdString, ConnectionAndTimer> = ...

Data structure to store all NodeConnections. If a connection to a node n does not exist, no entry for n will exist in the map. Alternatively, if a connection is currently being instantiated by some thread, an entry will exist in the map, but only with the lock (no connection object). Once a connection is instantiated, the entry in the map is updated to include the connection object. A nodeIdString is used for the key here since NodeIds can't be used to properly retrieve a value from the map.

keyRing: KeyRing
logger: Logger
nodeGraph: NodeGraph
quicClientCrypto: ClientCryptoOps
quicServer: QUICServer
quicSocket: QUICSocket
rpcCallTimeoutTime: number

Default timeout for RPC handlers

rpcParserBufferSize: number

Max parse buffer size before RPC parser throws an parse error.

rpcServer: RPCServer
seedNodes: SeedNodes
tlsConfig: TLSConfig

Accessors

  • get [eventHandled](): ReadonlyWeakSet<Event>
  • Returns ReadonlyWeakSet<Event>

  • get [eventHandlers](): ReadonlyMap<string, Set<EventHandlerInfo>>
  • Returns ReadonlyMap<string, Set<EventHandlerInfo>>

  • get [eventTarget](): EventTarget
  • Returns EventTarget

  • get [handleEventError](): ((evt) => void)
  • Returns ((evt) => void)

      • (evt): void
      • Parameters

        • evt: EventError

        Returns void

  • get [running](): boolean
  • Returns boolean

  • get [statusP](): Promise<Status>
  • Returns Promise<Status>

  • get [status](): Status
  • Returns Status

Methods

  • Parameters

    • type: string
    • callback: null | EventListenerOrEventListenerObject
    • Optional options: boolean | AddEventListenerOptions

    Returns void

  • Removes the connection from the connection man and destroys it.

    Parameters

    • targetNodeId: NodeId

      Id of node we are destroying connection to

    Returns Promise<void>

  • Parameters

    • event: Event

    Returns boolean

  • Protected

    This will connect to the provided address looking for any of the listed nodes. Locking is not handled at this level, it must be handled by the caller.

    Parameters

    Returns Promise<Map<NodeIdString, ConnectionAndTimer>>

  • Used internally by getMultiConnection to attempt a single connection. Locking is not done at this stage, it must be done at a higher level. This will do the following...

    1. Attempt the connection
    2. On success, do final setup and add connection to result and connection map.
    3. If already in the map it will clean up connection.

    Parameters

    Returns Promise<void>

  • Will attempt to find a connection via a Kademlia search. The connection will be established in the process.

    Parameters

    • targetNodeId: NodeId

      Id of the node we are tying to find

    • Optional pingTimeoutTime: number

      timeout for any ping attempts

    • Optional ctx: Partial<ContextTimed>

    Returns PromiseCancellable<undefined | NodeAddress>

  • Attempts to locate a target node in the network (using Kademlia). Adds all discovered, active nodes to the current node's database (up to k discovered nodes). Once the target node is found, the method returns and stops trying to locate other nodes.

    Ultimately, attempts to perform a "DNS resolution" on the given target node ID (i.e. given a node ID, retrieves the node address, containing its IP and port).

    Parameters

    • targetNodeId: NodeId

      ID of the node attempting to be found (i.e. attempting to find its IP address and port)

    • Optional pingTimeoutTime: number
    • Optional ctx: Partial<ContextTimed>

    Returns PromiseCancellable<undefined | NodeAddress>

    whether the target node was located in the process

  • This will return an existing connection or establish a new one as needed. If no address is provided it will preform a kademlia search for the node.

    Parameters

    • targetNodeId: NodeId
    • Optional address: NodeAddress
    • Optional ctx: Partial<ContextTimed>

    Returns any

  • This gets a connection with a known address.

    Parameters

    • targetNodeId: NodeId

      Id of node we are creating connection to.

    • address: NodeAddress

      The address to connect on if specified. If not provided we attempt a kademlia search.

    • Optional ctx: Partial<ContextTimed>

    Returns PromiseCancellable<ConnectionAndTimer>

    ConnectionAndLock that was created or exists in the connection map

  • Used to start connections to multiple nodes and hosts at the same time. The main use-case is to connect to multiple seed nodes on the same hostname.

    Parameters

    • nodeIds: NodeId[]
    • addresses: NodeAddress[]
    • Optional limit: number
    • Optional ctx: Partial<ContextTimed>

    Returns PromiseCancellable<NodeId[]>

  • Performs an RPC request to retrieve the closest nodes relative to the given target node ID.

    Parameters

    • nodeId: NodeId

      the node ID to search on

    • targetNodeId: NodeId

      the node ID to find other nodes closest to it

    • Optional ctx: Partial<ContextTimed>

    Returns PromiseCancellable<[NodeId, NodeData][]>

  • This will take a QUICConnection emitted by the QUICServer and handle adding it to the connection map This will also set up some event handling for the connection.

    Parameters

    • quicConnection: QUICConnection

    Returns Promise<void>

  • Triggers the destruction of the NodeConnectionManager. Since this is only in response to an underlying problem or close it will force destroy. Dispatched by the EventNodeConnectionManagerError event as the EventNodeConnectionManagerError -> EventNodeConnectionManagerClose event path.

    Returns Promise<void>

  • Dispatches a EventNodeConnectionManagerClose in response to any NodeConnectionManager error event. Will trigger stop of the NodeConnectionManager via the EventNodeConnectionManagerError -> EventNodeConnectionManagerClose event path.

    Returns void

  • Redispatches QUICSOcket or QUICServer error events as NodeConnectionManager error events. This should trigger the destruction of the NodeConnection through the EventNodeConnectionError -> EventNodeConnectionClose event path.

    Parameters

    • evt: EventQUICSocketError

    Returns void

  • Handles EventQUICServerConnection events. These are reverser or server peer initated connections that needs to be handled and added to the connectio map.

    Parameters

    • evt: EventQUICServerConnection

    Returns Promise<void>

  • Handle unexpected stoppage of the QUICServer. Not expected to happen without error but we have it just in case.

    Parameters

    • _evt: EventQUICServerStopped

    Returns void

  • Handle unexpected stoppage of the QUICSocket. Not expected to happen without error but we have it just in case.

    Parameters

    • _evt: EventQUICSocketStopped

    Returns void

  • Open up a port in the NAT by sending packets to the target address. The packets will be sent in an exponential backoff dialing pattern and contain random data.

    This can't know it succeeded, it will continue until timed out or cancelled.

    Parameters

    • host: Host

      host of the target client.

    • port: Port

      port of the target client.

    • Optional ctx: Partial<ContextTimed>

    Returns Promise<void>

  • This attempts the NAT hole punch procedure. It will return a PromiseCancellable that will resolve once the procedure times out, is cancelled or the other end responds.

    This is pretty simple, it will contact all known seed nodes and get them to relay a punch signal message.

    Note: Avoid using a large set of target nodes, It could trigger a large amount of pings to a single target.

    Parameters

    • targetNodeIds: NodeId[]
    • Optional ctx: Partial<ContextTimedInput>

    Returns PromiseCancellable<void>

  • Returns {
        address: {
            host: Host;
            hostname: undefined | Hostname;
            port: Port;
        };
        nodeId: NodeId;
        timeout: undefined | number;
        usageCount: number;
    }[]

  • Checks if a connection can be made to the target. Returns true if the connection can be authenticated, it's certificate matches the nodeId and the addresses match if provided. Otherwise, returns false.

    Parameters

    • nodeId: NodeId

      NodeId of the target

    • host: Host | Hostname

      Host of the target node

    • port: Port

      Port of the target node

    • Optional ctx: Partial<ContextTimedInput>

    Returns PromiseCancellable<boolean>

  • Forwards a received hole punch message on to the target. If not known, the node ID -> address mapping is attempted to be discovered through Kademlia (note, however, this is currently only called by a 'broker' node).

    Parameters

    • message: HolePunchRelayMessage

      the original relay message (assumed to be created in nodeConnection.start())

    • sourceAddress: NodeAddress
    • Optional ctx: Partial<ContextTimed>

    Returns PromiseCancellable<void>

  • Parameters

    • type: string
    • callback: null | EventListenerOrEventListenerObject
    • Optional options: boolean | EventListenerOptions

    Returns void

  • Performs an RPC request to send a hole-punch message to the target. Used to initially establish the NodeConnection from source to target.

    Parameters

    • relayNodeId: NodeId

      node ID of the relay node (i.e. the seed node)

    • sourceNodeId: NodeId

      node ID of the current node (i.e. the sender)

    • targetNodeId: NodeId

      node ID of the target node to hole punch

    • Optional address: NodeAddress
    • Optional ctx: Partial<ContextTimed>

    Returns PromiseCancellable<void>

  • Parameters

    • __namedParameters: {
          host?: Host;
          ipv6Only?: boolean;
          manifest?: ServerManifest;
          port?: Port;
          reuseAddr?: boolean;
      }
      • Optional host?: Host
      • Optional ipv6Only?: boolean
      • Optional manifest?: ServerManifest
      • Optional port?: Port
      • Optional reuseAddr?: boolean

    Returns Promise<void>

Generated using TypeDoc