Class NodeGraph

Hierarchy

  • CreateDestroyStartStop
    • NodeGraph

Constructors

  • Parameters

    • __namedParameters: {
          db: DB;
          keyRing: KeyRing;
          logger: Logger;
          nodeBucketLimit: number;
          nodeContactAddressLimit: number;
          nodeIdBits: number;
      }
      • db: DB
      • keyRing: KeyRing
      • logger: Logger
      • nodeBucketLimit: number
      • nodeContactAddressLimit: number
      • nodeIdBits: number

    Returns NodeGraph

Properties

[initLock]: RWLockWriter
db: DB
keyRing: KeyRing
logger: Logger
nodeBucketLimit: number

Max number of nodes in each bucket.

nodeContactAddressLimit: number

Max number of nodeContactAddresses for each node.

nodeGraphBucketsDbPath: readonly (string | Buffer)[]

Buckets stores lexi(NodeBucketIndex)/NodeId/nodeContactAddress -> NodeContactAddressData.

nodeContactAddress are canoncialized to be consistent.

nodeGraphConnectedDbPath: readonly (string | Buffer)[]

Last updated stores lexi(NodeBucketIndex)/"time"/lexi(connectedTime)/nodeId -> nodeId. lexi(NodeBucketIndex)/"nodeId"/nodeId -> lexi(connectedTime).

nodeGraphDbPath: readonly (string | Buffer)[] = ...
nodeGraphMetaDbPath: readonly (string | Buffer)[]

Meta stores the keyof NodeBucketMeta -> NodeBucketMeta[keyof NodeBucketMeta].

nodeIdBits: number

Bit size of the node IDs. This is also the total number of buckets.

Accessors

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

  • 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

  • Derive the bucket index of the k-buckets from the new NodeId The bucket key is the string encoded version of bucket index that preserves lexicographic order

    Parameters

    Returns [number, string]

  • Deletes the connectedTime for a NodeId

    Parameters

    • nodeId: NodeId
    • tran: DBTransaction

    Returns Promise<void>

  • Returns Promise<void>

  • Parameters

    • event: Event

    Returns boolean

  • Gets a bucket.

    The bucket's node IDs is sorted lexicographically by default Alternatively you can acquire them sorted by connected timestamp or by distance to the own NodeId.

    Parameters

    • bucketIndex: number
    • Optional sort: "nodeId" | "connected" | "distance"
    • Optional order: "asc" | "desc"
    • Optional limit: number

      Limit the number of nodes returned, note that -1 means no limit, but Infinity means 0.

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

    Returns Promise<NodeBucket>

  • Get a bucket meta POJO. This will provide default values for missing properties.

    Parameters

    • bucketIndex: number
    • Optional tran: DBTransaction

    Returns Promise<NodeBucketMeta>

  • Get a single bucket meta property. This will provide default values for missing properties.

    Type Parameters

    • Key extends "count"

    Parameters

    • bucketIndex: number
    • key: Key
    • Optional tran: DBTransaction

    Returns Promise<NodeBucketMeta[Key]>

  • Gets all buckets. Buckets are always sorted by NodeBucketIndex first Then secondly by the sort parameter The order parameter applies to both, for example possible sorts: NodeBucketIndex asc, NodeID asc NodeBucketIndex desc, NodeId desc NodeBucketIndex asc, distance asc NodeBucketIndex desc, distance desc NodeBucketIndex asc, connected asc NodeBucketIndex desc, connected desc

    Parameters

    • sort: "nodeId" | "connected" | "distance" = 'nodeId'
    • order: "asc" | "desc" = 'asc'
    • Optional tran: DBTransaction

    Returns AsyncGenerator<[number, NodeBucket], any, unknown>

  • Gets the closest nodes (closest based on Kademlia XOR operator) to a given node ID. The returned results will be sorted by distance in ascending order. If the given node ID already exists in the node graph, then it will be the first result.

    Parameters

    • nodeId: NodeId
    • Optional limit: number

      Defaults to the bucket limit.

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

    Returns Promise<NodeBucket>

    The NodeBucket which could have less than limit nodes if the node graph has less than the requested limit.

  • Gets the connectedTime for a node

    Parameters

    • nodeId: NodeId
    • Optional tran: DBTransaction

    Returns any

  • Get a single NodeContact

    Parameters

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

    Returns Promise<undefined | NodeContact>

  • Get all NodeContact.

    Results are sorted by NodeBucketIndex then NodeId then NodeContactAddress. The order parameter applies to both, for example: NodeBucketIndex asc, NodeID asc, NodeContactAddress asc NodeBucketIndex desc, NodeId desc, NodeContactAddress desc

    Parameters

    • order: "asc" | "desc" = 'asc'
    • Optional tran: DBTransaction

    Returns AsyncGenerator<[NodeId, NodeContact], any, unknown>

  • Locks the bucket index for exclusive operations. This allows you to sequence operations for any bucket.

    Parameters

    • bucketIndex: number
    • tran: DBTransaction
    • Optional ctx: ContextTimed

    Returns Promise<void>

  • Returns to total number of nodes in the NodeGraph

    Parameters

    • Optional tran: DBTransaction

    Returns Promise<number>

  • This utility will clean out the oldest addresses until a set amount remain

    Parameters

    • nodeId: NodeId
    • num: number
    • Optional tran: DBTransaction

    Returns Promise<void>

  • Parameters

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

    Returns void

  • Resets the bucket according to the new node ID. Run this after new node ID is generated via renewal or reset.

    Parameters

    • Optional tran: DBTransaction

    Returns Promise<void>

  • Sets a single bucket meta property. Bucket meta properties cannot be mutated outside.

    Type Parameters

    • Key extends "count"

    Parameters

    • bucketIndex: number
    • key: Key
    • value: NodeBucketMeta[Key]
    • tran: DBTransaction

    Returns Promise<void>

  • Sets the connectedTime for a NodeId, replaces the old value if it exists

    Parameters

    • nodeId: NodeId
    • connectedTime: number
    • tran: DBTransaction
    • path: readonly (string | Buffer)[] = ...

    Returns Promise<void>

  • Sets a single NodeContact for a NodeId. This replaces the entire NodeContact for the NodeId. This will increment the bucket count if it is a new NodeID.

    Parameters

    Returns Promise<void>

    Throws

    If the bucket is full.

  • Sets a single NodeContactAddressData for a NodeId. This will increment the bucket count if it is a new NodeID.

    Parameters

    Returns Promise<void>

    Throws

    If the bucket is full.

  • Sets up the space key The space string is suffixed to the buckets and meta sublevels This is used to allow swapping of sublevels when remapping buckets during this.resetBuckets

    Parameters

    • tran: DBTransaction

    Returns Promise<NodeGraphSpace>

  • Parameters

    • __namedParameters: {
          fresh?: boolean;
      } = {}
      • Optional fresh?: boolean

    Returns Promise<void>

  • Unsets a NodeId record. It will decrement the bucket count if it existed.

    Parameters

    • nodeId: NodeId
    • Optional tran: DBTransaction

    Returns Promise<void>

  • Parameters

    • __namedParameters: {
          db: DB;
          fresh?: boolean;
          keyRing: KeyRing;
          logger?: Logger;
          nodeBucketLimit?: number;
          nodeContactAddressLimit?: number;
          nodeIdBits?: number;
      }
      • db: DB
      • Optional fresh?: boolean
      • keyRing: KeyRing
      • Optional logger?: Logger
      • Optional nodeBucketLimit?: number
      • Optional nodeContactAddressLimit?: number
      • Optional nodeIdBits?: number

    Returns Promise<NodeGraph>

Generated using TypeDoc