bip150/bip151: destroy on peer close.

This commit is contained in:
Christopher Jeffrey 2016-08-23 05:54:41 -07:00
parent db07d42803
commit 23f9e543be
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 26 additions and 0 deletions

View File

@ -237,6 +237,13 @@ BIP150.prototype.findAuthorized = function findAuthorized(hash) {
}
};
BIP150.prototype.destroy = function destroy() {
if (this.timeout != null) {
clearTimeout(this.timeout);
this.timeout = null;
}
};
BIP150.prototype.complete = function complete(err) {
assert(!this.completed, 'Already completed.');
assert(this.callback, 'No completion callback.');

View File

@ -677,6 +677,17 @@ BIP151.prototype.wait = function wait(timeout, callback) {
});
};
/**
* Destroy BIP151 state and streams.
*/
BIP151.prototype.destroy = function destroy() {
if (this.timeout != null) {
clearTimeout(this.timeout);
this.timeout = null;
}
};
/**
* Feed ciphertext payload chunk
* to the input stream. Potentially

View File

@ -698,8 +698,16 @@ Peer.prototype.destroy = function destroy() {
this.destroyed = true;
this.connected = false;
this.socket.destroy();
this.socket = null;
if (this.bip151)
this.bip151.destroy();
if (this.bip150)
this.bip150.destroy();
this.emit('close');
if (this.ping.timer) {