Class NodeGraph

Hierarchy

  • CreateDestroyStartStop
    • NodeGraph

Constructors

  • Parameters

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

    Returns NodeGraph

Properties

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

Max number of nodes in each k-bucket

nodeGraphBucketsDbPath: readonly (string | Buffer)[]
nodeGraphDbPath: readonly (string | Buffer)[] = ...
nodeGraphLastUpdatedDbPath: readonly (string | Buffer)[]
nodeGraphMetaDbPath: readonly (string | Buffer)[]
nodeIdBits: number

Bit size of the NodeIds This equals the 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]

  • 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 lastUpdated timestamp or by distance to the own NodeId

    Parameters

    • bucketIndex: number
    • sort: "nodeId" | "lastUpdated" | "distance" = 'nodeId'
    • order: "asc" | "desc" = 'asc'
    • Optional tran: DBTransaction

    Returns Promise<NodeBucket>

  • 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, lastUpdated asc NodeBucketIndex desc, lastUpdated desc

    Parameters

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

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

  • Finds the set of nodes (of size k) known by the current node (i.e. in its buckets' database) that have the smallest distance to the target node (i.e. are closest to the target node). i.e. FIND_NODE RPC from Kademlia spec

    Used by the RPC service.

    Parameters

    • nodeId: NodeId

      the node ID to find other nodes closest to it

    • limit: number = ...

      the number of the closest nodes to return (by default, returns according to the maximum number of nodes per bucket)

    • Optional tran: DBTransaction

    Returns Promise<NodeBucket>

    a mapping containing exactly k nodeIds -> nodeAddresses (unless the current node has less than k nodes in all of its buckets, in which case it returns all nodes it has knowledge of)

  • Get all nodes. Nodes are always sorted by NodeBucketIndex first Then secondly by the node IDs The order parameter applies to both, for example possible sorts: NodeBucketIndex asc, NodeID asc NodeBucketIndex desc, NodeId desc

    Parameters

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

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

  • Parameters

    • bucketIndex: number
    • limit: number = 1
    • Optional tran: DBTransaction

    Returns Promise<NodeId[]>

  • Parameters

    • bucketIndex: number
    • tran: DBTransaction

    Returns Promise<void>

  • Parameters

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

    Returns void

  • Parameters

    • nodeIdOwn: NodeId
    • Optional tran: DBTransaction

    Returns Promise<void>

  • Sets a bucket meta property This is protected because users cannot directly manipulate bucket meta

    Type Parameters

    • Key extends "count"

    Parameters

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

    Returns Promise<void>

  • Will add a node to the node graph and increment the bucket count. If the node already existed it will be updated.

    Parameters

    • nodeId: NodeId

      NodeId to add to the NodeGraph

    • nodeAddress: NodeAddress

      Address information to add

    • Optional tran: DBTransaction

    Returns Promise<void>

  • 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.refreshBuckets

    Parameters

    • tran: DBTransaction

    Returns Promise<NodeGraphSpace>

  • Parameters

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

    Returns Promise<void>

  • Parameters

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

    Returns Promise<NodeGraph>

Generated using TypeDoc