From a23a5437a423af1b60df595f0086ea58df7f3208 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 16 Dec 2016 19:28:14 -0800 Subject: [PATCH] net: fix peer error handling. --- lib/net/peer.js | 57 +++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/lib/net/peer.js b/lib/net/peer.js index 44553d12..273da7f1 100644 --- a/lib/net/peer.js +++ b/lib/net/peer.js @@ -912,7 +912,7 @@ Peer.prototype.needsDrain = function needsDrain(size) { if (this.drainSize >= (5 << 20)) { this.logger.warning( - 'Peer is not reading: %s buffered (%s).', + 'Peer is not reading: %dmb buffered (%s).', util.mb(this.drainSize), this.hostname); this.destroy(); @@ -984,9 +984,6 @@ Peer.prototype.sendRaw = function sendRaw(cmd, body, checksum) { Peer.prototype.error = function error(err) { var i, args, msg; - if (this.destroyed) - return; - if (typeof err === 'string') { args = new Array(arguments.length); @@ -1534,39 +1531,39 @@ Peer.prototype.handleVersion = co(function* handleVersion(version) { this.ignore(); throw new Error('Peer does not support network services.'); } - } - if (this.options.headers) { - if (!version.hasHeaders()) { - this.ignore(); - throw new Error('Peer does not support getheaders.'); - } - } - - if (this.options.spv) { - if (!version.hasBloom()) { - this.ignore(); - throw new Error('Peer does not support BIP37.'); - } - } - - if (this.options.witness) { - this.haveWitness = version.hasWitness(); - - if (!this.haveWitness) { - if (!this.network.oldWitness) { + if (this.options.headers) { + if (!version.hasHeaders()) { this.ignore(); - throw new Error('Peer does not support segregated witness.'); + throw new Error('Peer does not support getheaders.'); } + } - try { - yield this.request('havewitness'); - } catch (err) { + if (this.options.spv) { + if (!version.hasBloom()) { this.ignore(); - throw new Error('Peer does not support segregated witness.'); + throw new Error('Peer does not support BIP37.'); } + } - this.haveWitness = true; + if (this.options.witness) { + this.haveWitness = version.hasWitness(); + + if (!this.haveWitness) { + if (!this.network.oldWitness) { + this.ignore(); + throw new Error('Peer does not support segregated witness.'); + } + + try { + yield this.request('havewitness'); + } catch (err) { + this.ignore(); + throw new Error('Peer does not support segregated witness.'); + } + + this.haveWitness = true; + } } }