more DOS protection.
This commit is contained in:
parent
ddbb7894fa
commit
03c117b009
@ -490,8 +490,16 @@ Pool.prototype._handleBlocks = function _handleBlocks(hashes, peer) {
|
|||||||
for (i = 0; i < hashes.length; i++) {
|
for (i = 0; i < hashes.length; i++) {
|
||||||
hash = hashes[i];
|
hash = hashes[i];
|
||||||
|
|
||||||
// Resolve orphan chain
|
|
||||||
if (this.chain.hasOrphan(hash)) {
|
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(
|
peer.loadBlocks(
|
||||||
this.chain.locatorHashes(),
|
this.chain.locatorHashes(),
|
||||||
this.chain.getOrphanRoot(hash)
|
this.chain.getOrphanRoot(hash)
|
||||||
@ -542,7 +550,7 @@ Pool.prototype._handleInv = function _handleInv(hashes, peer) {
|
|||||||
|
|
||||||
Pool.prototype._handleBlock = function _handleBlock(block, peer) {
|
Pool.prototype._handleBlock = function _handleBlock(block, peer) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var requested, hasPrev;
|
var requested;
|
||||||
|
|
||||||
// Fulfill our request.
|
// Fulfill our request.
|
||||||
requested = this._response(block);
|
requested = this._response(block);
|
||||||
@ -566,7 +574,9 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer) {
|
|||||||
// Ensure this is not a continuation
|
// Ensure this is not a continuation
|
||||||
// of an invalid chain.
|
// of an invalid chain.
|
||||||
if (this.block.invalid[block.prevBlock]) {
|
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);
|
this.misbehaving(peer, 100);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -604,7 +614,7 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer) {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Make sure the peer doesn't send us
|
// 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)) {
|
if (this.orphaning(peer)) {
|
||||||
this.emit('debug', 'Peer is orphaning (%s)', peer.host);
|
this.emit('debug', 'Peer is orphaning (%s)', peer.host);
|
||||||
this.misbehaving(peer, 100);
|
this.misbehaving(peer, 100);
|
||||||
@ -618,6 +628,7 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer) {
|
|||||||
if (this._addIndex(block, peer))
|
if (this._addIndex(block, peer))
|
||||||
this.emit('pool block', block, peer);
|
this.emit('pool block', block, peer);
|
||||||
|
|
||||||
|
// Resolve orphan chain.
|
||||||
this.peers.load.loadBlocks(
|
this.peers.load.loadBlocks(
|
||||||
this.chain.locatorHashes(),
|
this.chain.locatorHashes(),
|
||||||
this.chain.getOrphanRoot(block)
|
this.chain.getOrphanRoot(block)
|
||||||
@ -629,6 +640,11 @@ Pool.prototype._handleBlock = function _handleBlock(block, peer) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!this.chain.hasBlock(block.prevBlock)) {
|
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.options.multiplePeers) {
|
||||||
if (this.misbehaving(peer, 10))
|
if (this.misbehaving(peer, 10))
|
||||||
return false;
|
return false;
|
||||||
@ -1688,7 +1704,7 @@ Pool.prototype.orphaning = function orphaning(peer) {
|
|||||||
|
|
||||||
peer._orphans += 1;
|
peer._orphans += 1;
|
||||||
|
|
||||||
if (peer._orphans > 100)
|
if (peer._orphans > 200)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user