AbstractNode

Represents a network node

Constructor

new AbstractNode(options)

Contructs the primary interface for a kad node

Parameters:
NameTypeDescription
optionsobject
Properties
NameTypeAttributesDescription
transportAbstractNode~transport

See Transport Adapters

identitybuffer

See Contacts and Identities

contactBucket~contact

See Contacts and Identities

storageAbstractNode~storage

See storage-adapters

loggerAbstractNode~logger<optional>
messengerMessenger<optional>

See Message Format

Methods

listen()

Passes through to the AbstractNode~transport

plugin(plugin)

Accepts an arbitrary function that receives this node as context for mounting protocol handlers and extending the node with other methods

Parameters:
NameTypeDescription
pluginfunction

Using and Authoring Plugins

receive(request, response)

Processes a the given arguments by sending them through the appropriate middleware stack

Parameters:
NameTypeDescription
requestAbstractNode~request
responseAbstractNode~response

send(method, params, contact, callbackopt) → {Promise.<(object|array), Error>}

Sends the [method, params] to the contact and executes the handler on response or timeout

Parameters:
NameTypeAttributesDescription
methodstring

RPC method name

paramsobject | array

RPC parameters

contactBucket~contact

Destination address information

callbackAbstractNode~sendCallback<optional>
Returns:
Type: 
Promise.<(object|array), Error>

use(methodopt, middleware)

Mounts a message handler route for processing incoming RPC messages

Parameters:
NameTypeAttributesDescription
methodstring<optional>

RPC method name to route through

middlewareAbstractNode~middleware

(inner) responseError(errorMessage, errorCodeopt)

Parameters:
NameTypeAttributesDescription
errorMessagestring

Text describing the error encountered

errorCodenumber<optional>

Error code

(inner) responseSend(results)

Parameters:
NameTypeDescription
resultsarray | object

Result parameters to respond with

Type Definitions

logger

Type:
  • object
Properties
NameTypeDescription
debugfunction

Passed string of debug information

infofunction

Passed string of general information

warnfunction

Passed string of warnings

errorfunction

Passed string of error message

middleware(erroropt, request, response, next)

Parameters:
NameTypeAttributesDescription
errorerror<optional>

Error object resulting from a middleware

requestAbstractNode~request

The incoming message object

responseAbstractNode~response

The outgoing response object

nextAbstractNode~next

Call to proceed to next middleware

next(error)

Parameters:
NameTypeDescription
errorerror | null

Indicates to exit the middleware stack

request

Properties
NameTypeDescription
contactarray

Peer who sent this request

Properties
NameTypeDescription
0string

Peer's node identity

1object

Peer's contact information (varies by plugin)

paramsarray | object

Method parameters (varies by method)

methodstring

Method name being called

response

Properties

sendCallback(error, result)

Parameters:
NameTypeDescription
errornull | AbstractNode~sendError
resultobject | array | string | number

sendError

Properties
NameTypeDescription
messagestring

Error description

typestring

Error type

requestobject

Request the error is from

Properties
NameTypeDescription
idstring

Message id

paramsarray

Parameters sent

targetBucket~contact

Contact message was for

methodstring

RPC method in message

storage

Implements a subset of the LevelUP interface

Type:
  • object
Properties
NameTypeDescription
getfunction
putfunction
delfunction
createReadStreamfunction

transport

Type:
  • object
Properties
NameTypeDescription
readfunction

Returns raw message buffer if available

writefunction

Passed raw message buffer

Events

error

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

Type:
  • Error

join

Join event is triggered when the routing table is no longer empty