Extends
Methods
expire(callbackopt) → {Promise}
Items expire T_EXPIRE seconds after the original publication. All items are assigned an expiration time which is "exponentially inversely proportional to the number of nodes between the current node and the node whose ID is closest to the key", where this number is "inferred from the bucket structure of the current node".
Name | Type | Attributes | Description |
---|---|---|---|
callback | KademliaNode~expireCallback | <optional> |
- Source
- Type:
- Promise
iterativeFindNode(key, callbackopt) → {Promise.<Array.<Bucket~contact>>}
Basic kademlia lookup operation that builds a set of K contacts closest to the given key
Name | Type | Attributes | Description |
---|---|---|---|
key | buffer | | Reference key for node lookup | |
callback | KademliaNode~iterativeFindNodeCallback | <optional> |
- Source
- Type:
- Promise.<Array.<Bucket~contact>>
iterativeFindValue(key, callbackopt) → {Promise.<object>}
Kademlia search operation that is conducted as a node lookup and builds a list of K closest contacts. If at any time during the lookup the value is returned, the search is abandoned. If no value is found, the K closest contacts are returned. Upon success, we must store the value at the nearest node seen during the search that did not return the value.
Name | Type | Attributes | Description |
---|---|---|---|
key | buffer | | Key for value lookup | |
callback | KademliaNode~iterativeFindValueCallback | <optional> |
- Source
- Type:
- Promise.<object>
iterativeStore(key, value, callback) → {Promise.<number>}
Performs a KademliaNode#iterativeFindNode to collect K contacts nearest to the given key, sending a STORE message to each of them.
Name | Type | Description |
---|---|---|
key | buffer | | Key to store data under |
value | buffer | | Value to store by key |
callback | KademliaNode~iterativeStoreCallback |
- Source
- Type:
- Promise.<number>
join(peer, joinListeneropt) → {Promise}
Inserts the given contact into the routing table and uses it to perform a KademliaNode#iterativeFindNode for this node's identity, then refreshes all buckets further than it's closest neighbor, which will be in the occupied bucket with the lowest index
Name | Type | Attributes | Description |
---|---|---|---|
peer | Bucket~contact | Peer to bootstrap from | |
joinListener | function | <optional> | Function to set as join listener |
- Source
- Type:
- Promise
listen()
Adds the kademlia rule handlers before calling super#listen()
- Overrides
- Source
ping(peer, callbackopt) → {Promise.<number>}
Sends a PING message to the supplied contact, resolves with latency
Name | Type | Attributes | Description |
---|---|---|---|
peer | Bucket~contact | ||
callback | KademliaNode~pingCallback | <optional> |
- Source
- Type:
- Promise.<number>
plugin(plugin)
Accepts an arbitrary function that receives this node as context for mounting protocol handlers and extending the node with other methods
Name | Type | Description |
---|---|---|
plugin | function |
- Overrides
- Source
receive(request, response)
Processes a the given arguments by sending them through the appropriate middleware stack
Name | Type | Description |
---|---|---|
request | AbstractNode~request | |
response | AbstractNode~response |
- Overrides
- Source
refresh(startIndex, callbackopt) → {Promise}
If no node lookups have been performed in any given bucket's range for T_REFRESH, the node selects a random number in that range and does a refresh, an iterativeFindNode using that number as key.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
startIndex | number | 0 | bucket index to start refresh from | |
callback | KademliaNode~refreshCallback | <optional> |
- Source
- Type:
- Promise
replicate(callbackopt) → {Promise}
Performs a scan of the storage adapter and performs republishing/replication of items stored. Items that we did not publish ourselves get republished every T_REPLICATE. Items we did publish get republished every T_REPUBLISH.
Name | Type | Attributes | Description |
---|---|---|---|
callback | KademliaNode~replicateCallback | <optional> |
- Source
- Type:
- Promise
send(method, params, contact, callbackopt) → {Promise.<(object|array), Error>}
Sends the [method, params] to the contact and executes the handler on response or timeout
Name | Type | Attributes | Description |
---|---|---|---|
method | string | RPC method name | |
params | object | | RPC parameters | |
contact | Bucket~contact | Destination address information | |
callback | AbstractNode~sendCallback | <optional> |
- Overrides
- Source
- Type:
- Promise.<(object|array), Error>
use(methodopt, middleware)
Mounts a message handler route for processing incoming RPC messages
Name | Type | Attributes | Description |
---|---|---|---|
method | string | <optional> | RPC method name to route through |
middleware | AbstractNode~middleware |
- Overrides
- Source
Type Definitions
entry
- object
Name | Type | Description |
---|---|---|
value | string | | The primary entry value |
publisher | string | Node identity of the original publisher |
timestamp | number | Last update/replicate time |
- Source
expireCallback(error)
Name | Type | Description |
---|---|---|
error | error | |
- Source
iterativeFindNodeCallback(error, contacts)
Name | Type | Description |
---|---|---|
error | error | | |
contacts | Array.<Bucket~contact> | Result of the lookup operation |
- Source
iterativeFindValueCallback(error, value, contact)
Name | Type | Description |
---|---|---|
error | error | | |
value | KademliaNode~entry | |
contact | null | | Contact responded with entry |
- Source
iterativeStoreCallback(error, stored)
Note that if there is a protocol/validation error, you will not receive it as an error in the callback. Be sure to also check that stored > 0 as part of error handling here.
Name | Type | Description |
---|---|---|
error | error | | |
stored | number | Total nodes who stored the pair |
- Source
pingCallback(error, latency)
Name | Type | Description |
---|---|---|
error | error | | |
latency | number | Milliseconds before response received |
- Source
refreshCallback(error, bucketsRefreshed)
Name | Type | Description |
---|---|---|
error | error | | |
bucketsRefreshed | array |
- Source
replicateCallback(error)
Name | Type | Description |
---|---|---|
error | error | |
- Source
Events
error
Error event fires when a critical failure has occurred; if no handler is specified, then it will throw
- Error
- Overrides
- Source
join
Join event is triggered when the routing table is no longer empty
- Overrides
- Source