refactor.

This commit is contained in:
Christopher Jeffrey 2016-05-19 21:35:02 -07:00
parent b4bfe53bfe
commit bd3d17ef53
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -98,7 +98,7 @@ function Peer(pool, options) {
this.localNonce = utils.nonce(); this.localNonce = utils.nonce();
this.filterRate = -1; this.filterRate = -1;
this.challenge = null; this.challenge = utils.nonce();
this.lastPong = 0; this.lastPong = 0;
this.banScore = 0; this.banScore = 0;
@ -130,7 +130,7 @@ function Peer(pool, options) {
map: {} map: {}
}; };
this.pings = { this.ping = {
timer: null, timer: null,
interval: this.options.pingInterval || 30000 interval: this.options.pingInterval || 30000
}; };
@ -186,13 +186,12 @@ Peer.prototype._init = function init() {
self._error(err); self._error(err);
}); });
this.challenge = utils.nonce(); this.ping.timer = setInterval(function() {
// self.challenge = utils.nonce();
this.pings.timer = setInterval(function() {
self.write(self.framer.ping({ self.write(self.framer.ping({
nonce: self.challenge nonce: self.challenge
})); }));
}, this.pings.interval); }, this.ping.interval);
this.request('verack', function(err, payload) { this.request('verack', function(err, payload) {
if (err) { if (err) {
@ -263,7 +262,7 @@ Peer.prototype.createSocket = function createSocket(port, host) {
'Connecting to %s:%d (priority=%s).', 'Connecting to %s:%d (priority=%s).',
hostname, this.priority); hostname, this.priority);
socket.on('connect', function() { socket.once('connect', function() {
bcoin.debug( bcoin.debug(
'Connected to %s:%d (priority=%s).', 'Connected to %s:%d (priority=%s).',
hostname, self.priority); hostname, self.priority);
@ -368,8 +367,8 @@ Peer.prototype.destroy = function destroy() {
this.socket = null; this.socket = null;
this.emit('close'); this.emit('close');
clearInterval(this.pings.timer); clearInterval(this.ping.timer);
this.pings.timer = null; this.ping.timer = null;
Object.keys(this.requests.map).forEach(function(cmd) { Object.keys(this.requests.map).forEach(function(cmd) {
var queue = this.requests.map[cmd]; var queue = this.requests.map[cmd];