@torrent-tv/proxy 2.102.4 → 2.103.0

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torrent-tv/proxy",
3
- "version": "2.102.4",
3
+ "version": "2.103.0",
4
4
  "description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {
@@ -26,6 +26,7 @@ import { deriveSourceKey } from "../../utils/torrent-source-key.js";
26
26
  import { noteTorrentDestroyed } from "./destroyed-torrents.js";
27
27
  import { PieceTimings, describePieceTiming } from "./piece-timing.js";
28
28
  import { TailRepeat } from "./worker/tail-repeat.js";
29
+ import { tracePieceStorePut } from "./worker/trace-piece-store-put.js";
29
30
 
30
31
  /**
31
32
  * The second-peer requests for the last blocks of a piece somebody waits for,
@@ -1544,6 +1545,7 @@ export class TorrentPool {
1544
1545
  wrap("_onListening", "W1");
1545
1546
  wrap("_startDiscovery", "W2");
1546
1547
  wrap("_onStore", "W6");
1548
+ tracePieceStorePut(pieceStoreOf(torrent), trace);
1547
1549
  const verify = torrent._verifyPieces;
1548
1550
  if (typeof verify === "function") {
1549
1551
  torrent._verifyPieces = function (callback, ...args) {
@@ -0,0 +1,28 @@
1
+ /** Record the torrent worker's verified-piece storage write without changing its callback API. */
2
+ export function tracePieceStorePut(store, trace, now = () => performance.now()) {
3
+ const put = store?.put;
4
+ if (typeof put !== "function") return false;
5
+
6
+ store.put = function (index, bytes, callback) {
7
+ const startedAt = now();
8
+ const fields = { piece: index, bytes: bytes?.byteLength ?? bytes?.length ?? null, startedAt };
9
+ trace("W9", "begin", fields);
10
+ let finished = false;
11
+ const finish = error => {
12
+ if (finished) return;
13
+ finished = true;
14
+ const endedAt = now();
15
+ trace("W9", "end", { ...fields, endedAt, durationMs: endedAt - startedAt,
16
+ outcome: error ? "error" : "stored", ...(error ? { error: String(error?.message ?? error) } : {}) });
17
+ callback?.(error);
18
+ };
19
+
20
+ try {
21
+ return put.call(this, index, bytes, finish);
22
+ } catch (error) {
23
+ finish(error);
24
+ throw error;
25
+ }
26
+ };
27
+ return true;
28
+ }