set misbehavior for inv and headers.

This commit is contained in:
Christopher Jeffrey 2016-06-12 01:50:24 -07:00
parent 9ccac80ad6
commit 08f5865e78
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 10 additions and 12 deletions

View File

@ -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);
});

View File

@ -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) {