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

  EventEmitter.call(this);

  this.options = options;
  this.network = this.options.network;
  this.logger = this.options.logger.context('peer');
  this.locker = new Lock();

  this.parser = new Parser(this.network);
  this.framer = new Framer(this.network);

  this.id = -1;
  this.socket = null;
  this.opened = false;
  this.outbound = false;
  this.loader = false;
  this.address = new NetAddress();
  this.local = new NetAddress();
  this.connected = false;
  this.destroyed = false;
  this.ack = false;
  this.handshake = false;
  this.time = 0;
  this.lastSend = 0;
  this.lastRecv = 0;
  this.drainSize = 0;
  this.drainQueue = [];
  this.banScore = 0;
  this.invQueue = [];
  this.onPacket = null;

  this.next = null;
  this.prev = null;

  this.version = -1;
  this.services = 0;
  this.height = -1;
  this.agent = null;
  this.noRelay = false;
  this.preferHeaders = false;
  this.hashContinue = null;
  this.spvFilter = null;
  this.feeRate = -1;
  this.bip151 = null;
  this.bip150 = null;
  this.compactMode = -1;
  this.compactWitness = false;
  this.merkleBlock = null;
  this.merkleTime = -1;
  this.merkleMatches = 0;
  this.merkleMap = null;
  this.syncing = false;
  this.sentAddr = false;
  this.sentGetAddr = false;
  this.challenge = null;
  this.lastPong = -1;
  this.lastPing = -1;
  this.minPing = -1;
  this.blockTime = -1;

  this.bestHash = null;
  this.bestHeight = -1;

  this.connectTimeout = null;
  this.pingTimer = null;
  this.invTimer = null;
  this.stallTimer = null;

  this.addrFilter = new RollingFilter(5000, 0.001);
  this.invFilter = new RollingFilter(50000, 0.000001);

  this.blockMap = new Map();
  this.txMap = new Map();
  this.responseMap = new Map();
  this.compactBlocks = new Map();

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

  EventEmitter.call(this);

  this.options = options;
  this.network = this.options.network;
  this.logger = this.options.logger.context('peer');
  this.locker = new Lock();

  this.parser = new Parser(this.network);
  this.framer = new Framer(this.network);

  this.id = -1;
  this.socket = null;
  this.opened = false;
  this.outbound = false;
  this.loader = false;
  this.address = new NetAddress();
  this.local = new NetAddress();
  this.connected = false;
  this.destroyed = false;
  this.ack = false;
  this.handshake = false;
  this.time = 0;
  this.lastSend = 0;
  this.lastRecv = 0;
  this.drainSize = 0;
  this.drainQueue = [];
  this.banScore = 0;
  this.invQueue = [];
  this.onPacket = null;

  this.next = null;
  this.prev = null;

  this.version = -1;
  this.services = 0;
  this.height = -1;
  this.agent = null;
  this.noRelay = false;
  this.preferHeaders = false;
  this.hashContinue = null;
  this.spvFilter = null;
  this.feeRate = -1;
  this.bip151 = null;
  this.bip150 = null;
  this.compactMode = -1;
  this.compactWitness = false;
  this.merkleBlock = null;
  this.merkleTime = -1;
  this.merkleMatches = 0;
  this.merkleMap = null;
  this.syncing = false;
  this.sentAddr = false;
  this.sentGetAddr = false;
  this.challenge = null;
  this.lastPong = -1;
  this.lastPing = -1;
  this.minPing = -1;
  this.blockTime = -1;

  this.bestHash = null;
  this.bestHeight = -1;

  this.connectTimeout = null;
  this.pingTimer = null;
  this.invTimer = null;
  this.stallTimer = null;

  this.addrFilter = new RollingFilter(5000, 0.001);
  this.invFilter = new RollingFilter(50000, 0.000001);

  this.blockMap = new Map();
  this.txMap = new Map();
  this.responseMap = new Map();
  this.compactBlocks = new Map();

  this._init();
}
function Peer ( options ) { if ( ! ( this instanceof Peer ) ) return new Peer ( options ) ; EventEmitter . call ( this ) ; this . options = options ; this . network = this . options . network ; this . logger = this . options . logger . context ( 'peer' ) ; this . locker = new Lock ( ) ; this . parser = new Parser ( this . network ) ; this . framer = new Framer ( this . network ) ; this . id = - 1 ; this . socket = null ; this . opened = false ; this . outbound = false ; this . loader = false ; this . address = new NetAddress ( ) ; this . local = new NetAddress ( ) ; this . connected = false ; this . destroyed = false ; this . ack = false ; this . handshake = false ; this . time = 0 ; this . lastSend = 0 ; this . lastRecv = 0 ; this . drainSize = 0 ; this . drainQueue = [ ] ; this . banScore = 0 ; this . invQueue = [ ] ; this . onPacket = null ; this . next = null ; this . prev = null ; this . version = - 1 ; this . services = 0 ; this . height = - 1 ; this . agent = null ; this . noRelay = false ; this . preferHeaders = false ; this . hashContinue = null ; this . spvFilter = null ; this . feeRate = - 1 ; this . bip151 = null ; this . bip150 = null ; this . compactMode = - 1 ; this . compactWitness = false ; this . merkleBlock = null ; this . merkleTime = - 1 ; this . merkleMatches = 0 ; this . merkleMap = null ; this . syncing = false ; this . sentAddr = false ; this . sentGetAddr = false ; this . challenge = null ; this . lastPong = - 1 ; this . lastPing = - 1 ; this . minPing = - 1 ; this . blockTime = - 1 ; this . bestHash = null ; this . bestHeight = - 1 ; this . connectTimeout = null ; this . pingTimer = null ; this . invTimer = null ; this . stallTimer = null ; this . addrFilter = new RollingFilter ( 5000 , 0.001 ) ; this . invFilter = new RollingFilter ( 50000 , 0.000001 ) ; this . blockMap = new Map ( ) ; this . txMap = new Map ( ) ; this . responseMap = new Map ( ) ; this . compactBlocks = new Map ( ) ; this . _init ( ) ; }
Represents a remote peer.
@alias module:net.Peer
@constructor
@param {PeerOptions} options
@property {net.Socket} socket
@property {NetAddress} address
@property {Parser} parser
@property {Framer} framer
@property {Number} version
@property {Boolean} destroyed
@property {Boolean} ack - Whether verack has been received.
@property {Boolean} connected
@property {Number} time
@property {Boolean} preferHeaders - Whether the peer has
requested getheaders.
@property {Hash?} hashContinue - The block hash at which to continue
the sync for the peer.
@property {Bloom?} spvFilter - The _peer's_ bloom spvFilter.
@property {Boolean} noRelay - Whether to relay transactions
immediately to the peer.
@property {BN} challenge - Local nonce.
@property {Number} lastPong - Timestamp for last `pong`
received (unix time).
@property {Number} lastPing - Timestamp for last `ping`
sent (unix time).
@property {Number} minPing - Lowest ping time seen.
@property {Number} banScore
@emits Peer#ack
Represents a remote peer .