bip151: cleanup handshake properly.

This commit is contained in:
Christopher Jeffrey 2017-01-15 23:43:19 -08:00
parent 9affb11b22
commit 1e9b7363c2
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -323,6 +323,7 @@ function BIP151(cipher) {
this.timeout = null; this.timeout = null;
this.job = null; this.job = null;
this.onShake = null;
this.bip150 = null; this.bip150 = null;
} }
@ -472,8 +473,15 @@ BIP151.prototype.cleanup = function cleanup() {
this.completed = true; this.completed = true;
this.job = null; this.job = null;
clearTimeout(this.timeout); if (this.timeout != null) {
this.timeout = null; clearTimeout(this.timeout);
this.timeout = null;
}
if (this.onShake) {
this.removeListener('handshake', this.onShake);
this.onShake = null;
}
return job; return job;
}; };
@ -530,9 +538,8 @@ BIP151.prototype._wait = function wait(timeout, resolve, reject) {
self.reject(new Error('BIP151 handshake timed out.')); self.reject(new Error('BIP151 handshake timed out.'));
}, timeout); }, timeout);
this.once('handshake', function() { this.onShake = this.resolve.bind(this);
self.resolve(); this.once('handshake', this.onShake);
});
}; };
/** /**
@ -544,6 +551,11 @@ BIP151.prototype.destroy = function destroy() {
clearTimeout(this.timeout); clearTimeout(this.timeout);
this.timeout = null; this.timeout = null;
} }
if (this.onShake) {
this.removeListener('handshake', this.onShake);
this.onShake = null;
}
}; };
/** /**