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
path: root/lib
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2016-04-06 11:08:19 +0300
committerFeross Aboukhadijeh <feross@feross.org>2016-04-06 11:08:19 +0300
commit0b9a07d25701db863e878939c6521526c41c84ef (patch)
treef584606e4e6dfe23192c826a3f2242cbba649ef4 /lib
parent796e28ae66dec1d3ac7c21aaf85a76cbee1b3151 (diff)
Base web seed pipeline length on piece length
Before this, the web seed pipeline length was based on the block size, just like it is for wire connections, which are block-based. This meant that we were massively over-estimating the number of http requests to make to the web seed servers. Now we use the piece length, since each web seed request is a piece length in size.
Diffstat (limited to 'lib')
-rw-r--r--lib/torrent.js27
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/torrent.js b/lib/torrent.js
index 0f99ee9..7681da0 100644
--- a/lib/torrent.js
+++ b/lib/torrent.js
@@ -932,9 +932,9 @@ Torrent.prototype._updateWire = function (wire) {
if (wire.peerChoking) return
if (!wire.downloaded) return validateWire()
- var minOutstandingRequests = getPipelineLength(wire, PIPELINE_MIN_DURATION)
+ var minOutstandingRequests = getBlockPipelineLength(wire, PIPELINE_MIN_DURATION)
if (wire.requests.length >= minOutstandingRequests) return
- var maxOutstandingRequests = getPipelineLength(wire, PIPELINE_MAX_DURATION)
+ var maxOutstandingRequests = getBlockPipelineLength(wire, PIPELINE_MAX_DURATION)
trySelectWire(false) || trySelectWire(true)
@@ -1187,7 +1187,7 @@ Torrent.prototype._hotswap = function (wire, index) {
var req = minWire.requests[i]
if (req.piece !== index) continue
- self.pieces[index].cancel((req.offset / Piece.BLOCK_SIZE) | 0)
+ self.pieces[index].cancel((req.offset / Piece.BLOCK_LENGTH) | 0)
}
self.emit('hotswap', minWire, wire, index)
@@ -1204,12 +1204,13 @@ Torrent.prototype._request = function (wire, index, hotswap) {
if (self.bitfield.get(index)) return false
- var maxOutstandingRequests = getPipelineLength(wire, PIPELINE_MAX_DURATION)
- 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)
- }
+ var maxOutstandingRequests = isWebSeed
+ ? Math.min(
+ getPiecePipelineLength(wire, PIPELINE_MAX_DURATION, self.pieceLength),
+ self.maxWebConns
+ )
+ : getBlockPipelineLength(wire, PIPELINE_MAX_DURATION)
+
if (numRequests >= maxOutstandingRequests) return false
// var endGame = (wire.requests.length === 0 && self.store.numMissing < 30)
@@ -1383,8 +1384,12 @@ Torrent.prototype._debug = function () {
debug.apply(null, args)
}
-function getPipelineLength (wire, duration) {
- return Math.ceil(2 + duration * wire.downloadSpeed() / Piece.BLOCK_LENGTH)
+function getBlockPipelineLength (wire, duration) {
+ return 2 + Math.ceil(duration * wire.downloadSpeed() / Piece.BLOCK_LENGTH)
+}
+
+function getPiecePipelineLength (wire, duration, pieceLength) {
+ return 1 + Math.ceil(duration * wire.downloadSpeed() / pieceLength)
}
/**