@torrent-tv/proxy 2.89.16 → 2.89.18

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.
Files changed (299) hide show
  1. package/README.md +14 -3
  2. package/package.json +10 -2
  3. package/routes/api/client-logs/post.js +9 -2
  4. package/server.js +0 -11
  5. package/.claude/commands/opsx/apply.md +0 -155
  6. package/.claude/commands/opsx/archive.md +0 -160
  7. package/.claude/commands/opsx/explore.md +0 -174
  8. package/.claude/commands/opsx/propose.md +0 -109
  9. package/.claude/commands/opsx/sync.md +0 -143
  10. package/.claude/skills/openspec-apply-change/SKILL.md +0 -159
  11. package/.claude/skills/openspec-archive-change/SKILL.md +0 -117
  12. package/.claude/skills/openspec-explore/SKILL.md +0 -289
  13. package/.claude/skills/openspec-propose/SKILL.md +0 -113
  14. package/.claude/skills/openspec-sync-specs/SKILL.md +0 -147
  15. package/.dockerignore +0 -5
  16. package/AGENTS.md +0 -363
  17. package/CHANGELOG.md +0 -2373
  18. package/Dockerfile +0 -30
  19. package/biome.json +0 -412
  20. package/corpus.tmp.json +0 -1
  21. package/docs/browser-proxy-contract.md +0 -155
  22. package/docs/container-architecture.md +0 -273
  23. package/docs/download-architecture.md +0 -261
  24. package/docs/encode-architecture.md +0 -765
  25. package/docs/encode-run-state.md +0 -96
  26. package/docs/logs.md +0 -138
  27. package/docs/playback-start-forecast.md +0 -113
  28. package/docs/socks5-egress-research.md +0 -114
  29. package/docs/storage-architecture.md +0 -273
  30. package/knip.json +0 -14
  31. package/main2.cpuprofile +0 -1
  32. package/openspec/changes/adaptive-bitrate/.openspec.yaml +0 -0
  33. package/openspec/changes/adaptive-bitrate/design.md +0 -92
  34. package/openspec/changes/adaptive-bitrate/proposal.md +0 -56
  35. package/openspec/changes/adaptive-bitrate/specs/adaptive-bitrate/spec.md +0 -51
  36. package/openspec/changes/adaptive-bitrate/tasks.md +0 -40
  37. package/openspec/changes/binary-distribution/.openspec.yaml +0 -2
  38. package/openspec/changes/binary-distribution/proposal.md +0 -53
  39. package/openspec/changes/chunked-request-bodies/design.md +0 -81
  40. package/openspec/changes/chunked-request-bodies/proposal.md +0 -53
  41. package/openspec/changes/chunked-request-bodies/specs/chunked-request-bodies/spec.md +0 -30
  42. package/openspec/changes/chunked-request-bodies/tasks.md +0 -40
  43. package/openspec/changes/cold-start/design.md +0 -98
  44. package/openspec/changes/cold-start/proposal.md +0 -62
  45. package/openspec/changes/cold-start/specs/cold-start/spec.md +0 -47
  46. package/openspec/changes/cold-start/tasks.md +0 -48
  47. package/openspec/changes/disk-cap/.openspec.yaml +0 -2
  48. package/openspec/changes/disk-cap/proposal.md +0 -37
  49. package/openspec/changes/disk-cap/specs/disk-cap/spec.md +0 -25
  50. package/openspec/changes/disk-cap/tasks.md +0 -19
  51. package/openspec/changes/proxy-observability/.openspec.yaml +0 -2
  52. package/openspec/changes/proxy-observability/design.md +0 -38
  53. package/openspec/changes/proxy-observability/proposal.md +0 -49
  54. package/openspec/changes/proxy-observability/specs/observability/spec.md +0 -33
  55. package/openspec/changes/proxy-observability/tasks.md +0 -21
  56. package/openspec/changes/seek-debounce/.openspec.yaml +0 -0
  57. package/openspec/changes/seek-debounce/design.md +0 -118
  58. package/openspec/changes/seek-debounce/proposal.md +0 -59
  59. package/openspec/changes/seek-debounce/specs/seek-debounce/spec.md +0 -41
  60. package/openspec/changes/seek-debounce/tasks.md +0 -33
  61. package/openspec/changes/subtitle-language/.openspec.yaml +0 -2
  62. package/openspec/changes/subtitle-language/proposal.md +0 -50
  63. package/openspec/changes/subtitle-language/specs/subtitle-language/spec.md +0 -34
  64. package/openspec/changes/subtitle-language/tasks.md +0 -26
  65. package/openspec/changes/track-selection/.openspec.yaml +0 -2
  66. package/openspec/changes/track-selection/design.md +0 -47
  67. package/openspec/changes/track-selection/proposal.md +0 -45
  68. package/openspec/changes/track-selection/specs/track-selection/spec.md +0 -41
  69. package/openspec/changes/track-selection/tasks.md +0 -20
  70. package/openspec/changes/transcode-quality/.openspec.yaml +0 -2
  71. package/openspec/changes/transcode-quality/proposal.md +0 -51
  72. package/openspec/changes/transcode-quality/specs/transcode-quality/spec.md +0 -139
  73. package/openspec/changes/transcode-quality/tasks.md +0 -63
  74. package/openspec/config.yaml +0 -38
  75. package/public/.well-known/appspecific/com.chrome.devtools.json +0 -1
  76. package/research/delivery-wedge-stand-ladder-2026-09-13.md +0 -329
  77. package/research/double-spawn-2026-09-10.md +0 -171
  78. package/research/handover-2026-09-13.md +0 -209
  79. package/research/handover-reader-claims-removal-2026-09-12.md +0 -166
  80. package/research/piece-withdrawn-but-still-claimed-2026-09-12.md +0 -175
  81. package/research/preset-benchmark-size-scaling-2026-08-22.md +0 -55
  82. package/research/priority-map-is-the-truth-2026-09-12.md +0 -225
  83. package/research/valgrind-replica-2026-08-27/logs.tar.gz +0 -0
  84. package/scripts/build-audio-samples.mjs +0 -31
  85. package/scripts/render-run-graph.js +0 -173
  86. package/test/asset-paths.test.js +0 -28
  87. package/test/audio-buffer-continuity.test.js +0 -77
  88. package/test/audio-calibration.test.js +0 -23
  89. package/test/audio-inventory.test.js +0 -212
  90. package/test/audio-track-bitrate.test.js +0 -40
  91. package/test/audio-warm-recorded.test.js +0 -63
  92. package/test/auto-quality-step.test.js +0 -762
  93. package/test/available-share.test.js +0 -76
  94. package/test/background-fill.test.js +0 -190
  95. package/test/client-log-file.test.js +0 -126
  96. package/test/coalesce.test.js +0 -39
  97. package/test/completed-files.test.js +0 -115
  98. package/test/concurrent-cost.test.js +0 -148
  99. package/test/container-media-info.test.js +0 -228
  100. package/test/contention.test.js +0 -76
  101. package/test/core-dumps.test.js +0 -57
  102. package/test/coverage-follows-the-disk.test.js +0 -233
  103. package/test/coverage-map.test.js +0 -195
  104. package/test/cue-push-carries-what-the-walk-found.test.js +0 -58
  105. package/test/cut-times-timeline.test.js +0 -65
  106. package/test/cuts-follow-published-grid.test.js +0 -109
  107. package/test/data-channel-frame.test.js +0 -63
  108. package/test/data-channel-viewer-lifecycle.test.js +0 -193
  109. package/test/dead-torrent-handle.test.js +0 -52
  110. package/test/declared-rates.test.js +0 -116
  111. package/test/declared-tracks.test.js +0 -43
  112. package/test/decode-cost-fit.test.js +0 -202
  113. package/test/decode-cost.test.js +0 -475
  114. package/test/delivery-probe-field.test.js +0 -173
  115. package/test/delivery-probe.test.js +0 -382
  116. package/test/demand-register.test.js +0 -206
  117. package/test/dht-bootstrap.test.js +0 -72
  118. package/test/drain-threat.test.js +0 -65
  119. package/test/duplicate-add.test.js +0 -48
  120. package/test/encode-admission.test.js +0 -170
  121. package/test/encode-cost.test.js +0 -275
  122. package/test/encode-exit.test.js +0 -111
  123. package/test/encode-orchestrator.test.js +0 -426
  124. package/test/encode-plan-viewers.test.js +0 -725
  125. package/test/encode-plan.test.js +0 -545
  126. package/test/encode-run-state.test.js +0 -314
  127. package/test/encode-run.test.js +0 -248
  128. package/test/encode-slope.test.js +0 -46
  129. package/test/encoded-output.test.js +0 -39
  130. package/test/encoder-kinds.test.js +0 -122
  131. package/test/encoder-readings.test.js +0 -68
  132. package/test/episode-naming.test.js +0 -131
  133. package/test/every-claimant-is-told-its-share.test.js +0 -152
  134. package/test/failed-encoder-still-serves-what-exists.test.js +0 -354
  135. package/test/failed-start-breaker.test.js +0 -202
  136. package/test/fastest-wires.test.js +0 -143
  137. package/test/ffmpeg-stream-counts.test.js +0 -101
  138. package/test/file-edges.test.js +0 -191
  139. package/test/files-in-use.test.js +0 -34
  140. package/test/fixtures/audio-frame-boundary.json +0 -1
  141. package/test/fixtures/refused-audio-20261002.json +0 -10
  142. package/test/fmp4-presentation-clock.test.js +0 -148
  143. package/test/fmp4-self-contained.test.js +0 -80
  144. package/test/fmp4-timestamps.test.js +0 -140
  145. package/test/fmp4-track-completeness.test.js +0 -41
  146. package/test/format-keyed-outputs.test.js +0 -78
  147. package/test/health-metrics.test.js +0 -36
  148. package/test/held-read-ownership.test.js +0 -77
  149. package/test/held-request-width.test.js +0 -157
  150. package/test/helpers/encode-run.js +0 -248
  151. package/test/helpers/held-file.js +0 -77
  152. package/test/helpers/manager.js +0 -62
  153. package/test/helpers/matroska-file.js +0 -296
  154. package/test/helpers/output-spec.js +0 -63
  155. package/test/host-load.test.js +0 -68
  156. package/test/index-accuracy-is-about-the-file.test.js +0 -128
  157. package/test/init-compat.test.js +0 -219
  158. package/test/input-lost-quiets-the-plan.test.js +0 -261
  159. package/test/input-unavailable.test.js +0 -48
  160. package/test/installation-id.test.js +0 -39
  161. package/test/keeping-period.test.js +0 -83
  162. package/test/keyframe-index-accuracy.test.js +0 -188
  163. package/test/keyframe-table-budget.test.js +0 -123
  164. package/test/keyframes-belong-to-the-file.test.js +0 -249
  165. package/test/learned-median.test.js +0 -37
  166. package/test/letting-go-asks-who-is-watching.test.js +0 -191
  167. package/test/limit-row-by-area.test.js +0 -60
  168. package/test/link-budget.test.js +0 -111
  169. package/test/link-probe.test.js +0 -56
  170. package/test/local-encoding-data.test.js +0 -273
  171. package/test/logger-repeats.test.js +0 -134
  172. package/test/look-ahead-coverage.test.js +0 -56
  173. package/test/manager-surface.test.js +0 -291
  174. package/test/matroska-blocks.test.js +0 -0
  175. package/test/matroska-cluster-discovery.test.js +0 -323
  176. package/test/matroska-cues-track.test.js +0 -192
  177. package/test/media-time.test.js +0 -62
  178. package/test/memory-budget.test.js +0 -390
  179. package/test/move-cost.test.js +0 -216
  180. package/test/mp4-composition-times.test.js +0 -0
  181. package/test/mp4-subtitles.test.js +0 -173
  182. package/test/one-authority.test.js +0 -285
  183. package/test/one-budget.test.js +0 -149
  184. package/test/one-output-one-session.test.js +0 -273
  185. package/test/one-resource-divided.test.js +0 -185
  186. package/test/one-serving-output-per-height.test.js +0 -458
  187. package/test/orchestrator-wired.test.js +0 -207
  188. package/test/output-catalog.test.js +0 -39
  189. package/test/output-shape.test.js +0 -21
  190. package/test/output-spec.test.js +0 -251
  191. package/test/output-speed.test.js +0 -92
  192. package/test/outputs-being-prepared.test.js +0 -40
  193. package/test/packet-witness-ring.test.js +0 -236
  194. package/test/packet-witness.test.js +0 -148
  195. package/test/piece-completeness.test.js +0 -78
  196. package/test/piece-disk-store.test.js +0 -401
  197. package/test/piece-from-whole-file.test.js +0 -129
  198. package/test/piece-lru.test.js +0 -319
  199. package/test/piece-reader.test.js +0 -162
  200. package/test/piece-selection-offset.test.js +0 -85
  201. package/test/piece-store-eviction.test.js +0 -595
  202. package/test/piece-store-never-refuses.test.js +0 -153
  203. package/test/piece-store-reservations.test.js +0 -403
  204. package/test/piece-store-slow-disk.test.js +0 -159
  205. package/test/piece-tail.test.js +0 -97
  206. package/test/plan-host-timings.test.js +0 -68
  207. package/test/plan-is-steady.test.js +0 -225
  208. package/test/playback-readiness.test.js +0 -518
  209. package/test/playback-start-regressions.test.js +0 -101
  210. package/test/priority-map-download.test.js +0 -174
  211. package/test/priority-map-emptied.test.js +0 -204
  212. package/test/priority-map-per-output.test.js +0 -215
  213. package/test/priority-map.test.js +0 -163
  214. package/test/probe-wedge-certainty.test.js +0 -60
  215. package/test/produced-copy-choice.test.js +0 -213
  216. package/test/published-timeline.test.js +0 -83
  217. package/test/quality-offer.test.js +0 -160
  218. package/test/quality-variants.test.js +0 -1274
  219. package/test/rate-control-in-the-output.test.js +0 -181
  220. package/test/read-survives-withdrawal.test.js +0 -164
  221. package/test/read-window.test.js +0 -365
  222. package/test/reads-not-yet-arrived.test.js +0 -218
  223. package/test/resume-warm.test.js +0 -39
  224. package/test/run-graph-drift.test.js +0 -37
  225. package/test/run-inputs.test.js +0 -80
  226. package/test/run-intervals.test.js +0 -100
  227. package/test/run-position-follows-published-grid.test.js +0 -89
  228. package/test/run-progress.test.js +0 -64
  229. package/test/same-height-switch.test.js +0 -663
  230. package/test/seek-frees-the-viewers-requests.test.js +0 -217
  231. package/test/seek-landing.test.js +0 -109
  232. package/test/seek-target-not-superseded.test.js +0 -195
  233. package/test/segment-closed-on-both-branches.test.js +0 -114
  234. package/test/segment-cut-times.test.js +0 -63
  235. package/test/segment-demand.test.js +0 -80
  236. package/test/segment-hold-supersede.test.js +0 -91
  237. package/test/segment-judged-by-its-own-header.test.js +0 -222
  238. package/test/segment-serve-wiring.test.js +0 -481
  239. package/test/segment-store-eviction.test.js +0 -247
  240. package/test/segment-store.test.js +0 -352
  241. package/test/segment-true-start.test.js +0 -86
  242. package/test/segments-are-shared.test.js +0 -176
  243. package/test/send-chunk-bytes.test.js +0 -86
  244. package/test/serving-existing-output.test.js +0 -111
  245. package/test/serving-output.test.js +0 -102
  246. package/test/shared-piece-store.test.js +0 -310
  247. package/test/sidecar-naming.test.js +0 -142
  248. package/test/soundtrack-rate-bound.test.js +0 -289
  249. package/test/source-file.test.js +0 -133
  250. package/test/source-files-route.test.js +0 -113
  251. package/test/source-registry.test.js +0 -18
  252. package/test/split-a-stretch.test.js +0 -139
  253. package/test/stale-request-after-seek.test.js +0 -158
  254. package/test/startup-readings.test.js +0 -124
  255. package/test/stream-route.test.js +0 -237
  256. package/test/subtitle-cue-framing.test.js +0 -200
  257. package/test/subtitle-cue-source.test.js +0 -102
  258. package/test/subtitle-cue-walk.test.js +0 -385
  259. package/test/subtitle-cursor.test.js +0 -63
  260. package/test/subtitle-defaults.test.js +0 -118
  261. package/test/subtitle-language.test.js +0 -252
  262. package/test/subtitle-metadata.test.js +0 -15
  263. package/test/subtitle-plan-waits.test.js +0 -125
  264. package/test/subtitle-track-numbering.test.js +0 -391
  265. package/test/supply-margin.test.js +0 -190
  266. package/test/swarm-follows-readers.test.js +0 -174
  267. package/test/swarm-reach.test.js +0 -130
  268. package/test/swarm-selection.test.js +0 -220
  269. package/test/tail-duplication.test.js +0 -167
  270. package/test/the-channel-has-both-ends.test.js +0 -91
  271. package/test/the-torrent-thread-serves-bytes.test.js +0 -107
  272. package/test/thread-pool.test.js +0 -53
  273. package/test/timeline.test.js +0 -84
  274. package/test/torrent-contents.test.js +0 -235
  275. package/test/torrent-cost.test.js +0 -71
  276. package/test/torrent-files.test.js +0 -221
  277. package/test/torrent-naming.test.js +0 -255
  278. package/test/tracks-begin-together.test.js +0 -209
  279. package/test/tunnel-renewal.test.js +0 -167
  280. package/test/two-viewers-one-picture.test.js +0 -508
  281. package/test/upload-hurry.test.js +0 -186
  282. package/test/usrsctp-state.test.js +0 -131
  283. package/test/video-facts.test.js +0 -102
  284. package/test/viewer-assignments.test.js +0 -143
  285. package/test/viewer-outputs.test.js +0 -285
  286. package/test/viewer-presence.test.js +0 -116
  287. package/test/viewer-requests-admission.test.js +0 -92
  288. package/test/viewer-starts-on-map.test.js +0 -27
  289. package/test/viewer-states.test.js +0 -192
  290. package/test/viewer-subtitle-subscription.test.js +0 -96
  291. package/test/viewer.test.js +0 -139
  292. package/test/viewing-generations.test.js +0 -390
  293. package/test/visible-rung.test.js +0 -37
  294. package/test/wait-ledger.test.js +0 -100
  295. package/test/webrtc-shim.test.js +0 -149
  296. package/test/wedge-certainty.test.js +0 -131
  297. package/test/whole-file-held-read.test.js +0 -30
  298. package/test/withdraw-piece-claim.test.js +0 -212
  299. package/test/worker-channel.test.js +0 -158
@@ -1,96 +0,0 @@
1
- <!-- GENERATED from services/encode/encode-run-state.js by scripts/render-run-graph.js.
2
- Do not edit by hand: change the table and run `npm run graph`. -->
3
-
4
- # The encoder run — states and transitions
5
-
6
- One run of one ffmpeg inside one transcode session. The table this is drawn
7
- from is executed by `services/encode/EncodeRuns.js`; every transition a real
8
- run makes is logged as state, event and target, so a run that takes an edge
9
- absent here is a violation the log names.
10
-
11
- ```mermaid
12
- stateDiagram-v2
13
- state RUN {
14
- [*] --> IDLE
15
- state WORKING {
16
- state ALIVE {
17
- STARTING
18
- PRODUCING
19
- SUSPENDED
20
- }
21
- RETRY_WAIT
22
- }
23
- IDLE
24
- STOPPED
25
- ENDED_COMPLETE
26
- ENDED_FAILED
27
- }
28
-
29
- RUN --> STARTING : SPAWNED
30
- WORKING --> STOPPED : STOP_ORDERED
31
- ALIVE --> SUSPENDED : SUSPEND_ORDERED
32
- ALIVE --> ENDED_COMPLETE : EXITED_COMPLETE
33
- ALIVE --> ENDED_FAILED : EXITED_SHORT
34
- ALIVE --> RETRY_WAIT : EXITED_INPUT_LOST
35
- ALIVE --> ENDED_FAILED : EXITED_FAILED
36
- STARTING --> PRODUCING : FIRST_SEGMENT
37
- SUSPENDED --> PRODUCING : RESUME_ORDERED
38
- RETRY_WAIT --> IDLE : RETRY_DUE
39
- ```
40
-
41
- ## States
42
-
43
- | state | means |
44
- |---|---|
45
- | `IDLE` | No process, and one is expected — before the first run, or after a retry timer fired. |
46
- | `STARTING` | Spawned; this run has produced nothing servable yet. |
47
- | `PRODUCING` | This run has produced at least one servable segment. |
48
- | `SUSPENDED` | SIGSTOP delivered, process alive — and nothing is reading the input. |
49
- | `RETRY_WAIT` | The input went away; a restart is timed. Requests are held, not refused. |
50
- | `STOPPED` | Stopped on purpose with no replacement — a rung the viewer switched away from. |
51
- | `ENDED_COMPLETE` | Ran through the last segment of the file. Nothing is owed. |
52
- | `ENDED_FAILED` | Terminal for this target: requests are answered as failures. |
53
-
54
- ## Events
55
-
56
- | event | means |
57
- |---|---|
58
- | `SPAWNED` | A process was spawned for this session. |
59
- | `FIRST_SEGMENT` | The first servable segment of this run was served. |
60
- | `SUSPEND_ORDERED` | SIGSTOP was delivered. |
61
- | `RESUME_ORDERED` | SIGCONT was sent. |
62
- | `STOP_ORDERED` | The run was stopped with no replacement. |
63
- | `EXITED_COMPLETE` | Exit 0, having produced through the last segment. |
64
- | `EXITED_SHORT` | Exit 0, short of the last segment — the input dried up. |
65
- | `EXITED_INPUT_LOST` | Died because the input was not there. Recoverable. |
66
- | `EXITED_FAILED` | Died for any other reason, or could not be spawned. |
67
- | `RETRY_DUE` | The input-retry timer fired. |
68
-
69
- ## What each state answers
70
-
71
- Outputs depend on the state alone — computed here by calling the same
72
- functions the session manager calls.
73
-
74
- | state | reads its input | can be signalled | a missing segment | on the wire | may restart |
75
- |---|---|---|---|---|---|
76
- | `IDLE` | no | no | hold | `starting` | yes |
77
- | `STARTING` | yes | yes | hold | `running` | yes |
78
- | `PRODUCING` | yes | yes | hold | `running` | yes |
79
- | `SUSPENDED` | no | yes | hold | `running` | yes |
80
- | `RETRY_WAIT` | no | no | hold | `starting` | yes |
81
- | `STOPPED` | no | no | hold | `running` | yes |
82
- | `ENDED_COMPLETE` | no | no | hold | `ready` | no |
83
- | `ENDED_FAILED` | no | no | fail | `failed` | yes |
84
-
85
- ## Edges that must never exist
86
-
87
- The machine's real content: a near-complete digraph asserts nothing.
88
-
89
- | from | event | must not reach | because |
90
- |---|---|---|---|
91
- | `SUSPENDED` | `FIRST_SEGMENT` | `PRODUCING` | a segment request must not release a suspended encoder — 2.9.93, where any request did, and the run sawtoothed from 155 s to 922 s ahead of the viewer in three minutes |
92
- | `ENDED_FAILED` | `FIRST_SEGMENT` | `PRODUCING` | a dead run is not a producing one — 2.9.93, where the handle pointed at a corpse and every later seek was waved through as already covered, so the session answered 500 for ever |
93
- | `ENDED_FAILED` | `RESUME_ORDERED` | `PRODUCING` | there is no process to continue; only a spawn leads out of a failure |
94
- | `IDLE` | `FIRST_SEGMENT` | `PRODUCING` | nothing produces before a process exists |
95
- | `RETRY_WAIT` | `FIRST_SEGMENT` | `PRODUCING` | a run waiting for its input back has no process; only a spawn resumes production |
96
- | `STOPPED` | `RESUME_ORDERED` | `PRODUCING` | a rung the viewer switched away from must not be revived by its own held requests — the host has one encoder's worth of capacity and the rung on screen needs it |
package/docs/logs.md DELETED
@@ -1,138 +0,0 @@
1
- # Logs — where to look
2
-
3
- No browser console copy-paste is needed: the page forwards its own log. But it
4
- lands in TWO places depending on the phase of the session — the registry server
5
- and the proxy — see "Browser logs are in TWO places" below before concluding
6
- anything from a half-session.
7
-
8
- ## Where the proxy writes its log, by how it is started
9
-
10
- The proxy is deployment-agnostic: the Home Assistant addon is one way to run it,
11
- npm and Docker on Linux, macOS or Windows are others. Where its log goes is
12
- decided by one start parameter, `--log-file <path>`, and nothing else:
13
-
14
- - **With `--log-file`**: every line goes to the console AND to that file
15
- (appended, rotated to `<path>.1` past 1 GiB), and the browser's lines go to
16
- one file per viewing session in the same directory (see "The files on the
17
- proxy" below). The directory of the file must exist.
18
- - **Without it**: everything goes to the console only, the browser's lines
19
- included, each prefixed `client <sessionId:8>`. Before torrent-tv/meta#96 the
20
- browser's lines were dropped in this case. The console is kept by whatever
21
- started the process, and only as long as that keeps it.
22
-
23
- | How it is started | Log | Browser lines | Survives |
24
- |---|---|---|---|
25
- | Home Assistant addon | `/data/proxy.log` (`run.sh` passes `--log-file /data/proxy.log`) | `/data/client-*.log` | restarts and addon updates |
26
- | npm / `npx`, any OS, no `--log-file` | the terminal | the terminal | nothing |
27
- | npm under systemd, no `--log-file` | the unit's journal: `journalctl -u <unit>` | the same journal | restarts, within journald's limits |
28
- | npm with `--log-file`, e.g. `/var/log/torrent-tv-proxy/proxy.log`, `~/Library/Logs/torrent-tv/proxy.log`, `%LOCALAPPDATA%\torrent-tv\proxy.log` | that file | `client-*.log` beside it | restarts and updates |
29
- | Docker, no `--log-file` | `docker logs <container>` | the same | only the container's life: recreating it deletes the log |
30
- | Docker with a volume and `--log-file`, e.g. `-v ttv-proxy-logs:/logs … --log-file /logs/proxy.log` | the file in the volume | `client-*.log` in the volume | recreating the container |
31
-
32
- So on any host where the log matters, pass `--log-file` and point it at a
33
- directory that outlives the process — which is what the addon does.
34
-
35
- ## HA proxy (aarch64, addon `b34a1737_torrent_tv_proxy`)
36
-
37
- Image `b34a1737/aarch64-addon-torrent_tv_proxy:<version>` = `@torrent-tv/proxy` `<version>` (see `ha-addon/torrent_tv_proxy/config.yaml`).
38
-
39
- - Console + file are the same: the proxy logs to both `stdout` and `/data/proxy.log` on start (`logging to /data/proxy.log as well as the console`).
40
- - **Since 2.71.0 that is true of the torrent thread too, and it was not before.**
41
- A worker thread loads its own instance of every module, so the logger's file
42
- handle — set once, on the main thread — was null in the worker for the life of
43
- the process. Measured over a whole 49 938-line file: zero lines from the piece
44
- reader (`read "…"`, `supply "…"`, every wait and its cause) and zero from the
45
- torrent pool, against 52 and 36 of them in `docker logs`, which every release
46
- destroys. The worker now sends its lines to the main thread, which is the only
47
- writer; a line from there reads `torrent-worker: …`.
48
- - Via container:
49
- ```bash
50
- ssh ha "sudo docker logs app_b34a1737_torrent_tv_proxy --tail 200"
51
- ssh ha "sudo docker exec app_b34a1737_torrent_tv_proxy cat /data/proxy.log | tail -n 300"
52
- ```
53
- - Filter by session: every transcode session logs its id, e.g. `003ed2fd-7c9b-4cd5-9d05-ff875ff2be23`, `hold segment-00068.mp4 failed`, `encode-run failed`, `EXITED_*`.
54
- - Host file `/data/proxy.log` survives `docker logs` rotation; `core dumps: 1 present` line shows kept dump under `/data`.
55
-
56
- SSH to HA requires `MACs hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,umac-128-etm@openssh.com` — server `OpenSSH_10.3` on `homeassistant.local` offers only `*-etm` (`Unable to negotiate` / `Corrupted MAC` otherwise). Already in `~/.ssh/config` `Host ha`.
57
-
58
- ## DO server (webauth.courses, `infra-server-1`)
59
-
60
- - Server is `infra-server-1` (`ghcr.io/torrent-tv/server`) on `do` (`206.189.97.152`).
61
- - Every container there logs to the host journal, and rsyslog writes one file per
62
- source to `/var/log/torrent-tv/`; the files and the journal survive the
63
- deployments that recreate the containers (`infra` README, "Logs";
64
- torrent-tv/meta#96):
65
- - `server.log` — the server's own lines;
66
- - `client.log` — browser lines the server received, prefixed
67
- `[client <tag> <id> sig=<webrtcSessionId>]`
68
- (`server/routes/api/client-logs/post.js`);
69
- - `nginx.log`, `doco-cd.log`.
70
- - Frontend logs reach the droplet only in the phases the proxy cannot be reached
71
- in — see "Browser logs are in TWO places" below.
72
- - Reading:
73
- ```bash
74
- ssh do "tail -n 300 /var/log/torrent-tv/client.log"
75
- # filter a single viewing:
76
- ssh do "grep 003ed2fd /var/log/torrent-tv/client.log /var/log/torrent-tv/server.log"
77
- ssh do "journalctl -t torrent-tv-server --since '-1h' -o short-iso-precise"
78
- ```
79
- - `docker logs infra-server-1` shows only the CURRENT container's lines — a
80
- deployment gives it a new container. Use the files or `journalctl -t`.
81
- - No need to open eruda or copy the browser console on a phone — it is forwarded.
82
-
83
- ## Browser logs are in TWO places, split by phase — read both
84
-
85
- Until 2026-09-13 the page's whole log went to the droplet's standard output,
86
- which every release of the server destroys. A viewer reported a desync and a
87
- frozen picture that day and the analysis ran on half the evidence, so the log
88
- moved to the proxy — beside the proxy's own, on the same durable directory.
89
-
90
- The split is by PHASE, and neither half is the whole session:
91
-
92
- 1. **Before a transport exists** — the page opening, the proxy being chosen, a
93
- connection failing — there is nowhere else to send it, so it goes to the
94
- SERVER (`/var/log/torrent-tv/client.log` on the droplet);
95
- 2. **From the moment the data channel is up**, the page's logger is given a
96
- proxy sink (`loading.js`, `setProxySink`) and every batch goes to the PROXY
97
- over that channel. This is the bulk of a viewing;
98
- 3. **At unload** it goes to the server again: `navigator.sendBeacon` is the only
99
- thing a page that is going away can use, and a data channel is not;
100
- 4. **A batch that cannot reach the proxy** falls back to the server.
101
-
102
- So a session that failed while connecting is on the droplet, a session that
103
- failed while playing is on the addon host, and a complete reading of a long
104
- failure needs both.
105
-
106
- ### The files on the proxy
107
-
108
- When the proxy was started with `--log-file`: one file per viewing session, in
109
- the proxy log's own directory (`/data` on the addon host), named so the two
110
- halves join without guessing. Without `--log-file` the same lines are in the
111
- proxy's console, prefixed `client <sessionId:8>`.
112
-
113
- ```
114
- client-<YYYYMMDD-HHMMSS UTC of the session start>-<sessionId:8>-<torrent name:60>-<infoHash:8>.log
115
- ```
116
-
117
- A session that has not chosen a torrent yet writes `no-torrent-yet` in that
118
- last part — the file is keyed by the session id, not by the name, so choosing a
119
- torrent later does NOT start a second file. Rotated at 16 MB to `<name>.log.1`.
120
-
121
- ```bash
122
- ssh ha "sudo docker exec app_b34a1737_torrent_tv_proxy sh -c 'ls -la /data/client-*.log'"
123
- ssh ha "sudo docker exec app_b34a1737_torrent_tv_proxy sh -c 'cat /data/client-20260913-*.log'"
124
- ```
125
-
126
- Implementation: `utils/client-log-file.js`, route `routes/api/client-logs/post.js`.
127
-
128
- ## Quick triage
129
-
130
- - Rewind/seek bug (hold 0ms → 500): HA `hold ... failed after 0ms → 500` + `encode-run` lines for the same `<sessionId>`, and DO `client.log` `[client ...] fragLoadError / levelLoadError 500` for same `sn`.
131
- - Cushion / link budget: HA `memory: rss=... anon=...` and `cushion` lines; DO `[eta]` / `[cushion]` from client.
132
- - Update check: `ssh ha "sudo docker exec hassio_cli ha apps info b34a1737_torrent_tv_proxy | grep version"` and `ssh ha "sudo docker ps --filter name=app_b34a1737_torrent_tv_proxy"`.
133
-
134
- ## Related
135
-
136
- - `ha-addon/CLAUDE.md` — addon build/update detour via `hassio_cli`, cache-bust via `config.yaml` version.
137
- - `docs/container-architecture.md` — what container/track classes log and where.
138
- - `routes/api/client-logs/post.js` and `server/routes/api/client-logs/post.js` — the two receivers; both sanitize the same way (control chars → space, `MAX_LINES`, `MAX_MSG_LEN`).
@@ -1,113 +0,0 @@
1
- # Playback start forecast
2
-
3
- For resource r, measured service is S_r(t) = rate_r * t. New observations
4
- replace the conditional future rate; polling cannot invent acceleration,
5
- exponential recovery or a new physical measurement.
6
-
7
- Source work uses the file's measured byte density, missing local byte ranges
8
- and the observed torrent download rate. Shared input ranges are downloaded
9
- once. Files on the same torrent share a queue; distinct torrents use distinct
10
- observed services. Local input reading is included in effective processing
11
- speed, rather than charged again as a separate disk or memory delay.
12
-
13
- Each output's remaining processing work subtracts progress only within its
14
- actual live run intervals. Initial video rates use existing codec/size/encoder
15
- calibration. Initial audio rates use short packaged per-codec measurements and
16
- sample work (encoding) or encoded bytes (copying). Actual output progress
17
- replaces these initial rates. That rate is the run's processing speed: film
18
- made over the run's own working time, with the time its input waited for the
19
- swarm and the time it was stopped taken out (`RunClock`, fed by the stream
20
- route, which marks each wait of a run's input read). The download is charged
21
- once, by the source service, and not a second time inside the processing rate. Startup is charged once, separately from processing
22
- throughput, and disappears once actual run progress establishes processing.
23
-
24
- Input arrival and processing overlap. With arrival time D(m), processing rate
25
- e and previous completion C, completion for an interval [a,b] is
26
-
27
- max(C + (b-a)/e, sup_m(D(m) + (b-m)/e)).
28
-
29
- Between service boundaries these functions are linear, so only endpoints are
30
- needed. Client delivery follows production and shares the observed link queue.
31
- Measured client ranges and prepared media establish each track's deadlines.
32
-
33
- The minimum start delay for this conditional trajectory is
34
-
35
- max(0, max_j(completion_j - presentation_deadline_j)).
36
-
37
- This covers the remaining finite movie, including rates below real time. Slow
38
- positive service gives a finite preproduction delay; it is not rejected by a
39
- browser-capacity threshold or a capped search. Observed supply-interruption
40
- coverage is held in prepared proxy media and client media, without requiring
41
- the browser to hold it all.
42
-
43
- Critical review: future rates can change, average byte density is an initial
44
- mapping rather than an exact packet index, initial audio sample-work scaling
45
- does not model every decoder's nonlinear cost, and client receive/append time
46
- is not separately measured. These are approximation limits, not hidden weights.
47
- Actual progress, segment sizes and link observations refine the prediction.
48
- The client countdown uses elapsed local monotonic time; expiration cannot
49
- authorize playback. Only the proxy's readiness and real track coverage can.
50
-
51
- Zero service, missing media facts and a genuine timestamp gap remain explicit
52
- noncomputable states. The UI reports their causes instead of an estimating
53
- placeholder or a fabricated duration.
54
-
55
- ## Continuity is decided in exact time
56
-
57
- The forecast lives in the viewer component (`services/viewer/`), because what
58
- it predicts is how the viewer's browser will play; the request operation
59
- (`ViewerRequests`) is handed it by `wire-outputs.js`.
60
-
61
- 1. **The file states integers.** A piece's media is read as presentation
62
- intervals in the integer ticks of each track's timescale
63
- (`readPresentationRanges`, `services/encode/segment-formats/mp4-boxes.js`).
64
- Intervals are joined there only where they touch or overlap; the format
65
- states what the samples say and nothing about browsers.
66
- 2. **One function places a piece.** The position written into `tfdt` when a
67
- piece is served and the position its coverage is read at both come from
68
- `readTrackEdits`, which converts the movie-timescale edit into track ticks
69
- with one stated rounding. The reader and the writer cannot disagree.
70
- 3. **Seconds from the page are exact fractions.** A buffered range, a position
71
- or a cut time arrives as a JavaScript number, which is a binary fraction;
72
- `services/viewer/media-time.js` converts it to that fraction exactly. No unit
73
- is chosen. A buffered range is widened by `REPORTED_TIME_ERROR`, the bound of
74
- Chromium's three truncations to whole microseconds, so that it denotes every
75
- exact time the report can stand for.
76
- 4. **The join rule holds in every engine.** The Media Source specification
77
- leaves the threshold to the implementation, so a gap counts as joined only
78
- when Chromium, Gecko and WebKit all join it: twice the gap within the two
79
- ranges' longest frames since a keyframe (Gecko's fuzz), and the gap within
80
- 2002/24000 s (WebKit's `timeFudgeFactor`). Chromium's own bound follows from
81
- the first. Old iOS without Media Source plays HLS in a closed player, and
82
- nothing is derived for it.
83
-
84
- Seconds appear again only for rates, schedules and the answer.
85
-
86
- ## A piece is finished when its frames reach its cut
87
-
88
- A closed non-final fragment is reusable only if the end of its last frame, on
89
- every track, reaches its muxer's cut less `SEGMENT_CUT_TIME_DELTA_SECONDS`,
90
- the delta the muxer is configured with. That is a fact of production, so no
91
- browser frame allowance is used to decide completeness. For explicit cuts the
92
- closure channel is CSV: its reference packet end has not lost the fraction of
93
- a movie tick that MP4's empty edit loses. The first reference packet's time is
94
- recovered from that end minus the first piece's exact sample span (the first
95
- CSV start is zero even after a seek), and is added to the relative cut times
96
- handed to FFmpeg. Comparisons use integer microseconds, as FFmpeg's segment
97
- muxer does. A stored piece without this closure reading carries the upper
98
- uncertainty of its empty edit, read from the movie and track timescales.
99
-
100
- The last frame must still reach the cut on every track. No playable media, a
101
- missing full frame, or a failed rename remains a publication failure. Such a
102
- failure stops the run, records that cause and releases its claimed interval;
103
- the existing repeated-start failure limit applies to subsequent attempts. A
104
- refused file cannot stay claimed while the encoder finishes the whole film.
105
-
106
- The encoding decides completeness
107
- (`encode/piece-completeness.js`): `EncodeRuns` judges a closed file before it is
108
- published, and judges a stored piece left by an earlier process when the
109
- forecast asks for it, taking a short one off the disk. The segment store keeps
110
- the bytes and the media intervals read from them and judges nothing. Interrupted
111
- fragments are therefore never served or counted, so the production schedule
112
- treats their media as unfinished work. The final fragment uses its actual media
113
- end rather than the container's approximate duration.
@@ -1,114 +0,0 @@
1
- # SOCKS5 torrent egress — feasibility research (NOT implemented)
2
-
3
- Research only (2026-07-10), no code. Question: can the proxy route its
4
- **torrent** traffic (peers, trackers, DHT) through an owner-configured SOCKS5
5
- endpoint (e.g. a VPN provider's) to hide the owner's home IP from the swarm,
6
- while WebRTC to the viewer stays direct? Roadmap item 8 in the root
7
- `CLAUDE.md`.
8
-
9
- Stack: WebTorrent 2.8.5, Node. Verified against
10
- `node_modules/webtorrent/lib/*.js` and `index.js`.
11
-
12
- ## What "torrent traffic" actually is (and which parts can be SOCKS5'd)
13
-
14
- SOCKS5 forwards a connection through a relay so the destination sees the
15
- relay's IP, not ours. It supports TCP (CONNECT) and, in theory, UDP (UDP
16
- ASSOCIATE) — but UDP-ASSOCIATE is rarely usable from Node libraries that bind
17
- their own UDP sockets. So per traffic type:
18
-
19
- | Traffic | Transport | Where in WebTorrent | SOCKS5? |
20
- |---|---|---|---|
21
- | Peer wire (outgoing) | TCP | `torrent.js` `net.connect(opts)` (~L2112) | **Yes** (TCP CONNECT) |
22
- | Peer wire (outgoing) | µTP (UDP) | `torrent.js` `utp.connect()` (~L2110) | No (UDP, own socket) → **disable** |
23
- | HTTP/HTTPS trackers | TCP | `bittorrent-tracker` (HTTP agent) | **Yes** (agent) |
24
- | WSS trackers | TCP (WebSocket) | `bittorrent-tracker` (ws agent) | **Yes** (agent) |
25
- | UDP trackers (`udp://`) | UDP | `bittorrent-tracker` | No → **drop** (filter announce list) |
26
- | DHT | UDP | `bittorrent-dht` | No → **disable** (`dht:false`) |
27
- | LSD (local peer discovery) | UDP multicast | conn-pool | LAN-only leak → **disable** (`lsd:false`) |
28
- | Incoming peers | TCP/µTP listener | conn-pool | N/A (inbound; see note) |
29
-
30
- Conclusion: a clean, leak-free config is **TCP-only through the SOCKS5 relay**
31
- with every UDP path turned OFF. This is the standard "torrent proxy" model and
32
- its standard caveat: you lose µTP peers, UDP trackers, and DHT peer discovery —
33
- peer counts drop, but HTTP/WSS-tracker swarms (like the rutracker trackers our
34
- test torrents use) still work, and TCP peers are plentiful.
35
-
36
- WebTorrent already exposes the needed off-switches (verified in `index.js`):
37
- `utp: false` (L82), `dht: false` (L127), `lsd: false` (L76), `webSeeds`
38
- (L161). Announce-list filtering to `http(s)://`/`wss://` is ours to do.
39
-
40
- ## The hard part: no dialer hook for TCP peers
41
-
42
- WebTorrent has **no public option** to supply a custom socket/dialer for
43
- outgoing peer connections — it calls `net.connect(opts)` directly inside
44
- `torrent.js`. Three ways around it:
45
-
46
- ### Approach A — userland, scoped monkeypatch of `net.connect` (+ disable UDP)
47
- Wrap `net.connect` so that for a **peer destination** it returns a socket
48
- tunneled through SOCKS5 (via the already-present `socks` package —
49
- `SocksClient.createConnection({ proxy, command:'connect', destination })`),
50
- and for everything else (our loopback HTTP server, the signalling tunnel,
51
- ffmpeg's `127.0.0.1` fetch, DNS) it calls the real `net.connect`.
52
- - The `socks` dep is ALREADY in `node_modules` (currently transitive) — would
53
- become a direct dependency.
54
- - Shim detail: `net.connect` returns a socket synchronously and connects
55
- async; `SocksClient.createConnection` is Promise-based. Need a small adapter
56
- that returns a `net.Socket`-like duplex immediately and attaches the real
57
- tunneled socket once the SOCKS handshake resolves (or emits `error`). The
58
- `socks` package's event API supports this.
59
- - Scoping rule: SOCKS only for non-local IPv4/IPv6 destinations; NEVER for
60
- `127.0.0.1`/`::1`/the tunnel host — otherwise we'd route our own control
61
- plane through the VPN.
62
- - Trackers/webseeds (HTTP/WSS): pass a `socks-proxy-agent` as the HTTP/ws
63
- agent to `bittorrent-tracker` / webseed fetches (need to confirm WebTorrent
64
- threads an `agent` option through; may need a small patch).
65
- - Pros: no fork, no build-chain changes, deployment-agnostic. Cons: global
66
- monkeypatch is delicate; must be airtight on the scoping rule.
67
-
68
- ### Approach B — patch/fork WebTorrent to add a `createConnection` hook
69
- Add an option so `torrent.js` uses `opts.createConnection ?? net.connect`.
70
- Cleaner and explicit, but a fork to maintain (or an upstream PR — issue
71
- webtorrent#807 "SOCKS Proxy Support" is open and unresolved, so upstream is
72
- unlikely soon). More correct long-term if A proves too fragile.
73
-
74
- ### Approach C — network-level (VPN container / namespace), NOT in-proxy
75
- Run the whole proxy process behind a VPN with a kill-switch (e.g. a `gluetun`
76
- sidecar container, or a Linux network namespace bound to the VPN). Catches
77
- ALL traffic — TCP, µTP, DHT, UDP trackers — leak-proof, zero proxy code.
78
- Trade-off: not per-app (the whole proxy egresses via VPN, including the
79
- signalling tunnel unless split), heavier ops, and awkward for the HA addon
80
- (`host_network: true`). This is the ROBUST alternative to document alongside;
81
- for a bare-Docker/npm operator it may actually be the better answer than
82
- in-proxy SOCKS5.
83
-
84
- ## Kill-switch (fail-closed) — mandatory for the feature to mean anything
85
- If the SOCKS5 relay is down, torrent traffic must NOT silently fall back to a
86
- direct connection (that leaks the exact IP we set out to hide). With Approach
87
- A this is natural: a failed SOCKS handshake fails the peer connection with no
88
- direct retry, AND all UDP paths are already disabled, so nothing bypasses the
89
- relay. Must add a startup connectivity self-test + a clear log line
90
- (BitPlay's "test proxy" pattern), and surface "proxy down → torrent paused"
91
- rather than leaking.
92
-
93
- ## Recommended direction (when we build it)
94
- 1. Primary: **Approach A** — `socks` for TCP peers via a scoped `net.connect`
95
- shim + `socks-proxy-agent` for HTTP/WSS trackers + webseeds, with
96
- `utp:false`, `dht:false`, `lsd:false`, and announce-list filtered to
97
- TCP-based trackers. Fail-closed by construction.
98
- 2. Document **Approach C** (VPN container) in the addon/deployment docs as the
99
- leak-proof alternative for operators who prefer it.
100
- 3. Approach B only if A's monkeypatch proves too fragile in practice.
101
-
102
- ## Open questions to resolve at build time (not now)
103
- - Does WebTorrent 2.8.x thread an `agent`/proxy option to `bittorrent-tracker`
104
- and webseed fetches, or is a small patch needed there too?
105
- - `socks` socket-shim: cleanest way to present a pre-connect `net.Socket`
106
- (custom Duplex vs a paused real socket) without confusing
107
- `bittorrent-protocol`'s wire setup.
108
- - Incoming peers: with UDP off and outbound via SOCKS, do we still accept
109
- inbound TCP peers directly (that inbound listener exposes the home IP to
110
- connecting peers)? For full hiding, inbound may need to be disabled too
111
- (accept that peer discovery becomes outbound-only) — decide per privacy goal.
112
- - Interaction with the UPnP port mapping / WebRTC UDP port (those are for the
113
- viewer transport, NOT torrent egress — must stay direct; confirm the shim's
114
- scoping never touches them).