peer: throw on destroyed write.

This commit is contained in:
Christopher Jeffrey 2017-01-20 17:40:06 -08:00
parent f0f9f798c5
commit 08b41a2dc4
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 16 additions and 3 deletions

View File

@ -280,6 +280,9 @@ Peer.prototype._init = function init() {
self.destroy();
});
this.bip151.on('rekey', function() {
if (self.destroyed)
return;
self.logger.debug('Rekeying with peer (%s).', self.hostname);
self.send(self.bip151.toRekey());
});
@ -764,6 +767,9 @@ Peer.prototype.flushInv = function flushInv() {
var items = [];
var i, item, chunk;
if (this.destroyed)
return;
if (queue.length === 0)
return;
@ -1026,7 +1032,7 @@ Peer.prototype.destroy = function destroy() {
Peer.prototype.write = function write(data) {
if (this.destroyed)
return;
throw new Error('Peer is destroyed (write).');
this.lastSend = util.ms();
@ -1250,6 +1256,9 @@ Peer.prototype.wait = function wait(type, timeout) {
Peer.prototype.send = function send(packet) {
var tx, checksum;
if (this.destroyed)
throw new Error('Peer is destroyed (send).');
// Used cached hashes as the
// packet checksum for speed.
if (packet.type === packetTypes.TX) {

View File

@ -1255,8 +1255,12 @@ Pool.prototype.handleGetData = co(function* handleGetData(peer, packet) {
var unknown = -1;
var i, j, item, tx, block, result, height;
if (items.length > 50000)
throw new Error('getdata size too large (' + items.length + ').');
if (items.length > 50000) {
this.logger.warning('Peer sent a inv >50k items (%s).', peer.hostname);
peer.increaseBan(100);
peer.destroy();
return;
}
for (i = 0; i < items.length; i++) {
item = items[i];