From 4c4cf9e6a4f5981ac00a5546948cbdc5eeba58c9 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 24 Feb 2017 02:21:20 -0800 Subject: [PATCH] peer: timeout inv spamming. --- lib/net/peer.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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; + } + } }; /**