more DOS protection.

This commit is contained in:
Christopher Jeffrey 2016-01-20 12:04:38 -08:00
parent ddbb7894fa
commit 03c117b009

View File

@ -490,8 +490,16 @@ Pool.prototype._handleBlocks = function _handleBlocks(hashes, peer) {
for (i = 0; i < hashes.length; i++) {
hash = hashes[i];
// Resolve orphan chain
if (this.chain.hasOrphan(hash)) {
// Make sure the peer doesn't send us
// more than 200 orphans every 3 minutes.
if (this.orphaning(peer)) {
this.emit('debug', 'Peer is orphaning (%s)', peer.host);
this.misbehaving(peer, 100);
return;
}
// Resolve orphan chain.
peer.loadBlocks(
this.chain.locatorHashes(),
this.chain.getOrphanRoot(hash)
@ -542,7 +550,7 @@ Pool.prototype._handleInv = function _handleInv(hashes, peer) {
Pool.prototype._handleBlock = function _handleBlock(block, peer) {
var self = this;
var requested, hasPrev;
var requested;
// Fulfill our request.
requested = this._response(block);
@ -566,7 +574,9 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer) {
// Ensure this is not a continuation
// of an invalid chain.
if (this.block.invalid[block.prevBlock]) {
this.emit('debug', 'Peer is sending an invalid chain (%s)', peer.host);
this.emit('debug',
'Peer is sending an invalid continuation chain (%s)',
peer.host);
this.misbehaving(peer, 100);
return false;
}
@ -604,7 +614,7 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer) {
return false;
// Make sure the peer doesn't send us
// more than 100 orphans every 3 minutes.
// more than 200 orphans every 3 minutes.
if (this.orphaning(peer)) {
this.emit('debug', 'Peer is orphaning (%s)', peer.host);
this.misbehaving(peer, 100);
@ -618,6 +628,7 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer) {
if (this._addIndex(block, peer))
this.emit('pool block', block, peer);
// Resolve orphan chain.
this.peers.load.loadBlocks(
this.chain.locatorHashes(),
this.chain.getOrphanRoot(block)
@ -629,6 +640,11 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer) {
}
} else {
if (!this.chain.hasBlock(block.prevBlock)) {
// Special case for genesis block.
if (block.isGenesis())
return false;
// Increase banscore by 10 if we're using getheaders.
if (!this.options.multiplePeers) {
if (this.misbehaving(peer, 10))
return false;
@ -1688,7 +1704,7 @@ Pool.prototype.orphaning = function orphaning(peer) {
peer._orphans += 1;
if (peer._orphans > 100)
if (peer._orphans > 200)
return true;
return false;