Class: KademliaNode

KademliaNode

Extends AbstractNode with Kademlia-specific rules

new KademliaNode()

Source:

Extends

Methods


expire( [callback])

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".
Parameters:
Name Type Argument Description
callback KademliaNode~expireCallback <optional>
Source:

iterativeFindNode(key, callback)

Basic kademlia lookup operation that builds a set of K contacts closest to the given key
Parameters:
Name Type Description
key buffer | string Reference key for node lookup
callback KademliaNode~iterativeFindNodeCallback
Source:

iterativeFindValue(key, callback)

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.
Parameters:
Name Type Description
key buffer | string Key for value lookup
callback KademliaNode~iterativeFindValueCallback
Source:

iterativeStore(key, value, callback)

Performs a KademliaNode#iterativeFindNode to collect K contacts nearest to the given key, sending a STORE message to each of them.
Parameters:
Name Type Description
key buffer | string Key to store data under
value buffer | string | object Value to store by key
callback KademliaNode~iterativeStoreCallback
Source:

join(peer [, joinListener])

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
Parameters:
Name Type Argument Description
peer Bucket~contact Peer to bootstrap from
joinListener function <optional>
Function to set as join listener
Source:
Fires:

listen()

Adds the kademlia rule handlers before calling super#listen()
Overrides:
Source:

ping(peer, callback)

Sends a PING message to the supplied contact
Parameters:
Name Type Description
peer Bucket~contact
callback KademliaNode~pingCallback
Source:

plugin(plugin)

Accepts an arbitrary function that receives this node as context for mounting protocol handlers and extending the node with other methods
Parameters:
Name Type Description
plugin function Using and Authoring Plugins
Inherited From:
Source:

receive(request, response)

Processes a the given arguments by sending them through the appropriate middleware stack
Parameters:
Name Type Description
request AbstractNode~request
response AbstractNode~response
Inherited From:
Source:

refresh(startIndex [, callback])

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.
Parameters:
Name Type Argument Default Description
startIndex number 0 bucket index to start refresh from
callback KademliaNode~refreshCallback <optional>
Source:

replicate( [callback])

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.
Parameters:
Name Type Argument Description
callback KademliaNode~replicateCallback <optional>
Source:

send(method, params, contact [, callback])

Sends the [method, params] to the contact and executes the handler on response or timeout
Parameters:
Name Type Argument Description
method string RPC method name
params object | array RPC parameters
contact Bucket~contact Destination address information
callback AbstractNode~sendCallback <optional>
Inherited From:
Source:

use( [method], middleware)

Mounts a message handler route for processing incoming RPC messages
Parameters:
Name Type Argument Description
method string <optional>
RPC method name to route through
middleware AbstractNode~middleware
Inherited From:
Source:

Type Definitions


entry

Type:
  • object
Properties:
Name Type Description
value string | object | array The primary entry value
publisher string Node identity of the original publisher
timestamp number Last update/replicate time
Source:

expireCallback(error, itemsExpired)

Parameters:
Name Type Description
error error | null
itemsExpired number
Source:

iterativeFindNodeCallback(error, contacts)

Parameters:
Name Type Description
error error | null
contacts Array.<Bucket~contact> Result of the lookup operation
Source:

iterativeFindValueCallback(error, value, contact)

Parameters:
Name Type Description
error error | null
value KademliaNode~entry
contact null | Bucket~contact 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.
Parameters:
Name Type Description
error error | null
stored number Total nodes who stored the pair
Source:

pingCallback(error, latency)

Parameters:
Name Type Description
error error | null
latency number Milliseconds before response received
Source:

refreshCallback(error, bucketsRefreshed)

Parameters:
Name Type Description
error error | null
bucketsRefreshed array
Source:

replicateCallback(error, itemsReplicated)

Parameters:
Name Type Description
error error | null
itemsReplicated number
Source:

Events


error

Error event fires when a critical failure has occurred; if no handler is specified, then it will throw
Type: Error
Inherited From:
Source:

join

Join event is triggered when the routing table is no longer empty
Inherited From:
Source: