peer: throw on destroyed write.
This commit is contained in:
parent
f0f9f798c5
commit
08b41a2dc4
@ -280,6 +280,9 @@ Peer.prototype._init = function init() {
|
|||||||
self.destroy();
|
self.destroy();
|
||||||
});
|
});
|
||||||
this.bip151.on('rekey', function() {
|
this.bip151.on('rekey', function() {
|
||||||
|
if (self.destroyed)
|
||||||
|
return;
|
||||||
|
|
||||||
self.logger.debug('Rekeying with peer (%s).', self.hostname);
|
self.logger.debug('Rekeying with peer (%s).', self.hostname);
|
||||||
self.send(self.bip151.toRekey());
|
self.send(self.bip151.toRekey());
|
||||||
});
|
});
|
||||||
@ -764,6 +767,9 @@ Peer.prototype.flushInv = function flushInv() {
|
|||||||
var items = [];
|
var items = [];
|
||||||
var i, item, chunk;
|
var i, item, chunk;
|
||||||
|
|
||||||
|
if (this.destroyed)
|
||||||
|
return;
|
||||||
|
|
||||||
if (queue.length === 0)
|
if (queue.length === 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -1026,7 +1032,7 @@ Peer.prototype.destroy = function destroy() {
|
|||||||
|
|
||||||
Peer.prototype.write = function write(data) {
|
Peer.prototype.write = function write(data) {
|
||||||
if (this.destroyed)
|
if (this.destroyed)
|
||||||
return;
|
throw new Error('Peer is destroyed (write).');
|
||||||
|
|
||||||
this.lastSend = util.ms();
|
this.lastSend = util.ms();
|
||||||
|
|
||||||
@ -1250,6 +1256,9 @@ Peer.prototype.wait = function wait(type, timeout) {
|
|||||||
Peer.prototype.send = function send(packet) {
|
Peer.prototype.send = function send(packet) {
|
||||||
var tx, checksum;
|
var tx, checksum;
|
||||||
|
|
||||||
|
if (this.destroyed)
|
||||||
|
throw new Error('Peer is destroyed (send).');
|
||||||
|
|
||||||
// Used cached hashes as the
|
// Used cached hashes as the
|
||||||
// packet checksum for speed.
|
// packet checksum for speed.
|
||||||
if (packet.type === packetTypes.TX) {
|
if (packet.type === packetTypes.TX) {
|
||||||
|
|||||||
@ -1255,8 +1255,12 @@ Pool.prototype.handleGetData = co(function* handleGetData(peer, packet) {
|
|||||||
var unknown = -1;
|
var unknown = -1;
|
||||||
var i, j, item, tx, block, result, height;
|
var i, j, item, tx, block, result, height;
|
||||||
|
|
||||||
if (items.length > 50000)
|
if (items.length > 50000) {
|
||||||
throw new Error('getdata size too large (' + items.length + ').');
|
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++) {
|
for (i = 0; i < items.length; i++) {
|
||||||
item = items[i];
|
item = items[i];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user