@torrent-tv/proxy 2.89.17 → 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/server.js +0 -11
  4. package/.claude/commands/opsx/apply.md +0 -155
  5. package/.claude/commands/opsx/archive.md +0 -160
  6. package/.claude/commands/opsx/explore.md +0 -174
  7. package/.claude/commands/opsx/propose.md +0 -109
  8. package/.claude/commands/opsx/sync.md +0 -143
  9. package/.claude/skills/openspec-apply-change/SKILL.md +0 -159
  10. package/.claude/skills/openspec-archive-change/SKILL.md +0 -117
  11. package/.claude/skills/openspec-explore/SKILL.md +0 -289
  12. package/.claude/skills/openspec-propose/SKILL.md +0 -113
  13. package/.claude/skills/openspec-sync-specs/SKILL.md +0 -147
  14. package/.dockerignore +0 -5
  15. package/AGENTS.md +0 -363
  16. package/CHANGELOG.md +0 -2377
  17. package/Dockerfile +0 -30
  18. package/biome.json +0 -412
  19. package/corpus.tmp.json +0 -1
  20. package/docs/browser-proxy-contract.md +0 -155
  21. package/docs/container-architecture.md +0 -273
  22. package/docs/download-architecture.md +0 -261
  23. package/docs/encode-architecture.md +0 -765
  24. package/docs/encode-run-state.md +0 -96
  25. package/docs/logs.md +0 -151
  26. package/docs/playback-start-forecast.md +0 -113
  27. package/docs/socks5-egress-research.md +0 -114
  28. package/docs/storage-architecture.md +0 -273
  29. package/knip.json +0 -14
  30. package/main2.cpuprofile +0 -1
  31. package/openspec/changes/adaptive-bitrate/.openspec.yaml +0 -0
  32. package/openspec/changes/adaptive-bitrate/design.md +0 -92
  33. package/openspec/changes/adaptive-bitrate/proposal.md +0 -56
  34. package/openspec/changes/adaptive-bitrate/specs/adaptive-bitrate/spec.md +0 -51
  35. package/openspec/changes/adaptive-bitrate/tasks.md +0 -40
  36. package/openspec/changes/binary-distribution/.openspec.yaml +0 -2
  37. package/openspec/changes/binary-distribution/proposal.md +0 -53
  38. package/openspec/changes/chunked-request-bodies/design.md +0 -81
  39. package/openspec/changes/chunked-request-bodies/proposal.md +0 -53
  40. package/openspec/changes/chunked-request-bodies/specs/chunked-request-bodies/spec.md +0 -30
  41. package/openspec/changes/chunked-request-bodies/tasks.md +0 -40
  42. package/openspec/changes/cold-start/design.md +0 -98
  43. package/openspec/changes/cold-start/proposal.md +0 -62
  44. package/openspec/changes/cold-start/specs/cold-start/spec.md +0 -47
  45. package/openspec/changes/cold-start/tasks.md +0 -48
  46. package/openspec/changes/disk-cap/.openspec.yaml +0 -2
  47. package/openspec/changes/disk-cap/proposal.md +0 -37
  48. package/openspec/changes/disk-cap/specs/disk-cap/spec.md +0 -25
  49. package/openspec/changes/disk-cap/tasks.md +0 -19
  50. package/openspec/changes/proxy-observability/.openspec.yaml +0 -2
  51. package/openspec/changes/proxy-observability/design.md +0 -38
  52. package/openspec/changes/proxy-observability/proposal.md +0 -49
  53. package/openspec/changes/proxy-observability/specs/observability/spec.md +0 -33
  54. package/openspec/changes/proxy-observability/tasks.md +0 -21
  55. package/openspec/changes/seek-debounce/.openspec.yaml +0 -0
  56. package/openspec/changes/seek-debounce/design.md +0 -118
  57. package/openspec/changes/seek-debounce/proposal.md +0 -59
  58. package/openspec/changes/seek-debounce/specs/seek-debounce/spec.md +0 -41
  59. package/openspec/changes/seek-debounce/tasks.md +0 -33
  60. package/openspec/changes/subtitle-language/.openspec.yaml +0 -2
  61. package/openspec/changes/subtitle-language/proposal.md +0 -50
  62. package/openspec/changes/subtitle-language/specs/subtitle-language/spec.md +0 -34
  63. package/openspec/changes/subtitle-language/tasks.md +0 -26
  64. package/openspec/changes/track-selection/.openspec.yaml +0 -2
  65. package/openspec/changes/track-selection/design.md +0 -47
  66. package/openspec/changes/track-selection/proposal.md +0 -45
  67. package/openspec/changes/track-selection/specs/track-selection/spec.md +0 -41
  68. package/openspec/changes/track-selection/tasks.md +0 -20
  69. package/openspec/changes/transcode-quality/.openspec.yaml +0 -2
  70. package/openspec/changes/transcode-quality/proposal.md +0 -51
  71. package/openspec/changes/transcode-quality/specs/transcode-quality/spec.md +0 -139
  72. package/openspec/changes/transcode-quality/tasks.md +0 -63
  73. package/openspec/config.yaml +0 -38
  74. package/public/.well-known/appspecific/com.chrome.devtools.json +0 -1
  75. package/research/delivery-wedge-stand-ladder-2026-09-13.md +0 -329
  76. package/research/double-spawn-2026-09-10.md +0 -171
  77. package/research/handover-2026-09-13.md +0 -209
  78. package/research/handover-reader-claims-removal-2026-09-12.md +0 -166
  79. package/research/piece-withdrawn-but-still-claimed-2026-09-12.md +0 -175
  80. package/research/preset-benchmark-size-scaling-2026-08-22.md +0 -55
  81. package/research/priority-map-is-the-truth-2026-09-12.md +0 -225
  82. package/research/valgrind-replica-2026-08-27/logs.tar.gz +0 -0
  83. package/scripts/build-audio-samples.mjs +0 -31
  84. package/scripts/render-run-graph.js +0 -173
  85. package/test/asset-paths.test.js +0 -28
  86. package/test/audio-buffer-continuity.test.js +0 -77
  87. package/test/audio-calibration.test.js +0 -23
  88. package/test/audio-inventory.test.js +0 -212
  89. package/test/audio-track-bitrate.test.js +0 -40
  90. package/test/audio-warm-recorded.test.js +0 -63
  91. package/test/auto-quality-step.test.js +0 -762
  92. package/test/available-share.test.js +0 -76
  93. package/test/background-fill.test.js +0 -190
  94. package/test/client-log-file.test.js +0 -126
  95. package/test/client-logs-route.test.js +0 -34
  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,382 +0,0 @@
1
- import test from "node:test";
2
- import assert from "node:assert/strict";
3
-
4
- import {
5
- allowedGap,
6
- probeWedgeIsCertain,
7
- readProbeState,
8
- PROBE_INTERVAL_MS,
9
- UNRELIABLE_LABEL
10
- } from "../services/transport/delivery-probe.js";
11
-
12
- const ORDERED = ["proxy", "proxy-control"];
13
- const ALL = [...ORDERED, UNRELIABLE_LABEL];
14
-
15
- /**
16
- * @param {Record<string, number>} seen
17
- * @param {object} [overrides]
18
- */
19
- function state(seen, overrides = {}) {
20
- const allowed = {};
21
- for (const label of overrides.labels ?? ALL) {
22
- allowed[label] = 3;
23
- }
24
- return {
25
- seq: 100,
26
- seen,
27
- labels: ALL,
28
- echoes: 5,
29
- echoAgeMs: 400,
30
- allowed,
31
- ...overrides
32
- };
33
- }
34
-
35
- test("every channel current reads as flowing", () => {
36
- const { verdict } = readProbeState(state({ proxy: 100, "proxy-control": 99, "proxy-fast": 100 }));
37
- assert.equal(verdict, "flowing");
38
- });
39
-
40
- test("a lag shorter than the verdict window is still flowing", () => {
41
- const behind = 100 - 3;
42
- const { verdict } = readProbeState(
43
- state({ proxy: behind, "proxy-control": behind, "proxy-fast": 100 })
44
- );
45
- assert.equal(verdict, "flowing");
46
- });
47
-
48
- test("ordered channels behind while the unordered one keeps up names a stuck stream", () => {
49
- const { verdict, detail } = readProbeState(
50
- state({ proxy: 40, "proxy-control": 41, "proxy-fast": 100 })
51
- );
52
- assert.equal(verdict, "stream-stuck");
53
- // The numbers that produced the verdict must be in the line beside it.
54
- assert.match(detail, /proxy=40\(gap 60 of 3\)/);
55
- });
56
-
57
- test("every channel behind names the association", () => {
58
- const { verdict } = readProbeState(
59
- state({ proxy: 40, "proxy-control": 41, "proxy-fast": 42 })
60
- );
61
- assert.equal(verdict, "association-stopped");
62
- });
63
-
64
- test("without the unordered channel the verdict says it cannot compare", () => {
65
- const { verdict } = readProbeState(
66
- state({ proxy: 40, "proxy-control": 41 }, { labels: ORDERED })
67
- );
68
- assert.equal(verdict, "ordered-behind-no-comparison");
69
- });
70
-
71
- test("a stale echo means the reverse direction went too", () => {
72
- const { verdict } = readProbeState(
73
- state({ proxy: 40, "proxy-control": 41, "proxy-fast": 42 }, { echoAgeMs: 30_000 })
74
- );
75
- assert.equal(verdict, "reverse-direction-gone");
76
- });
77
-
78
- test("before the first echo nothing is claimed", () => {
79
- const { verdict } = readProbeState(state({}, { echoes: 0, echoAgeMs: null }));
80
- assert.equal(verdict, "no-echo-yet");
81
- });
82
-
83
- test("a channel that has never reported counts as behind, not as unknown", () => {
84
- const { verdict, detail } = readProbeState(
85
- state({ "proxy-fast": 100 })
86
- );
87
- assert.equal(verdict, "stream-stuck");
88
- assert.match(detail, /proxy=\?\(gap \? of 3\)/);
89
- });
90
-
91
- test("the allowance is the queue's own drain time, not a chosen number", () => {
92
- // 8 MB queued at 8 MB/s is one second of draining; probes go twice a second,
93
- // so two of them may legitimately be outstanding, plus the one sent after
94
- // the peer composed its report, plus the round trip.
95
- assert.equal(
96
- allowedGap({ queuedBytes: 8 * 1024 * 1024, bytesPerSecond: 8 * 1024 * 1024, rttMs: 0 }),
97
- Math.ceil(1000 / PROBE_INTERVAL_MS) + 1
98
- );
99
- // An empty queue still allows the one probe that is always in flight.
100
- assert.equal(allowedGap({ queuedBytes: 0, bytesPerSecond: 8 * 1024 * 1024, rttMs: 0 }), 1);
101
- // The round trip counts: the echo has to come back too.
102
- assert.ok(
103
- allowedGap({ queuedBytes: 0, bytesPerSecond: 1024, rttMs: 2000 }) >
104
- allowedGap({ queuedBytes: 0, bytesPerSecond: 1024, rttMs: 0 })
105
- );
106
- });
107
-
108
- test("with no rate measured nothing is claimed", () => {
109
- assert.equal(allowedGap({ queuedBytes: 1024, bytesPerSecond: 0, rttMs: 10 }), null);
110
- const { verdict } = readProbeState(
111
- state({ proxy: 40, "proxy-control": 41, "proxy-fast": 42 }, { allowed: {} })
112
- );
113
- assert.equal(verdict, "no-rate-yet");
114
- });
115
-
116
- test("a burst big enough to explain the lag is not called a stopped association", () => {
117
- // The 2026-08-26 false positive: all three channels at gap 7 while 150 Mbps
118
- // crossed the association. 64 MB queued at 18 MB/s is three and a half
119
- // seconds of draining, which is seven probe intervals.
120
- const allowance = allowedGap({
121
- queuedBytes: 64 * 1024 * 1024,
122
- bytesPerSecond: 18 * 1024 * 1024,
123
- rttMs: 16
124
- });
125
- assert.ok(allowance >= 7);
126
- const allowed = Object.fromEntries(ALL.map((label) => [label, allowance]));
127
- const { verdict } = readProbeState(
128
- state({ proxy: 93, "proxy-control": 93, "proxy-fast": 93 }, { allowed })
129
- );
130
- assert.equal(verdict, "flowing");
131
- });
132
-
133
- test("the peer's own answering cadence counts toward the allowance", () => {
134
- // Field case 2026-08-27: queues empty, 3.4 MB/s crossing, tab hidden so the
135
- // browser echoed about once a second. Without the peer's cadence the
136
- // allowance is the probe interval and the crossing — two probes — and every
137
- // other line read `association-stopped`.
138
- const withoutCadence = allowedGap({
139
- queuedBytes: 0,
140
- bytesPerSecond: 3.4 * 1024 * 1024,
141
- rttMs: 9
142
- });
143
- assert.equal(withoutCadence, 2);
144
- const withCadence = allowedGap({
145
- queuedBytes: 0,
146
- bytesPerSecond: 3.4 * 1024 * 1024,
147
- rttMs: 9,
148
- echoIntervalMs: 1000
149
- });
150
- assert.ok(withCadence >= 3, `a second of cadence must allow more than ${withCadence}`);
151
- const allowed = Object.fromEntries(ALL.map((label) => [label, withCadence]));
152
- const { verdict } = readProbeState(
153
- state({ proxy: 98, "proxy-control": 98, "proxy-fast": 98 }, { allowed, echoAgeMs: 977 })
154
- );
155
- assert.equal(verdict, "flowing");
156
- });
157
-
158
- test("a stale echo is judged against the peer's cadence, not a fixed half second", () => {
159
- // The same numbers with the cadence unknown must still be able to say the
160
- // reverse direction is gone — the bound rises with the cadence, it does not
161
- // disappear.
162
- const { verdict } = readProbeState(
163
- state({ proxy: 99, "proxy-control": 99, "proxy-fast": 99 }, { echoAgeMs: 60_000, echoStaleMs: 2000 })
164
- );
165
- assert.equal(verdict, "reverse-direction-gone");
166
- });
167
-
168
- test("bytes still arriving outrank the probe gaps — the cushion fill is not a wedge", () => {
169
- // The field shape of 2026-08-28: every queue at 0 B, so the allowance is
170
- // small, the probes are far behind because the browser is busy pulling two
171
- // minutes of film, and the association is perfectly healthy. Before the peer's
172
- // own byte counter was consulted this read as `association-stopped`, four
173
- // times in the first two minutes of a session nobody was troubled by.
174
- const state = {
175
- seq: 88,
176
- seen: { proxy: 78, "proxy-control": 78, "proxy-fast": 78 },
177
- labels: ["proxy", "proxy-control", "proxy-fast"],
178
- echoes: 40,
179
- echoAgeMs: 1305,
180
- allowed: { proxy: 9, "proxy-control": 9, "proxy-fast": 9 },
181
- echoStaleMs: 6000,
182
- peerBytesAdvancing: true
183
- };
184
- const reading = readProbeState(state);
185
- assert.equal(reading.verdict, "flowing");
186
- assert.match(reading.detail, /peerBytes=advancing/);
187
- });
188
-
189
- test("the same gaps with the peer's counter STILL are the wedge", () => {
190
- // One field changes, and it is the one that says whether anything is
191
- // arriving. This is the shape of a real freeze: probes behind, and the far
192
- // end receiving nothing.
193
- const reading = readProbeState({
194
- seq: 88,
195
- seen: { proxy: 78, "proxy-control": 78, "proxy-fast": 78 },
196
- labels: ["proxy", "proxy-control", "proxy-fast"],
197
- echoes: 40,
198
- echoAgeMs: 1305,
199
- allowed: { proxy: 9, "proxy-control": 9, "proxy-fast": 9 },
200
- echoStaleMs: 6000,
201
- peerBytesAdvancing: false
202
- });
203
- assert.equal(reading.verdict, "association-stopped");
204
- assert.match(reading.detail, /peerBytes=still/);
205
- });
206
-
207
- test("a browser that does not report its bytes is judged as before", () => {
208
- // The term says nothing rather than guessing, and the rule falls back.
209
- const reading = readProbeState({
210
- seq: 88,
211
- seen: { proxy: 78, "proxy-control": 78, "proxy-fast": 78 },
212
- labels: ["proxy", "proxy-control", "proxy-fast"],
213
- echoes: 40,
214
- echoAgeMs: 1305,
215
- allowed: { proxy: 9, "proxy-control": 9, "proxy-fast": 9 },
216
- echoStaleMs: 6000,
217
- peerBytesAdvancing: null
218
- });
219
- assert.equal(reading.verdict, "association-stopped");
220
- assert.doesNotMatch(reading.detail, /peerBytes=/);
221
- });
222
-
223
- test("a frozen tab's own event-loop delay counts toward the allowance", () => {
224
- // Field case 2026-09-03, session 03f211b8. The viewer paused at 15:24:21 with
225
- // 121.5 s buffered; the tab went hidden at 15:24:35 and its event loop fell
226
- // behind — loopLag 681 → 1881 → 4297 → 5957 ms. At 15:26:05 the probes read
227
- // `gap 12 of 11` and printed `association-stopped`, the ring files were kept
228
- // and a 180 s capture was taken; seven seconds later the same connection read
229
- // `flowing`. Nothing had stopped: the browser simply could not run the timer
230
- // that answers a probe.
231
- // The line printed `gap 12 of 11`; the queue was empty and the round trip
232
- // 162 ms, so the cadence term is whatever made the allowance 11. The probe
233
- // interval, added to the allowance on 2026-10-04, makes the same figures 12.
234
- const measured = {
235
- queuedBytes: 0,
236
- bytesPerSecond: 300,
237
- rttMs: 162,
238
- echoIntervalMs: 5000
239
- };
240
- const withoutLag = allowedGap(measured);
241
- const withLag = allowedGap({ ...measured, peerLoopLagMs: 1881 });
242
- assert.equal(withoutLag, 12, `11 in the field plus the probe interval, not ${withoutLag}`);
243
- assert.ok(withLag > 12, `a gap of 12 must fit inside ${withLag}`);
244
- const allowed = Object.fromEntries(ALL.map((label) => [label, withLag]));
245
- const { verdict, detail } = readProbeState(
246
- state(
247
- { proxy: 9547, "proxy-control": 9547, "proxy-fast": 9547 },
248
- {
249
- seq: 9559,
250
- allowed,
251
- echoAgeMs: 5963,
252
- echoStaleMs: 11 * PROBE_INTERVAL_MS + 162 + 5000 + 1881,
253
- peerBytesAdvancing: false,
254
- peerLoopLagMs: 1881,
255
- peerVisibility: "hidden"
256
- }
257
- )
258
- );
259
- assert.equal(verdict, "flowing");
260
- assert.match(detail, /peerLoopLag=1881ms/);
261
- assert.match(detail, /peerTab=hidden/);
262
- });
263
-
264
- test("the peer's lag widens the bound on a stale echo without removing it", () => {
265
- // The same term must not make `reverse-direction-gone` unreachable: a peer
266
- // that has genuinely gone silent is still silent for far longer than its own
267
- // loop delay explains.
268
- const { verdict } = readProbeState(
269
- state(
270
- { proxy: 99, "proxy-control": 99, "proxy-fast": 99 },
271
- {
272
- echoAgeMs: 120_000,
273
- echoStaleMs: 5500 + 162 + 1000 + 4297,
274
- peerLoopLagMs: 4297,
275
- peerVisibility: "hidden"
276
- }
277
- )
278
- );
279
- assert.equal(verdict, "reverse-direction-gone");
280
- });
281
-
282
- test("a peer that reports no loop delay is judged exactly as before", () => {
283
- const reading = readProbeState(
284
- state({ proxy: 90, "proxy-control": 90, "proxy-fast": 90 }, { peerBytesAdvancing: false })
285
- );
286
- assert.equal(reading.verdict, "association-stopped");
287
- assert.doesNotMatch(reading.detail, /peerLoopLag=/);
288
- assert.doesNotMatch(reading.detail, /peerTab=/);
289
- });
290
-
291
- test("a quiet stretch shorter than a legitimate report is not a wedge", () => {
292
- // Field 2026-09-11: two captures of 180 s each, triggered at `wedged 1s` and
293
- // `wedged 2s`, on a connection with `rtt=5ms`, every queue at 0 B and the
294
- // viewer watching. In its first minutes a connection has shown no healthy gap
295
- // at all, and the floor under "longer than anything healthy" was a single
296
- // probe interval — 500 ms — so any quiet moment beat it.
297
- // Both cadences plus the crossing: a probe sent just after the peer composed
298
- // a report shows up only in the next one.
299
- const legitimateReportMs = 500 + 500 + 12 + 0;
300
- assert.equal(
301
- probeWedgeIsCertain({ stuckForMs: 1000, longestHealthySeenGapMs: 0, legitimateReportMs }).isCertain,
302
- false,
303
- "a second of quiet is shorter than one legitimate report and says nothing"
304
- );
305
- // And what the detector exists for is untouched: a counter frozen for
306
- // minutes is far past any report this connection could legitimately owe.
307
- assert.equal(
308
- probeWedgeIsCertain({ stuckForMs: 60_000, longestHealthySeenGapMs: 0, legitimateReportMs }).isCertain,
309
- true
310
- );
311
- // A peer whose event loop is late is owed that time as well.
312
- assert.equal(
313
- probeWedgeIsCertain({
314
- stuckForMs: 3000,
315
- longestHealthySeenGapMs: 0,
316
- legitimateReportMs: 500 + 12 + 5000
317
- }).isCertain,
318
- false,
319
- "a peer frozen for five seconds cannot answer sooner than that"
320
- );
321
- });
322
-
323
- test("what is behind is judged in time, not in probes", () => {
324
- // The same probe goes down every channel including the one carrying the film,
325
- // and SCTP schedules per association — so a probe waits behind queued video
326
- // exactly as a segment does. Counting outstanding probes therefore measures
327
- // the queue, not the association, which is why the count is only printed now.
328
- const behind = { proxy: 800, "proxy-control": 800, "proxy-fast": 800 };
329
- const mayWait = { proxy: 2000, "proxy-control": 2000, "proxy-fast": 2000 };
330
-
331
- // Far behind in probes, well within the time its own queue is allowed.
332
- const healthy = readProbeState(
333
- state(
334
- { proxy: 40, "proxy-control": 41, "proxy-fast": 42 },
335
- { behindMs: behind, allowedWaitMs: mayWait }
336
- )
337
- );
338
- assert.equal(healthy.verdict, "flowing");
339
- assert.match(healthy.detail, /800ms of 2000ms/, "both readings belong in the line");
340
-
341
- // The same gaps, the same allowance, and the probe is older than the queue
342
- // could account for: that is the association and not the burst.
343
- const wedged = readProbeState(
344
- state(
345
- { proxy: 40, "proxy-control": 41, "proxy-fast": 42 },
346
- {
347
- behindMs: { proxy: 9000, "proxy-control": 9000, "proxy-fast": 9000 },
348
- allowedWaitMs: mayWait
349
- }
350
- )
351
- );
352
- assert.equal(wedged.verdict, "association-stopped");
353
- });
354
-
355
- test("with no send time recorded the count still decides", () => {
356
- // A probe older than the history kept, or a connection that has just begun:
357
- // the reading is absent rather than wrong, and the old comparison stands.
358
- const { verdict } = readProbeState(
359
- state({ proxy: 40, "proxy-control": 41, "proxy-fast": 42 }, { behindMs: {}, allowedWaitMs: {} })
360
- );
361
- assert.equal(verdict, "association-stopped");
362
- });
363
-
364
- test("a one-way delay of a probe that arrived says nothing about one that did not", () => {
365
- // Field 2026-09-28, 10b53a7e: probe 1464 had taken 9 ms, and for the whole
366
- // wedge it stayed the newest the peer had seen. A one-way figure in the
367
- // state is not read: the age of that probe decides.
368
- const { verdict } = readProbeState(
369
- state(
370
- { proxy: 1464, "proxy-control": 1464, "proxy-fast": 1464 },
371
- {
372
- seq: 1526,
373
- behindMs: { proxy: 30_600, "proxy-control": 30_600, "proxy-fast": 30_600 },
374
- allowedWaitMs: { proxy: 1029, "proxy-control": 1029, "proxy-fast": 1029 },
375
- oneWayMs: { proxy: 9, "proxy-control": 9, "proxy-fast": 9 },
376
- allowedOneWayMs: { proxy: 13, "proxy-control": 13, "proxy-fast": 13 },
377
- peerBytesAdvancing: false
378
- }
379
- )
380
- );
381
- assert.equal(verdict, "association-stopped");
382
- });
@@ -1,206 +0,0 @@
1
- /**
2
- * @file What is wanted, by whom, and how urgently.
3
- *
4
- * These are the rules the download layer and the memory store both read, so a
5
- * defect here is a defect in two places at once. Everything is numbers: no
6
- * torrent, no library, no piece store.
7
- */
8
-
9
- import test from "node:test";
10
- import assert from "node:assert/strict";
11
-
12
- import { DemandRegister } from "../services/torrent/demand/DemandRegister.js";
13
- import { unionOf, Window } from "../services/torrent/demand/Window.js";
14
- import {
15
- isConditional,
16
- mayDisplaceSlowPeer,
17
- selectionPriority,
18
- Urgency
19
- } from "../services/torrent/demand/Urgency.js";
20
- import { nearestFirst, piecesNeededFor, piecesOf, piecesWithin } from "../services/torrent/demand/pieces.js";
21
-
22
- const MEGABYTE = 1024 * 1024;
23
-
24
- test("a window states bytes and refuses what it cannot mean", () => {
25
- const window = new Window({
26
- claimant: "video", fileIndex: 0, byteStart: 100, byteEnd: 199, urgency: Urgency.NEAR
27
- });
28
- assert.equal(window.byteLength, 100, "inclusive at both ends");
29
-
30
- assert.throws(() => new Window({
31
- claimant: "", fileIndex: 0, byteStart: 0, byteEnd: 1, urgency: 0
32
- }), /claimant/, "a window nobody can release is a leak with a name missing");
33
- assert.throws(() => new Window({
34
- claimant: "video", fileIndex: 0, byteStart: 200, byteEnd: 100, urgency: 0
35
- }), /Byte end/);
36
- assert.throws(() => new Window({
37
- claimant: "video", fileIndex: -1, byteStart: 0, byteEnd: 1, urgency: 0
38
- }), /File index/);
39
- });
40
-
41
- test("windows of different files are never merged", () => {
42
- const register = new DemandRegister();
43
- register.state({ claimant: "a", fileIndex: 0, byteStart: 0, byteEnd: 99, urgency: Urgency.NEAR });
44
- register.state({ claimant: "b", fileIndex: 1, byteStart: 0, byteEnd: 99, urgency: Urgency.NEAR });
45
-
46
- // Byte 50 of file 0 and byte 50 of file 1 are different bytes. Two viewers on
47
- // two episodes of one release is the ordinary case, not an edge one.
48
- assert.deepEqual(register.union(), [
49
- { byteStart: 0, byteEnd: 99 },
50
- { byteStart: 0, byteEnd: 99 }
51
- ]);
52
- assert.deepEqual(register.files(), [0, 1]);
53
- });
54
-
55
- test("the union of overlapping windows is their union, not their sum", () => {
56
- // Picture and sound are two readers of one file and their windows overlap by
57
- // construction. Adding them would report a demand that is not there.
58
- assert.deepEqual(
59
- unionOf([
60
- { byteStart: 0, byteEnd: 99 },
61
- { byteStart: 50, byteEnd: 149 }
62
- ]),
63
- [{ byteStart: 0, byteEnd: 149 }]
64
- );
65
- // Touching ranges are one run: 0-99 and 100-199 have nothing between them.
66
- assert.deepEqual(
67
- unionOf([
68
- { byteStart: 100, byteEnd: 199 },
69
- { byteStart: 0, byteEnd: 99 }
70
- ]),
71
- [{ byteStart: 0, byteEnd: 199 }]
72
- );
73
- assert.deepEqual(
74
- unionOf([
75
- { byteStart: 0, byteEnd: 99 },
76
- { byteStart: 200, byteEnd: 299 }
77
- ]),
78
- [{ byteStart: 0, byteEnd: 99 }, { byteStart: 200, byteEnd: 299 }],
79
- "a gap between them is a gap"
80
- );
81
- });
82
-
83
- test("a claimant states one window, and restating replaces it", () => {
84
- const register = new DemandRegister();
85
- register.state({ claimant: "video", fileIndex: 0, byteStart: 0, byteEnd: 99, urgency: Urgency.NEAR });
86
- register.state({ claimant: "video", fileIndex: 0, byteStart: 100, byteEnd: 199, urgency: Urgency.NEAR });
87
-
88
- // A reader walking a film restates its window many times a second. If those
89
- // accumulated, the download set would be the whole file within a minute.
90
- assert.equal(register.size, 1);
91
- assert.deepEqual(register.union(0), [{ byteStart: 100, byteEnd: 199 }]);
92
- });
93
-
94
- test("a withdrawal names its own claimant and nothing else", () => {
95
- const register = new DemandRegister();
96
- register.state({ claimant: "video", fileIndex: 0, byteStart: 0, byteEnd: 99, urgency: Urgency.NEAR });
97
- register.state({ claimant: "audio", fileIndex: 0, byteStart: 0, byteEnd: 99, urgency: Urgency.NEAR });
98
-
99
- assert.equal(register.withdraw("audio"), true);
100
- assert.equal(register.withdraw("audio"), false, "a second release withdraws nothing");
101
- assert.equal(register.withdraw("nobody"), false, "a stray release matches nothing");
102
- assert.equal(register.size, 1, "and video still wants what it wanted");
103
- });
104
-
105
- test("the speculative levels are stated only while nothing urgent is missing", () => {
106
- const register = new DemandRegister();
107
- register.state({ claimant: "video", fileIndex: 0, byteStart: 0, byteEnd: 99, urgency: Urgency.BLOCKED });
108
- register.state({ claimant: "fill", fileIndex: 0, byteStart: 1000, byteEnd: 9999, urgency: Urgency.TAIL });
109
- register.state({ claimant: "back", fileIndex: 0, byteStart: 0, byteEnd: 999, urgency: Urgency.BEHIND });
110
-
111
- // Something urgent is missing: the speculative levels are not stated at all.
112
- // Withdrawn, not lowered — a withdrawn window is not in the download set, so
113
- // a peer with nothing urgent to give cannot fall through to it and spend the
114
- // shared link on a piece nobody is waiting for.
115
- assert.deepEqual(
116
- register.levelsToState((window) => window.urgency !== Urgency.BLOCKED),
117
- [Urgency.BLOCKED, Urgency.NEAR, Urgency.AHEAD]
118
- );
119
-
120
- // Everything urgent has arrived: they are stated, in order.
121
- assert.deepEqual(
122
- register.levelsToState(() => true),
123
- [Urgency.BLOCKED, Urgency.NEAR, Urgency.AHEAD, Urgency.TAIL, Urgency.BEHIND]
124
- );
125
-
126
- // The tail is complete but the gap behind is not: the gap stays stated and
127
- // nothing below it exists to withhold.
128
- assert.deepEqual(
129
- register.levelsToState((window) => window.urgency !== Urgency.BEHIND),
130
- [Urgency.BLOCKED, Urgency.NEAR, Urgency.AHEAD, Urgency.TAIL, Urgency.BEHIND]
131
- );
132
- });
133
-
134
- test("only the level being waited on may take a block from a slow peer", () => {
135
- assert.equal(mayDisplaceSlowPeer(Urgency.BLOCKED), true);
136
- for (const urgency of [Urgency.NEAR, Urgency.AHEAD, Urgency.TAIL, Urgency.BEHIND]) {
137
- assert.equal(mayDisplaceSlowPeer(urgency), false);
138
- }
139
- });
140
-
141
- test("the library is given the only distinction it keeps", () => {
142
- // Measured against the vendored 2.8.5: distinct non-zero priorities order the
143
- // selection list once and are round-robined afterwards by `shufflePriority`.
144
- // Zero is the only value that stays put, always last.
145
- assert.equal(selectionPriority(Urgency.BLOCKED), 1);
146
- assert.equal(selectionPriority(Urgency.NEAR), 1);
147
- assert.equal(selectionPriority(Urgency.AHEAD), 1);
148
- assert.equal(selectionPriority(Urgency.TAIL), 0);
149
- assert.equal(selectionPriority(Urgency.BEHIND), 0);
150
-
151
- assert.equal(isConditional(Urgency.AHEAD), false);
152
- assert.equal(isConditional(Urgency.TAIL), true);
153
- });
154
-
155
- test("bytes become pieces in one place, and a partial piece is a whole piece", () => {
156
- const pieceLength = 4 * MEGABYTE;
157
- // A file starting one piece into the torrent, wanting its first byte.
158
- assert.deepEqual(
159
- piecesOf({ fileOffset: pieceLength, byteStart: 0, byteEnd: 0, pieceLength }),
160
- { from: 1, to: 1 }
161
- );
162
- // A range ending one byte into the next piece still needs that whole piece:
163
- // the protocol delivers and verifies nothing smaller.
164
- assert.deepEqual(
165
- piecesOf({ fileOffset: 0, byteStart: 0, byteEnd: pieceLength, pieceLength }),
166
- { from: 0, to: 1 }
167
- );
168
- assert.equal(piecesOf({ fileOffset: 0, byteStart: 10, byteEnd: 5, pieceLength }), null);
169
- assert.equal(piecesOf({ fileOffset: 0, byteStart: 0, byteEnd: 1, pieceLength: 0 }), null);
170
- });
171
-
172
- test("a budget buys whole places, and a window needs one more than it measures", () => {
173
- const pieceLength = 16 * MEGABYTE;
174
- // The failure this rounding hid: 64 MB of allowance is four places, and two
175
- // readers asking for 96 MB each want six. Counted in bytes the shortage is
176
- // plain; counted in floored pieces it is not.
177
- assert.equal(piecesWithin(64 * MEGABYTE, pieceLength), 4);
178
- assert.equal(piecesNeededFor(96 * MEGABYTE, pieceLength), 7, "six, plus the one it can straddle");
179
- assert.equal(piecesWithin(0, pieceLength), 0);
180
- assert.equal(piecesNeededFor(0, pieceLength), 0);
181
- });
182
-
183
- test("the gap behind the playhead is stated nearest first", () => {
184
- // WebTorrent walks a selection from its start upwards, so one claim over
185
- // everything behind the viewer would be fetched from the beginning of the
186
- // file — the end furthest from where a backward seek lands.
187
- const ranges = nearestFirst({ byteStart: 0, byteEnd: 999, parts: 4 });
188
- assert.equal(ranges.length, 4);
189
- assert.equal(ranges[0].byteEnd, 999, "the part nearest the playhead comes first");
190
- assert.equal(ranges[ranges.length - 1].byteStart, 0, "and the furthest comes last");
191
- for (const range of ranges) {
192
- assert.ok(range.byteStart <= range.byteEnd);
193
- }
194
- assert.deepEqual(nearestFirst({ byteStart: 10, byteEnd: 5, parts: 2 }), []);
195
- });
196
-
197
- test("a byte is as urgent as the most urgent thing that wants it", () => {
198
- const register = new DemandRegister();
199
- register.state({ claimant: "map:tail", fileIndex: 0, byteStart: 0, byteEnd: 999, urgency: Urgency.TAIL });
200
- register.state({ claimant: "map:near", fileIndex: 0, byteStart: 400, byteEnd: 599, urgency: Urgency.NEAR });
201
-
202
- assert.equal(register.urgencyAt(0, 100), Urgency.TAIL);
203
- assert.equal(register.urgencyAt(0, 500), Urgency.NEAR, "the overlap took the less urgent of the two");
204
- assert.equal(register.urgencyAt(0, 5000), null, "a byte nobody wants reported a level anyway");
205
- assert.equal(register.urgencyAt(1, 500), null, "byte 500 of another file is not this byte");
206
- });
@@ -1,72 +0,0 @@
1
- /**
2
- * @file The DHT's entry points are given as addresses, not names.
3
- *
4
- * Measured 2026-08-21 on the addon host. Two of the three bootstrap nodes the
5
- * library ships answer nothing: `router.bittorrent.com` and `router.utorrent.com`
6
- * did not reply to a hand-written `ping` at all, while a control datagram to a
7
- * DNS server came back in 20 ms. The third, `dht.transmissionbt.com`, is alive —
8
- * it answered `find_node` with eight nodes — but on a host with global IPv6 its
9
- * name resolves to an IPv6 address first, and the DHT's socket is IPv4, so by
10
- * name it was never reached. By name: 0 nodes after 21 s, every run. By address:
11
- * 22 nodes in 5 s.
12
- */
13
-
14
- import assert from "node:assert/strict";
15
- import test from "node:test";
16
-
17
- import { dhtNodeCount, parseBootstrapEntry, resolveDhtBootstrap } from "../services/torrent/torrent-pool.js";
18
-
19
- test("a bootstrap entry is split into host and port", () => {
20
- assert.deepEqual(parseBootstrapEntry("dht.libtorrent.org:25401"), {
21
- host: "dht.libtorrent.org",
22
- port: 25401
23
- });
24
- });
25
-
26
- test("an entry with no port gets the DHT's own", () => {
27
- assert.deepEqual(parseBootstrapEntry("router.bittorrent.com"), {
28
- host: "router.bittorrent.com",
29
- port: 6881
30
- });
31
- });
32
-
33
- test("an unusable entry is dropped rather than breaking the client", () => {
34
- // One bad line in the list must cost that node and nothing else — the DHT is
35
- // best-effort by nature and a typo here would otherwise take the whole client
36
- // down at construction.
37
- assert.equal(parseBootstrapEntry(""), null);
38
- assert.equal(parseBootstrapEntry(" "), null);
39
- assert.equal(parseBootstrapEntry("host:0"), null);
40
- assert.equal(parseBootstrapEntry("host:70000"), null);
41
- assert.equal(parseBootstrapEntry("host:not-a-port"), null);
42
- assert.equal(parseBootstrapEntry(":6881"), null);
43
- assert.equal(parseBootstrapEntry(null), null);
44
- assert.equal(parseBootstrapEntry(42), null);
45
- });
46
-
47
- test("the routing table's size is readable, and its absence is not an error", () => {
48
- assert.equal(dhtNodeCount({ dht: { nodes: { toArray: () => [1, 2, 3] } } }), 3);
49
- assert.equal(dhtNodeCount({ dht: { nodes: { toArray: () => [] } } }), 0);
50
- // A client built without a DHT, or one whose internals moved: the difference
51
- // between "no DHT" and "an empty DHT" is the whole point of the report, so
52
- // the first must not be printed as the second.
53
- assert.equal(dhtNodeCount({}), null);
54
- assert.equal(dhtNodeCount({ dht: {} }), null);
55
- assert.equal(dhtNodeCount(null), null);
56
- assert.equal(dhtNodeCount({ dht: { nodes: { toArray: () => { throw new Error("gone"); } } } }), null);
57
- });
58
-
59
- test("a name that will not resolve inside the cap is dropped, not waited on", async () => {
60
- // The whole call is awaited before the torrent client exists, so a resolver
61
- // that black-holes must cost the cap and not c-ares' own four tries.
62
- const started = Date.now();
63
- // `.invalid` is reserved by RFC 2606 and never resolves; the cap is what
64
- // bounds the wait when a resolver answers slowly rather than quickly.
65
- const resolved = await resolveDhtBootstrap(["nothing.invalid:6881"], 200);
66
- assert.deepEqual(resolved, []);
67
- assert.ok(Date.now() - started < 2000, "the cap, not the resolver, decided when to give up");
68
- });
69
-
70
- test("an empty list is an answer, not a failure", async () => {
71
- assert.deepEqual(await resolveDhtBootstrap([], 200), []);
72
- });