From 23f9e543be31f3cda0ca65ab78bfca3897b812ba Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 23 Aug 2016 05:54:41 -0700 Subject: [PATCH] bip150/bip151: destroy on peer close. --- lib/bcoin/bip150.js | 7 +++++++ lib/bcoin/bip151.js | 11 +++++++++++ lib/bcoin/peer.js | 8 ++++++++ 3 files changed, 26 insertions(+) diff --git a/lib/bcoin/bip150.js b/lib/bcoin/bip150.js index c1de195e..25fa7a85 100644 --- a/lib/bcoin/bip150.js +++ b/lib/bcoin/bip150.js @@ -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.'); diff --git a/lib/bcoin/bip151.js b/lib/bcoin/bip151.js index 468666c7..09147536 100644 --- a/lib/bcoin/bip151.js +++ b/lib/bcoin/bip151.js @@ -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 diff --git a/lib/bcoin/peer.js b/lib/bcoin/peer.js index 1ea7a96d..2965a613 100644 --- a/lib/bcoin/peer.js +++ b/lib/bcoin/peer.js @@ -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) {