@torrent-tv/proxy 2.102.3 → 2.102.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -38,6 +38,7 @@ export class PieceTimings {
|
|
|
38
38
|
*/
|
|
39
39
|
asked(piece, offset, peer, now) {
|
|
40
40
|
let record = this.#pieces.get(piece);
|
|
41
|
+
const firstAsk = !record;
|
|
41
42
|
if (!record) {
|
|
42
43
|
record = { firstAskAt: now, asks: 0, peers: new Set(), blocks: new Map(), arrived: new Set(), askedAgain: 0, arrivedTwice: 0,
|
|
43
44
|
slowestMs: 0, slowestPeer: null, lastInFlightMs: 0, lastPeer: null };
|
|
@@ -47,6 +48,7 @@ export class PieceTimings {
|
|
|
47
48
|
record.peers.add(peer);
|
|
48
49
|
if (!record.blocks.has(offset)) record.blocks.set(offset, now);
|
|
49
50
|
else record.askedAgain += 1;
|
|
51
|
+
return firstAsk;
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
/**
|
|
@@ -1603,6 +1603,7 @@ export class TorrentPool {
|
|
|
1603
1603
|
// its blocks were in flight, and from whom (`piece-timing.js`). One line
|
|
1604
1604
|
// per piece: a 2.3 GB film is 563.
|
|
1605
1605
|
const timings = new PieceTimings();
|
|
1606
|
+
const waitTracePieceStarts = new Map();
|
|
1606
1607
|
tailRepeats.set(torrent, new TailRepeat({ torrent, requiredPieces: () => demandFor(torrent).selection.requiredPieces(),
|
|
1607
1608
|
log: (line) => logger.info(`download ${label()} ${line}`) }));
|
|
1608
1609
|
torrent.on("wire", (wire) => {
|
|
@@ -1616,9 +1617,13 @@ export class TorrentPool {
|
|
|
1616
1617
|
const queued = this.requests.length;
|
|
1617
1618
|
const answer = request.call(this, index, offset, length, callback);
|
|
1618
1619
|
if (this.requests.length > queued) {
|
|
1619
|
-
trace("W8", "event", { moment: "block-requested", piece: index, offset, length, peer });
|
|
1620
1620
|
const now = Date.now();
|
|
1621
|
-
timings.asked(index, offset, peer, now);
|
|
1621
|
+
const firstAsk = timings.asked(index, offset, peer, now);
|
|
1622
|
+
if (firstAsk) {
|
|
1623
|
+
const startedAt = performance.now();
|
|
1624
|
+
waitTracePieceStarts.set(index, startedAt);
|
|
1625
|
+
trace("W8", "begin", { piece: index, startedAt, firstOffset: offset, blockLength: length });
|
|
1626
|
+
}
|
|
1622
1627
|
// When this wire was asked for the block: how long it has held it is
|
|
1623
1628
|
// what decides whether a second peer is asked (`duplicateTailFor`).
|
|
1624
1629
|
this.requests.at(-1).askedAt = now;
|
|
@@ -1627,11 +1632,19 @@ export class TorrentPool {
|
|
|
1627
1632
|
};
|
|
1628
1633
|
wire.on("piece", (index, offset) => {
|
|
1629
1634
|
timings.arrived(index, offset, peer, Date.now());
|
|
1630
|
-
trace("W8", "event", { moment: "block-received", piece: index, offset, peer });
|
|
1631
1635
|
});
|
|
1632
1636
|
});
|
|
1633
1637
|
torrent.on("verified", (piece) => {
|
|
1634
|
-
|
|
1638
|
+
const pieceTiming = timings.verified(piece, Date.now());
|
|
1639
|
+
const startedAt = waitTracePieceStarts.get(piece);
|
|
1640
|
+
if (startedAt !== undefined) {
|
|
1641
|
+
waitTracePieceStarts.delete(piece);
|
|
1642
|
+
const endedAt = performance.now();
|
|
1643
|
+
trace("W8", "end", { piece, startedAt, endedAt, durationMs: endedAt - startedAt,
|
|
1644
|
+
outcome: "verified", asks: pieceTiming?.asks ?? null, peers: pieceTiming?.peers ?? null,
|
|
1645
|
+
askedAgain: pieceTiming?.askedAgain ?? null, slowestBlockMs: pieceTiming?.slowestMs ?? null });
|
|
1646
|
+
}
|
|
1647
|
+
logger.info(`download ${label()} verified piece=${piece}${describePieceTiming(pieceTiming)}`);
|
|
1635
1648
|
});
|
|
1636
1649
|
|
|
1637
1650
|
// The first connected peer, said once, because the wait for it can BE the
|