Class: AbstractNode

AbstractNode

Represents a network node

new AbstractNode(options)

Contructs the primary interface for a kad node
Parameters:
Name Type Description
options object
Properties
Name Type Argument Description
transport AbstractNode~transport See Transport Adapters
identity buffer See Contacts and Identities
contact Bucket~contact See Contacts and Identities
storage AbstractNode~storage See storage-adapters
logger AbstractNode~logger <optional>
messenger Messenger <optional>
See Message Format
Source:

Methods


listen()

Passes through to the AbstractNode~transport
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
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
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>
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
Source:

<inner> responseError(errorMessage [, errorCode])

Parameters:
Name Type Argument Description
errorMessage string Text describing the error encountered
errorCode number <optional>
Error code
Source:

<inner> responseSend(results)

Parameters:
Name Type Description
results array | object Result parameters to respond with
Source:

Type Definitions


logger

Type:
  • object
Properties:
Name Type Description
debug function Passed string of debug information
info function Passed string of general information
warn function Passed string of warnings
error function Passed string of error message
Source:

middleware( [error], request, response, next)

Parameters:
Name Type Argument Description
error error <optional>
Error object resulting from a middleware
request AbstractNode~request The incoming message object
response AbstractNode~response The outgoing response object
next AbstractNode~next Call to proceed to next middleware
Source:

next(error)

Parameters:
Name Type Description
error error | null Indicates to exit the middleware stack
Source:

request

Properties:
Name Type Description
contact array Peer who sent this request
Properties
Name Type Description
0 string Peer's node identity
1 object Peer's contact information (varies by plugin)
params array | object Method parameters (varies by method)
method string Method name being called
Source:

response

Properties:
Name Type Description
send AbstractNode~responseSend
error AbstractNode~responseError
Source:

sendCallback(error, result)

Parameters:
Name Type Description
error null | AbstractNode~sendError
result object | array | string | number
Source:

sendError

Properties:
Name Type Description
message string Error description
type string Error type
request object Request the error is from
Properties
Name Type Description
id string Message id
params array Parameters sent
target Bucket~contact Contact message was for
method string RPC method in message
Source:

storage

Implements a subset of the LevelUP interface
Type:
  • object
Properties:
Name Type Description
get function
put function
del function
createReadStream function
Source:

transport

Type:
  • object
Properties:
Name Type Description
read function Returns raw message buffer if available
write function Passed raw message buffer
Source:

Events


error

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

join

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