new Router(identity)
Kademlia routing table consisting of module:kdns/constants~B total module:kdns/bucket~Buckets - each holding up to module:kdns/constants~K total module:kdns/contacts~Contacts.
Name | Type | Description |
---|---|---|
identity | buffer | Reference point for calculating distances |
Extends
- Map
Members
events
Exposes events arising from handling protocol messages. Some of these events may require handling if they pass a Protocol~HandlerResponse
Name | Type | Description |
---|---|---|
events | EventEmitter | Router events interface |
identity
Exposes events arising from handling protocol messages. Some of these events may require handling if they pass a Protocol~HandlerResponse
Name | Type | Description |
---|---|---|
identity | buffer | Reference key for distance calculation |
length
The total buckets in the routing table
Name | Type | Description |
---|---|---|
length | number |
size
The total contacts in the routing table
Name | Type | Description |
---|---|---|
size | number |
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 | module:kdns/contacts~Contact | Contact information for peer |
- Type:
- array
getClosestBucket() → {module:kdns/bucket~Bucket}
Returns the [index, bucket] of the occupied bucket with the lowest index
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 |
- Type:
- Map
getContactByNodeId(nodeId) → {module:kdns/contacts~Contact}
Returns the contact object associated with the given node id
Name | Type | Description |
---|---|---|
nodeId | string | | Node identity of the contact |
indexOf(nodeId) → {number}
Returns the bucket index of the given node id
Name | Type | Description |
---|---|---|
nodeId | string | | Node identity to get index for |
- Type:
- number
removeContactByNodeId(nodeId) → {undefined}
Removes the contact from the routing table given a node id
Name | Type | Description |
---|---|---|
nodeId | string | | Node identity to remove |
- Type:
- undefined
Events
contact_added
Contact is inserted into the routing table
Name | Type | Description |
---|---|---|
fingerprint | string | Node ID of the inserted contact |
contact_deleted
Contact is evicted from the routing table
Name | Type | Description |
---|---|---|
fingerprint | string | Node ID of the evicted contact |