Constructor
new RoutingTable(identity)
Constructs a routing table
Name | Type | Description |
---|---|---|
identity | buffer | Reference point for calculating distances |
- Source
Members
length
Returns the total buckets in the routing table
Name | Type | Description |
---|---|---|
length | number |
- Source
size
Returns the total contacts in the routing table
Name | Type | Description |
---|---|---|
size | number |
- Source
Methods
addContactByNodeId(nodeId, contact) → {array}
Adds the contact to the routing table in the proper bucket position, returning the [bucketIndex, bucket, contactIndex, contact]; if the returned contactIndex is -1, it indicates the bucket is full and the contact was not added; kademlia implementations should PING the contact at bucket.head to determine if it should be dropped before calling this method again
Name | Type | Description |
---|---|---|
nodeId | string | | Node identity to add |
contact | object | contact information for peer |
- Source
- Type:
- array
getClosestBucket() → {Bucket}
Returns the [index, bucket] of the occupied bucket with the lowest index
- Source
- Type:
- Bucket
getClosestContactsToKey(key, nopt, exclusiveopt) → {map}
Returns a array of N contacts closest to the supplied key
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
key | string | | Key to get buckets for | ||
n | number | <optional> | 20 | Number of results to return |
exclusive | boolean | <optional> | false | Exclude exact matches |
- Source
- Type:
- map
getContactByNodeId(nodeId) → {Bucket~contact}
Returns the contact object associated with the given node id
Name | Type | Description |
---|---|---|
nodeId | string | | Node identity of the contact |
- Source
- Type:
- Bucket~contact
indexOf(nodeId) → {number}
Returns the bucket index of the given node id
Name | Type | Description |
---|---|---|
nodeId | string | | Node identity to get index for |
- Source
- Type:
- number
removeContactByNodeId(nodeId) → {boolean}
Removes the contact from the routing table given a node id
Name | Type | Description |
---|---|---|
nodeId | string | | Node identity to remove |
- Source
- Type:
- boolean