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:
authorPaul-Louis Ageneau <paul-louis@ageneau.org>2022-01-20 17:55:18 +0300
committerGitHub <noreply@github.com>2022-01-20 17:55:18 +0300
commit8de2a136d68366d298e3ec01b5e4b17a4c4e074c (patch)
tree2bc1198f1ba989a764d59a0b2099bdc528285ad8 /lib
parentb60fe362c8870423e5127f6c67ce7546cc2c0ad7 (diff)
feat: add reqq field support (#2246)
Diffstat (limited to 'lib')
-rw-r--r--lib/torrent.js18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/torrent.js b/lib/torrent.js
index 1bb0062..99947eb 100644
--- a/lib/torrent.js
+++ b/lib/torrent.js
@@ -1464,7 +1464,8 @@ class Torrent extends EventEmitter {
piece = self._rarityMap.getRarestPiece(filter)
if (piece < 0) break
- while (self._request(wire, piece, self._critical[piece] || hotswap)) {
+ while (self._request(wire, piece, self._critical[piece] || hotswap) &&
+ wire.requests.length < maxOutstandingRequests) {
// body intentionally empty
// request all non-reserved blocks in this piece
}
@@ -1482,7 +1483,8 @@ class Torrent extends EventEmitter {
for (piece = next.from + next.offset; piece <= next.to; piece++) {
if (!wire.peerPieces.get(piece) || !rank(piece)) continue
- while (self._request(wire, piece, self._critical[piece] || hotswap)) {
+ while (self._request(wire, piece, self._critical[piece] || hotswap) &&
+ wire.requests.length < maxOutstandingRequests) {
// body intentionally empty
// request all non-reserved blocks in piece
}
@@ -1920,7 +1922,17 @@ class Torrent extends EventEmitter {
}
function getBlockPipelineLength (wire, duration) {
- return 2 + Math.ceil(duration * wire.downloadSpeed() / Piece.BLOCK_LENGTH)
+ let length = 2 + Math.ceil(duration * wire.downloadSpeed() / Piece.BLOCK_LENGTH)
+
+ // Honor reqq (maximum number of outstanding request messages) if specified by peer
+ if (wire.peerExtendedHandshake) {
+ const reqq = wire.peerExtendedHandshake.reqq
+ if (typeof reqq === 'number' && reqq > 0) {
+ length = Math.min(length, reqq)
+ }
+ }
+
+ return length
}
function getPiecePipelineLength (wire, duration, pieceLength) {