src/net/pool.js
function Pool(options) {
  if (!(this instanceof Pool))
    return new Pool(options);

  AsyncObject.call(this);

  this.options = new PoolOptions(options);

  this.network = this.options.network;
  this.logger = this.options.logger.context('net');
  this.chain = this.options.chain;
  this.mempool = this.options.mempool;
  this.server = this.options.createServer();
  this.nonces = this.options.nonces;

  this.locker = new Lock(true);
  this.connected = false;
  this.disconnecting = false;
  this.syncing = false;
  this.spvFilter = null;
  this.txFilter = null;
  this.blockMap = new Set();
  this.txMap = new Set();
  this.compactBlocks = new Set();
  this.invMap = new Map();
  this.pendingFilter = null;
  this.pendingRefill = null;

  this.checkpoints = false;
  this.headerChain = new List();
  this.headerNext = null;
  this.headerTip = null;

  this.peers = new PeerList();
  this.authdb = new BIP150.AuthDB(this.options);
  this.hosts = new HostList(this.options);
  this.id = 0;

  if (this.options.spv)
    this.spvFilter = Bloom.fromRate(20000, 0.001, Bloom.flags.ALL);

  if (!this.options.mempool)
    this.txFilter = new RollingFilter(50000, 0.000001);

  this._init();
}
function Pool(options) {
  if (!(this instanceof Pool))
    return new Pool(options);

  AsyncObject.call(this);

  this.options = new PoolOptions(options);

  this.network = this.options.network;
  this.logger = this.options.logger.context('net');
  this.chain = this.options.chain;
  this.mempool = this.options.mempool;
  this.server = this.options.createServer();
  this.nonces = this.options.nonces;

  this.locker = new Lock(true);
  this.connected = false;
  this.disconnecting = false;
  this.syncing = false;
  this.spvFilter = null;
  this.txFilter = null;
  this.blockMap = new Set();
  this.txMap = new Set();
  this.compactBlocks = new Set();
  this.invMap = new Map();
  this.pendingFilter = null;
  this.pendingRefill = null;

  this.checkpoints = false;
  this.headerChain = new List();
  this.headerNext = null;
  this.headerTip = null;

  this.peers = new PeerList();
  this.authdb = new BIP150.AuthDB(this.options);
  this.hosts = new HostList(this.options);
  this.id = 0;

  if (this.options.spv)
    this.spvFilter = Bloom.fromRate(20000, 0.001, Bloom.flags.ALL);

  if (!this.options.mempool)
    this.txFilter = new RollingFilter(50000, 0.000001);

  this._init();
}
function Pool ( options ) { if ( ! ( this instanceof Pool ) ) return new Pool ( options ) ; AsyncObject . call ( this ) ; this . options = new PoolOptions ( options ) ; this . network = this . options . network ; this . logger = this . options . logger . context ( 'net' ) ; this . chain = this . options . chain ; this . mempool = this . options . mempool ; this . server = this . options . createServer ( ) ; this . nonces = this . options . nonces ; this . locker = new Lock ( true ) ; this . connected = false ; this . disconnecting = false ; this . syncing = false ; this . spvFilter = null ; this . txFilter = null ; this . blockMap = new Set ( ) ; this . txMap = new Set ( ) ; this . compactBlocks = new Set ( ) ; this . invMap = new Map ( ) ; this . pendingFilter = null ; this . pendingRefill = null ; this . checkpoints = false ; this . headerChain = new List ( ) ; this . headerNext = null ; this . headerTip = null ; this . peers = new PeerList ( ) ; this . authdb = new BIP150 . AuthDB ( this . options ) ; this . hosts = new HostList ( this . options ) ; this . id = 0 ; if ( this . options . spv ) this . spvFilter = Bloom . fromRate ( 20000 , 0.001 , Bloom . flags . ALL ) ; if ( ! this . options . mempool ) this . txFilter = new RollingFilter ( 50000 , 0.000001 ) ; this . _init ( ) ; }
A pool of peers for handling all network activity.
@alias module:net.Pool
@constructor
@param {Object} options
@param {Chain} options.chain
@param {Mempool?} options.mempool
@param {Number?} [options.maxOutbound=8] - Maximum number of peers.
@param {Boolean?} options.spv - Do an SPV sync.
@param {Boolean?} options.noRelay - Whether to ask
for relayed transactions.
@param {Number?} [options.feeRate] - Fee filter rate.
@param {Number?} [options.invTimeout=60000] - Timeout for broadcasted
objects.
@param {Boolean?} options.listen - Whether to spin up a server socket
and listen for peers.
@param {Boolean?} options.selfish - A selfish pool. Will not serve blocks,
headers, hashes, utxos, or transactions to peers.
@param {Boolean?} options.broadcast - Whether to automatically broadcast
transactions accepted to our mempool.
@param {String[]} options.seeds
@param {Function?} options.createSocket - Custom function to create a socket.
Must accept (port, host) and return a node-like socket.
@param {Function?} options.createServer - Custom function to create a server.
Must return a node-like server.
@emits Pool#block
@emits Pool#tx
@emits Pool#peer
@emits Pool#open
@emits Pool#close
@emits Pool#error
@emits Pool#reject
A pool of peers for handling all network activity .