From bd3d17ef531b377b1cadb2618a7467fa0977d9ca Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 19 May 2016 21:35:02 -0700 Subject: [PATCH] refactor. --- lib/bcoin/peer.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/bcoin/peer.js b/lib/bcoin/peer.js index 617d2d04..923b6626 100644 --- a/lib/bcoin/peer.js +++ b/lib/bcoin/peer.js @@ -98,7 +98,7 @@ function Peer(pool, options) { this.localNonce = utils.nonce(); this.filterRate = -1; - this.challenge = null; + this.challenge = utils.nonce(); this.lastPong = 0; this.banScore = 0; @@ -130,7 +130,7 @@ function Peer(pool, options) { map: {} }; - this.pings = { + this.ping = { timer: null, interval: this.options.pingInterval || 30000 }; @@ -186,13 +186,12 @@ Peer.prototype._init = function init() { self._error(err); }); - this.challenge = utils.nonce(); - - this.pings.timer = setInterval(function() { + this.ping.timer = setInterval(function() { + // self.challenge = utils.nonce(); self.write(self.framer.ping({ nonce: self.challenge })); - }, this.pings.interval); + }, this.ping.interval); this.request('verack', function(err, payload) { if (err) { @@ -263,7 +262,7 @@ Peer.prototype.createSocket = function createSocket(port, host) { 'Connecting to %s:%d (priority=%s).', hostname, this.priority); - socket.on('connect', function() { + socket.once('connect', function() { bcoin.debug( 'Connected to %s:%d (priority=%s).', hostname, self.priority); @@ -368,8 +367,8 @@ Peer.prototype.destroy = function destroy() { this.socket = null; this.emit('close'); - clearInterval(this.pings.timer); - this.pings.timer = null; + clearInterval(this.ping.timer); + this.ping.timer = null; Object.keys(this.requests.map).forEach(function(cmd) { var queue = this.requests.map[cmd];