net: fix peer error handling.
This commit is contained in:
parent
2beb9c06a5
commit
a23a5437a4
@ -912,7 +912,7 @@ Peer.prototype.needsDrain = function needsDrain(size) {
|
|||||||
|
|
||||||
if (this.drainSize >= (5 << 20)) {
|
if (this.drainSize >= (5 << 20)) {
|
||||||
this.logger.warning(
|
this.logger.warning(
|
||||||
'Peer is not reading: %s buffered (%s).',
|
'Peer is not reading: %dmb buffered (%s).',
|
||||||
util.mb(this.drainSize),
|
util.mb(this.drainSize),
|
||||||
this.hostname);
|
this.hostname);
|
||||||
this.destroy();
|
this.destroy();
|
||||||
@ -984,9 +984,6 @@ Peer.prototype.sendRaw = function sendRaw(cmd, body, checksum) {
|
|||||||
Peer.prototype.error = function error(err) {
|
Peer.prototype.error = function error(err) {
|
||||||
var i, args, msg;
|
var i, args, msg;
|
||||||
|
|
||||||
if (this.destroyed)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (typeof err === 'string') {
|
if (typeof err === 'string') {
|
||||||
args = new Array(arguments.length);
|
args = new Array(arguments.length);
|
||||||
|
|
||||||
@ -1534,39 +1531,39 @@ Peer.prototype.handleVersion = co(function* handleVersion(version) {
|
|||||||
this.ignore();
|
this.ignore();
|
||||||
throw new Error('Peer does not support network services.');
|
throw new Error('Peer does not support network services.');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (this.options.headers) {
|
if (this.options.headers) {
|
||||||
if (!version.hasHeaders()) {
|
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) {
|
|
||||||
this.ignore();
|
this.ignore();
|
||||||
throw new Error('Peer does not support segregated witness.');
|
throw new Error('Peer does not support getheaders.');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
if (this.options.spv) {
|
||||||
yield this.request('havewitness');
|
if (!version.hasBloom()) {
|
||||||
} catch (err) {
|
|
||||||
this.ignore();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user