src/kad/node.js
function Node (options) {
  if (!(this instanceof Node)) {
    return new Node(options)
  }

  events.EventEmitter.call(this)
  this._setStorageAdapter(options.storage)

  this._log = options.logger
  this._rpc = options.transport
  this._self = this._rpc._contact
  this._validator = options.validator

  this._router = options.router || new Router({
    logger: this._log,
    transport: this._rpc,
    validator: this._validateKeyValuePair.bind(this)
  })

  this._bindRouterEventHandlers()
  this._bindRPCMessageHandlers()
  this._startReplicationInterval()
  this._startExpirationInterval()
  this._log.info('node created', {
    nodeID: this._self.nodeID
  })
}
function Node (options) {
  if (!(this instanceof Node)) {
    return new Node(options)
  }

  events.EventEmitter.call(this)
  this._setStorageAdapter(options.storage)

  this._log = options.logger
  this._rpc = options.transport
  this._self = this._rpc._contact
  this._validator = options.validator

  this._router = options.router || new Router({
    logger: this._log,
    transport: this._rpc,
    validator: this._validateKeyValuePair.bind(this)
  })

  this._bindRouterEventHandlers()
  this._bindRPCMessageHandlers()
  this._startReplicationInterval()
  this._startExpirationInterval()
  this._log.info('node created', {
    nodeID: this._self.nodeID
  })
}
Represents a Kademlia node
@constructor
@param {Object} options
@param {Router} options.router - Custom router instance to use
@param {RPC} options.transport - Transport (RPC) adapter to use
@param {Object} options.storage - Storage adapter to use
@param {Logger} options.logger - Logger instance to use
@param {Node~validator} options.validator - Key-Value validation function
@emits Node#join
@emits Node#leave
@emits Node#connect
@emits Node#disconnect
@emits Node#error