diff options
author | grunjol <grunjol@argenteam.net> | 2016-03-09 20:01:31 +0300 |
---|---|---|
committer | grunjol <grunjol@argenteam.net> | 2016-03-09 20:06:30 +0300 |
commit | 001dc116d7695113d1219bcaf2ceba3d93de932d (patch) | |
tree | fb7cc77963cfbfa5cea0ba52bd983e18f272a9c8 | |
parent | 7094638b2ebb612b81919c33fb9619d7e1c453c5 (diff) |
limit (top) number of concurrent web seed connections
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | lib/torrent.js | 8 |
2 files changed, 9 insertions, 2 deletions
@@ -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 206cd4c..e93edc0 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) |