diff --git a/lib/net/peer.js b/lib/net/peer.js index 3bff434a..c024d58d 100644 --- a/lib/net/peer.js +++ b/lib/net/peer.js @@ -199,6 +199,14 @@ Peer.RESPONSE_TIMEOUT = 30000; Peer.BLOCK_TIMEOUT = 60000; +/** + * Max number of requested items. + * @const {Number} + * @default + */ + +Peer.MAX_REQUESTS = 5000; + /** * Create inbound peer from socket. * @param {PeerOptions} options @@ -1307,6 +1315,14 @@ Peer.prototype.maybeTimeout = function maybeTimeout() { return; } } + + if (this.options.isFull()) { + if (this.requestMap.size > Peer.MAX_REQUESTS) { + this.error('Peer is stalling (data).'); + this.destroy(); + return; + } + } }; /**