Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgrunjol <grunjol@argenteam.net>2016-03-09 20:01:31 +0300
committergrunjol <grunjol@argenteam.net>2016-03-09 20:06:30 +0300
commit001dc116d7695113d1219bcaf2ceba3d93de932d (patch)
treefb7cc77963cfbfa5cea0ba52bd983e18f272a9c8
parent7094638b2ebb612b81919c33fb9619d7e1c453c5 (diff)
limit (top) number of concurrent web seed connections
-rw-r--r--README.md3
-rw-r--r--lib/torrent.js8
2 files changed, 9 insertions, 2 deletions
diff --git a/README.md b/README.md
index bd3b8b0..b810e76 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 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)