diff --git a/lib/bcoin/peer.js b/lib/bcoin/peer.js index a5b54908..2ab5c9b6 100644 --- a/lib/bcoin/peer.js +++ b/lib/bcoin/peer.js @@ -1515,6 +1515,11 @@ Peer.prototype._handleInv = function _handleInv(items) { var txs = []; var i, item, unknown; + if (items.length > 50000) { + this.setMisbehavior(100); + return; + } + for (i = 0; i < items.length; i++) { item = items[i]; if (item.type === constants.inv.TX) { @@ -1541,6 +1546,11 @@ Peer.prototype._handleInv = function _handleInv(items) { }; Peer.prototype._handleHeaders = function _handleHeaders(headers) { + if (headers.length > 2000) { + this.setMisbehavior(100); + return; + } + headers = headers.map(function(header) { return new bcoin.headers(header); }); diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index e5cd3910..b4842809 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -574,11 +574,6 @@ Pool.prototype._handleHeaders = function _handleHeaders(headers, peer, callback) headers.length, peer.hostname); - if (headers.length > 2000) { - peer.setMisbehavior(100); - return callback(); - } - this.emit('headers', headers); if (peer === this.peers.load) { @@ -639,13 +634,6 @@ Pool.prototype._handleBlocks = function _handleBlocks(hashes, peer, callback) { hashes.length, peer.hostname); - // Normally this is 500, but with older - // versions locator.GetDistanceBack() is called. - if (hashes.length > 500) { - peer.setMisbehavior(100); - return; - } - this.emit('blocks', hashes); if (peer === this.peers.load) {