kdns/protocol~ Protocol

new Protocol(router, extensionsopt)

Parameters:
NameTypeAttributesDescription
routermodule:kdns/router~Router

Routing table to use

extensionsObject.<string, function()><optional>

Additional custom RPC handlers to include

Members

events

Exposes events arising from handling protocol messages. Some of these events may require handling if they pass a Protocol~HandlerResponse

Properties
NameTypeDescription
eventsEventEmitter

router

Properties
NameTypeDescription
routermodule:kdns/router~Router

Methods

FIND_NODE(key, contact, respond)

The FIND_NODE RPC includes a 160-bit key. The recipient of the RPC returns up to K contacts that it knows to be closest to the key. The recipient must return K contacts if at all possible. It may only return fewer than K if it is returning all of the contacts that it has knowledge of.

Parameters:
NameTypeDescription
keystring

160 bit ID to search for

contactmodule:kdns/contacts~Contact

The peer who originated this RPC

respondmodule:kdns/protocol~HandlerResponse

Callback function for responding to RPC

FIND_VALUE(key, contact, respond)

A FIND_VALUE RPC includes a B=160-bit key. If a corresponding value is present on the recipient, the associated data is returned. Otherwise the RPC is equivalent to a FIND_NODE and a set of K contacts is returned.

Parameters:
NameTypeDescription
keystring

160 bit ID to search for

contactmodule:kdns/contacts~Contact

The peer who originated this RPC

respondmodule:kdns/protocol~HandlerResponse

Callback function for responding to RPC

PING(contact, respond)

This RPC involves one node sending a PING message to another, which presumably replies with a PONG. This has a two-fold effect: the recipient of the PING must update the bucket corresponding to the sender; and, if there is a reply, the sender must update the bucket appropriate to the recipient.

Parameters:
NameTypeDescription
contactmodule:kdns/contacts~Contact

The peer who originated this RPC

respondmodule:kdns/protocol~HandlerResponse

Callback function for responding to RPC

STORE(key, item, contact, respond)

The sender of the STORE RPC provides a key and a block of data and requires that the recipient store the data and make it available for later retrieval by that key.

Parameters:
NameTypeDescription
keystring

160 bit ID to address this blob by

itemmodule:kdns/node~StoredItem

Blob and metadata to store

contactmodule:kdns/contacts~Contact

The peer who originated this RPC

respondmodule:kdns/protocol~HandlerResponse

Callback function for responding to RPC

Events

storage_get

storage_put