lib/application.js
function Application(options) {
  var self = this;

  if (!(self instanceof Application)) {
    return new Application(options);
  }

  stream.Duplex.call(self, { objectMode: true });

  self.id = hat();
  self.server = net.createServer(self._handleInbound.bind(self));
  self.options = merge(Object.create(Application.DEFAULTS), options);
  self.connections = { inbound: [], outbound: [] };

  // setup middlware stack with initial entry a simple passthrough
  self.stack = [function(socket) {
    return through(function(data) {
      this.queue(data);
    });
  }];

  Object.defineProperty(self, 'log', {
    value: this.options.logger || {
      info: NOOP, warn: NOOP, error: NOOP
    }
  });

  // connect to seeds
  self._enterNetwork();
  setInterval(self._enterNetwork.bind(self), self.options.retryInterval);
}
function Application(options) {
  var self = this;

  if (!(self instanceof Application)) {
    return new Application(options);
  }

  stream.Duplex.call(self, { objectMode: true });

  self.id = hat();
  self.server = net.createServer(self._handleInbound.bind(self));
  self.options = merge(Object.create(Application.DEFAULTS), options);
  self.connections = { inbound: [], outbound: [] };

  // setup middlware stack with initial entry a simple passthrough
  self.stack = [function(socket) {
    return through(function(data) {
      this.queue(data);
    });
  }];

  Object.defineProperty(self, 'log', {
    value: this.options.logger || {
      info: NOOP, warn: NOOP, error: NOOP
    }
  });

  // connect to seeds
  self._enterNetwork();
  setInterval(self._enterNetwork.bind(self), self.options.retryInterval);
}
function Application ( options ) { var self = this ; if ( ! ( self instanceof Application ) ) { return new Application ( options ) ; } stream . Duplex . call ( self , { objectMode : true } ) ; self . id = hat ( ) ; self . server = net . createServer ( self . _handleInbound . bind ( self ) ) ; self . options = merge ( Object . create ( Application . DEFAULTS ) , options ) ; self . connections = { inbound : [ ] , outbound : [ ] } ; // setup middlware stack with initial entry a simple passthrough self . stack = [ function ( socket ) { return through ( function ( data ) { this . queue ( data ) ; } ) ; } ] ; Object . defineProperty ( self , 'log' , { value : this . options . logger || { info : NOOP , warn : NOOP , error : NOOP } } ) ; // connect to seeds self . _enterNetwork ( ) ; setInterval ( self . _enterNetwork . bind ( self ) , self . options . retryInterval ) ; }
P2P application framework
@constructor
@param {object} options
P2P application framework