From cd7a0a4acb7f1757468f9d75e62813ad77e5399d Mon Sep 17 00:00:00 2001 From: grunjol Date: Wed, 9 Mar 2016 14:01:31 -0300 Subject: [PATCH 1/3] limit (top) number of concurrent web seed connections --- README.md | 3 ++- lib/torrent.js | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bd3b8b0a..b810e769 100644 --- a/README.md +++ b/README.md @@ -275,7 +275,8 @@ If `opts` is specified, then the default options (shown below) will be overridde announce: [], // Torrent trackers to use (added to list in .torrent or magnet uri) getAnnounceOpts: function, // Custom callback to allow sending extra parameters to the tracker path: String, // Folder to download files to (default=`/tmp/webtorrent/`) - store: Function // Custom chunk store (must follow [abstract-chunk-store](https://www.npmjs.com/package/abstract-chunk-store) API) + store: Function // Custom chunk store (must follow [abstract-chunk-store](https://www.npmjs.com/package/abstract-chunk-store) API), + maxWebConns: Number // Max number of simultaneous connections per web seed } ``` diff --git a/lib/torrent.js b/lib/torrent.js index 206cd4c3..c1b46789 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -75,6 +75,8 @@ function Torrent (torrentId, client, opts) { this._getAnnounceOpts = opts.getAnnounceOpts this.strategy = opts.strategy || 'sequential' + + this.maxWebConns = opts.maxWebConns this._rechokeNumSlots = (opts.uploads === false || opts.uploads === 0) ? 0 @@ -1127,7 +1129,11 @@ Torrent.prototype._request = function (wire, index, hotswap) { if (self.bitfield.get(index)) return false var maxOutstandingRequests = getPipelineLength(wire, PIPELINE_MAX_DURATION) - if (isWebSeed && maxOutstandingRequests > 2) maxOutstandingRequests -= 2 // A webseed will handle it's real max requests + if (isWebSeed) { + // A webseed will handle it's real max requests + if (maxOutstandingRequests > 2) maxOutstandingRequests -= 2 + if (self.maxWebConns) maxOutstandingRequests = Math.min(maxOutstandingRequests, self.maxWebConns) + } if (numRequests >= maxOutstandingRequests) return false // var endGame = (wire.requests.length === 0 && self.store.numMissing < 30) From 001dc116d7695113d1219bcaf2ceba3d93de932d Mon Sep 17 00:00:00 2001 From: grunjol Date: Wed, 9 Mar 2016 14:01:31 -0300 Subject: [PATCH 2/3] limit (top) number of concurrent web seed connections --- README.md | 3 ++- lib/torrent.js | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bd3b8b0a..b810e769 100644 --- a/README.md +++ b/README.md @@ -275,7 +275,8 @@ If `opts` is specified, then the default options (shown below) will be overridde announce: [], // Torrent trackers to use (added to list in .torrent or magnet uri) getAnnounceOpts: function, // Custom callback to allow sending extra parameters to the tracker path: String, // Folder to download files to (default=`/tmp/webtorrent/`) - store: Function // Custom chunk store (must follow [abstract-chunk-store](https://www.npmjs.com/package/abstract-chunk-store) API) + store: Function // Custom chunk store (must follow [abstract-chunk-store](https://www.npmjs.com/package/abstract-chunk-store) API), + maxWebConns: Number // Max number of simultaneous connections per web seed } ``` diff --git a/lib/torrent.js b/lib/torrent.js index 206cd4c3..e93edc0a 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -76,6 +76,8 @@ function Torrent (torrentId, client, opts) { this.strategy = opts.strategy || 'sequential' + this.maxWebConns = opts.maxWebConns + this._rechokeNumSlots = (opts.uploads === false || opts.uploads === 0) ? 0 : (+opts.uploads || 10) @@ -1127,7 +1129,11 @@ Torrent.prototype._request = function (wire, index, hotswap) { if (self.bitfield.get(index)) return false var maxOutstandingRequests = getPipelineLength(wire, PIPELINE_MAX_DURATION) - if (isWebSeed && maxOutstandingRequests > 2) maxOutstandingRequests -= 2 // A webseed will handle it's real max requests + if (isWebSeed) { + // A webseed will handle it's real max requests + if (maxOutstandingRequests > 2) maxOutstandingRequests -= 2 + if (self.maxWebConns) maxOutstandingRequests = Math.min(maxOutstandingRequests, self.maxWebConns) + } if (numRequests >= maxOutstandingRequests) return false // var endGame = (wire.requests.length === 0 && self.store.numMissing < 30) From fa544326a037fcac49711a2271a4b7f62ad63641 Mon Sep 17 00:00:00 2001 From: grunjol Date: Wed, 9 Mar 2016 14:58:59 -0300 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b810e769..4235ac37 100644 --- a/README.md +++ b/README.md @@ -275,7 +275,7 @@ If `opts` is specified, then the default options (shown below) will be overridde announce: [], // Torrent trackers to use (added to list in .torrent or magnet uri) getAnnounceOpts: function, // Custom callback to allow sending extra parameters to the tracker path: String, // Folder to download files to (default=`/tmp/webtorrent/`) - store: Function // Custom chunk store (must follow [abstract-chunk-store](https://www.npmjs.com/package/abstract-chunk-store) API), + store: Function, // Custom chunk store (must follow [abstract-chunk-store](https://www.npmjs.com/package/abstract-chunk-store) API) maxWebConns: Number // Max number of simultaneous connections per web seed } ```