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.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];