Class NodeManager

Hierarchy

  • StartStop
    • NodeManager

Constructors

  • Parameters

    • __namedParameters: {
          connectionConnectTimeoutTime?: number;
          db: DB;
          dnsServers?: string[];
          gestaltGraph: GestaltGraph;
          keyRing: KeyRing;
          logger?: Logger;
          mdnsOptions?: {
              groups: Host[];
              port: Port;
          };
          nodeConnectionManager: NodeConnectionManager;
          nodeGraph: NodeGraph;
          nodesConnectionFindLocalTimeoutTime?: number;
          refreshBucketDelayJitter?: number;
          refreshBucketDelayTime?: number;
          retryConnectionsDelayTime?: number;
          sigchain: Sigchain;
          taskManager: TaskManager;
      }
      • Optional connectionConnectTimeoutTime?: number
      • db: DB
      • Optional dnsServers?: string[]
      • gestaltGraph: GestaltGraph
      • keyRing: KeyRing
      • Optional logger?: Logger
      • Optional mdnsOptions?: {
            groups: Host[];
            port: Port;
        }
      • nodeConnectionManager: NodeConnectionManager
      • nodeGraph: NodeGraph
      • Optional nodesConnectionFindLocalTimeoutTime?: number
      • Optional refreshBucketDelayJitter?: number
      • Optional refreshBucketDelayTime?: number
      • Optional retryConnectionsDelayTime?: number
      • sigchain: Sigchain
      • taskManager: TaskManager

    Returns NodeManager

Properties

[initLock]: RWLockWriter
checkConnectionsHandler: TaskHandler = ...
checkConnectionsHandlerId: TaskHandlerId = ...
concurrencyLimit: number = 3
connectionConnectTimeoutTime: number

Time used to establish NodeConnection

connectionFindMDNSTimeoutTime: number

Timeout for finding a connection via MDNS

connectionLockBox: LockBox<Lock> = ...

Used to track locks for authentication failure and acquiring connections

db: DB
dnsServers: undefined | string[] = undefined
gcBucketHandler: TaskHandler = ...
gcBucketHandlerId: TaskHandlerId = ...
gestaltGraph: GestaltGraph
keyRing: KeyRing
logger: Logger
mdns: undefined | MDNS
mdnsOptions: undefined | {
    groups: Host[];
    port: Port;
}

Type declaration

nodeConnectionManager: NodeConnectionManager
nodeGraph: NodeGraph
pendingNodes: Map<number, Map<string, [NodeAddress, NodeContactAddressData]>> = ...
refreshBucketDelayJitter: number
refreshBucketDelayTime: number
refreshBucketHandler: TaskHandler = ...
refreshBucketHandlerId: TaskHandlerId = ...
retryConnectionsDelayTime: number

Interval used to reestablish connections to maintain network health. Will trigger a refreshBucket for bucket 255 if it is missing connections. Will always trigger a findNode(this.keyRing.getNodeId()).

sigchain: Sigchain
syncNodeGraphHandlerId: TaskHandlerId = ...
taskManager: TaskManager
tasksPath: "NodeManager" = 'NodeManager'

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

  • For usage with withF, to acquire a connection This unique acquire function structure of returning the ResourceAcquire itself is such that we can pass targetNodeId as a parameter (as opposed to an acquire function with no parameters).

    Parameters

    • nodeId: NodeId

      Id of target node to communicate with

    • ctx: ContextTimed

    Returns ResourceAcquire<NodeConnection>

    ResourceAcquire Resource API for use in with contexts

  • Parameters

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

    Returns void

  • Parameters

    • bucketIndex: number
    • nodeId: NodeId
    • nodeAddress: NodeAddress
    • nodeContactAddressData: NodeContactAddressData
    • block: boolean = false
    • connectionConnectTimeoutTime: number = ...
    • ctx: ContextTimed
    • Optional tran: DBTransaction

    Returns Promise<void>

  • Call this function upon receiving a "claim node request" notification from another node.

    Parameters

    • targetNodeId: NodeId
    • Optional tran: DBTransaction
    • Optional ctx: Partial<ContextTimedInput>

    Returns PromiseCancellable<void>

  • Parameters

    • event: Event

    Returns boolean

  • Will attempt to find a node within the network using a hybrid strategy of attempting signalled connections, direct connections and checking MDNS.

    Will attempt to fix regardless of existing connection.

    Parameters

    • __namedParameters: {
          concurrencyLimit?: number;
          connectionConnectTimeoutTime?: number;
          connectionFindMDNSTimeoutTime?: number;
          limit?: number;
          nodeId: NodeId;
      }
      • Optional concurrencyLimit?: number
      • Optional connectionConnectTimeoutTime?: number
      • Optional connectionFindMDNSTimeoutTime?: number
      • Optional limit?: number
      • nodeId: NodeId
    • Optional ctx: Partial<ContextTimedInput>

    Returns PromiseCancellable<undefined | [NodeAddress, NodeContactAddressData]>

  • Will try to make a connection to the node using direct connections only

    Parameters

    • nodeId: NodeId

      NodeId of the target to find.

    • nodeConnectionsQueue: NodeConnectionQueue

      shared nodeConnectionQueue helper class.

    • Optional connectionConnectTimeoutTime: number

      timeout time for each individual connection.

    • Optional ctx: Partial<ContextTimedInput>

    Returns PromiseCancellable<[[Host, Port], NodeContactAddressData]>

  • Will try to make a connection to the node using hole punched connections only

    Parameters

    • nodeId: NodeId

      NodeId of the target to find.

    • nodeConnectionsQueue: NodeConnectionQueue

      shared nodeConnectionQueue helper class.

    • Optional connectionConnectTimeoutTime: number

      timeout time for each individual connection.

    • Optional ctx: Partial<ContextTimedInput>

    Returns PromiseCancellable<[[Host, Port], NodeContactAddressData]>

  • Parameters

    • bucketIndex: number
    • Optional connectionConnectTimeoutTime: number
    • Optional ctx: Partial<ContextTimed>
    • Optional tran: DBTransaction

    Returns PromiseCancellable<void>

  • Gets the specified bucket from the NodeGraph

    Parameters

    • bucketIndex: number
    • Optional tran: DBTransaction

    Returns Promise<undefined | NodeBucket>

  • Will attempt to make a direct connection without ICE. This will only succeed due to these conditions

    1. connection already exists to target.
    2. Nat already allows port due to already being punched.
    3. Port is publicly accessible due to nat configuration . Will return true if connection was established or already exists, false otherwise.

    Parameters

    • nodeId: NodeId
    • host: Host
    • port: Port
    • Optional ctx: Partial<ContextTimedInput>

    Returns PromiseCancellable<boolean>

  • Will query via MDNS for running Polykey nodes with the matching NodeId

    Parameters

    • nodeId: NodeId
    • Optional ctx: Partial<ContextTimedInput>

    Returns PromiseCancellable<[Host, Port][]>

  • Will ask the target node about the closest nodes to the node and add them to the nodeConnectionsQueue.

    Parameters

    • nodeId: NodeId

      node to find the closest nodes to

    • nodeIdTarget: NodeId

      node to make RPC requests to

    • nodeConnectionsQueue: NodeConnectionQueue
    • ctx: ContextTimed

    Returns Promise<void>

  • Kademlia refresh bucket operation. It generates a random node ID within the range of a bucket and does a lookup for that node in the network. This will cause the network to update its node graph information.

    Parameters

    • bucketIndex: number
    • Optional connectionConnectTimeoutTime: number
    • Optional ctx: Partial<ContextTimed>

    Returns PromiseCancellable<void>

  • Parameters

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

    Returns void

  • Connects to the target node, and retrieves its sigchain data. Verifies and returns the decoded chain as ChainData. Note: this will drop any unverifiable claims. For node1 -> node2 claims, the verification process also involves connecting to node2 to verify the claim (to retrieve its signing public key).

    Parameters

    • targetNodeId: NodeId

      Id of the node to connect request the chain data of.

    • Optional claimId: ClaimId

      If set then we get the claims newer that this claim ID.

    • Optional ctx: Partial<ContextTimed>

    Returns PromiseCancellable<Record<ClaimId, SignedClaim>>

  • To be called on key renewal. Re-orders all nodes in all buckets with respect to the new node ID.

    Returns Promise<void>

  • Adds a node to the node graph. This assumes that you have already authenticated the node Updates the node if the node already exists This operation is blocking by default - set block to false to make it non-blocking

    Parameters

    • nodeId: NodeId

      ID of the node we wish to add

    • nodeAddress: NodeAddress

      Expected address of the node we want to add

    • nodeContactAddressData: NodeContactAddressData
    • Optional block: boolean

      When true it will wait for any garbage collection to finish before returning.

    • Optional force: boolean

      Flag for if we want to add the node without authenticating or if the bucket is full. This will drop the oldest node in favor of the new.

    • Optional connectionConnectTimeoutTime: number

      Timeout for each ping operation during garbage collection.

    • Optional tran: DBTransaction
    • Optional ctx: Partial<ContextTimed>

    Returns PromiseCancellable<void>

  • Cancels all NodeManager tasks. These are ephemeral and will be recreated next time we start.

    Returns Promise<void>

  • Perform an initial database synchronisation: get k of the closest nodes from each seed node and add them to this database Establish a connection to each node before adding it By default this operation is blocking, set block to false to make it

    From the spec: To join the network, a node u must have a contact to an already participating node w. u inserts w into the appropriate k-bucket. u then performs a node lookup for its own node ID. Finally, u refreshes all k-buckets further away than its closest neighbor. During the refreshes, u both populates its own k-buckets and inserts itself into other nodes’ k-buckets as necessary.

    So this will do 3 steps

    1. Connect to the initial nodes
    2. do a find-node operation for itself
    3. reschedule refresh bucket operations for every bucket above the closest node we found

    Parameters

    • initialNodes: [NodeId, NodeAddress][]
    • Optional connectionConnectTimeoutTime: number
    • Optional blocking: boolean
    • Optional ctx: Partial<ContextTimedInput>

    Returns PromiseCancellable<void>

  • Parameters

    Returns Promise<void>

  • Removes a node from the NodeGraph

    Parameters

    • nodeId: NodeId
    • tran: DBTransaction

    Returns Promise<void>

  • Parameters

    • bucketIndex: number
    • Optional delay: number
    • Optional lazy: boolean
    • Optional tran: DBTransaction
    • Optional ctx: Partial<ContextTimedInput>

    Returns Promise<Task>

  • Perform some function on another node over the network with a connection. Will either retrieve an existing connection, or create a new one if it doesn't exist. For use with normal arrow function

    Type Parameters

    • T

    Parameters

    • nodeId: NodeId

      Id of target node to communicate with

    • ctx: undefined | Partial<ContextTimedInput>
    • f: ((conn) => Promise<T>)

      Function to handle communication

        • (conn): Promise<T>
        • Parameters

          Returns Promise<T>

    Returns Promise<T>

  • Perform some function on another node over the network with a connection. Will either retrieve an existing connection, or create a new one if it doesn't exist. for use with a generator function

    Type Parameters

    • T

    • TReturn

    • TNext

    Parameters

    • nodeId: NodeId

      Id of target node to communicate with

    • ctx: undefined | Partial<ContextTimedInput>
    • g: ((conn) => AsyncGenerator<T, TReturn, TNext>)

      Generator function to handle communication

        • (conn): AsyncGenerator<T, TReturn, TNext>
        • Parameters

          Returns AsyncGenerator<T, TReturn, TNext>

    Returns AsyncGenerator<T, TReturn, TNext>

Generated using TypeDoc