@torrent-tv/proxy 2.89.17 → 2.89.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -3
- package/package.json +10 -2
- package/server.js +0 -11
- package/utils/client-log-file.js +147 -42
- package/.claude/commands/opsx/apply.md +0 -155
- package/.claude/commands/opsx/archive.md +0 -160
- package/.claude/commands/opsx/explore.md +0 -174
- package/.claude/commands/opsx/propose.md +0 -109
- package/.claude/commands/opsx/sync.md +0 -143
- package/.claude/skills/openspec-apply-change/SKILL.md +0 -159
- package/.claude/skills/openspec-archive-change/SKILL.md +0 -117
- package/.claude/skills/openspec-explore/SKILL.md +0 -289
- package/.claude/skills/openspec-propose/SKILL.md +0 -113
- package/.claude/skills/openspec-sync-specs/SKILL.md +0 -147
- package/.dockerignore +0 -5
- package/AGENTS.md +0 -363
- package/CHANGELOG.md +0 -2377
- package/Dockerfile +0 -30
- package/biome.json +0 -412
- package/corpus.tmp.json +0 -1
- package/docs/browser-proxy-contract.md +0 -155
- package/docs/container-architecture.md +0 -273
- package/docs/download-architecture.md +0 -261
- package/docs/encode-architecture.md +0 -765
- package/docs/encode-run-state.md +0 -96
- package/docs/logs.md +0 -151
- package/docs/playback-start-forecast.md +0 -113
- package/docs/socks5-egress-research.md +0 -114
- package/docs/storage-architecture.md +0 -273
- package/knip.json +0 -14
- package/main2.cpuprofile +0 -1
- package/openspec/changes/adaptive-bitrate/.openspec.yaml +0 -0
- package/openspec/changes/adaptive-bitrate/design.md +0 -92
- package/openspec/changes/adaptive-bitrate/proposal.md +0 -56
- package/openspec/changes/adaptive-bitrate/specs/adaptive-bitrate/spec.md +0 -51
- package/openspec/changes/adaptive-bitrate/tasks.md +0 -40
- package/openspec/changes/binary-distribution/.openspec.yaml +0 -2
- package/openspec/changes/binary-distribution/proposal.md +0 -53
- package/openspec/changes/chunked-request-bodies/design.md +0 -81
- package/openspec/changes/chunked-request-bodies/proposal.md +0 -53
- package/openspec/changes/chunked-request-bodies/specs/chunked-request-bodies/spec.md +0 -30
- package/openspec/changes/chunked-request-bodies/tasks.md +0 -40
- package/openspec/changes/cold-start/design.md +0 -98
- package/openspec/changes/cold-start/proposal.md +0 -62
- package/openspec/changes/cold-start/specs/cold-start/spec.md +0 -47
- package/openspec/changes/cold-start/tasks.md +0 -48
- package/openspec/changes/disk-cap/.openspec.yaml +0 -2
- package/openspec/changes/disk-cap/proposal.md +0 -37
- package/openspec/changes/disk-cap/specs/disk-cap/spec.md +0 -25
- package/openspec/changes/disk-cap/tasks.md +0 -19
- package/openspec/changes/proxy-observability/.openspec.yaml +0 -2
- package/openspec/changes/proxy-observability/design.md +0 -38
- package/openspec/changes/proxy-observability/proposal.md +0 -49
- package/openspec/changes/proxy-observability/specs/observability/spec.md +0 -33
- package/openspec/changes/proxy-observability/tasks.md +0 -21
- package/openspec/changes/seek-debounce/.openspec.yaml +0 -0
- package/openspec/changes/seek-debounce/design.md +0 -118
- package/openspec/changes/seek-debounce/proposal.md +0 -59
- package/openspec/changes/seek-debounce/specs/seek-debounce/spec.md +0 -41
- package/openspec/changes/seek-debounce/tasks.md +0 -33
- package/openspec/changes/subtitle-language/.openspec.yaml +0 -2
- package/openspec/changes/subtitle-language/proposal.md +0 -50
- package/openspec/changes/subtitle-language/specs/subtitle-language/spec.md +0 -34
- package/openspec/changes/subtitle-language/tasks.md +0 -26
- package/openspec/changes/track-selection/.openspec.yaml +0 -2
- package/openspec/changes/track-selection/design.md +0 -47
- package/openspec/changes/track-selection/proposal.md +0 -45
- package/openspec/changes/track-selection/specs/track-selection/spec.md +0 -41
- package/openspec/changes/track-selection/tasks.md +0 -20
- package/openspec/changes/transcode-quality/.openspec.yaml +0 -2
- package/openspec/changes/transcode-quality/proposal.md +0 -51
- package/openspec/changes/transcode-quality/specs/transcode-quality/spec.md +0 -139
- package/openspec/changes/transcode-quality/tasks.md +0 -63
- package/openspec/config.yaml +0 -38
- package/public/.well-known/appspecific/com.chrome.devtools.json +0 -1
- package/research/delivery-wedge-stand-ladder-2026-09-13.md +0 -329
- package/research/double-spawn-2026-09-10.md +0 -171
- package/research/handover-2026-09-13.md +0 -209
- package/research/handover-reader-claims-removal-2026-09-12.md +0 -166
- package/research/piece-withdrawn-but-still-claimed-2026-09-12.md +0 -175
- package/research/preset-benchmark-size-scaling-2026-08-22.md +0 -55
- package/research/priority-map-is-the-truth-2026-09-12.md +0 -225
- package/research/valgrind-replica-2026-08-27/logs.tar.gz +0 -0
- package/scripts/build-audio-samples.mjs +0 -31
- package/scripts/render-run-graph.js +0 -173
- package/test/asset-paths.test.js +0 -28
- package/test/audio-buffer-continuity.test.js +0 -77
- package/test/audio-calibration.test.js +0 -23
- package/test/audio-inventory.test.js +0 -212
- package/test/audio-track-bitrate.test.js +0 -40
- package/test/audio-warm-recorded.test.js +0 -63
- package/test/auto-quality-step.test.js +0 -762
- package/test/available-share.test.js +0 -76
- package/test/background-fill.test.js +0 -190
- package/test/client-log-file.test.js +0 -126
- package/test/client-logs-route.test.js +0 -34
- package/test/coalesce.test.js +0 -39
- package/test/completed-files.test.js +0 -115
- package/test/concurrent-cost.test.js +0 -148
- package/test/container-media-info.test.js +0 -228
- package/test/contention.test.js +0 -76
- package/test/core-dumps.test.js +0 -57
- package/test/coverage-follows-the-disk.test.js +0 -233
- package/test/coverage-map.test.js +0 -195
- package/test/cue-push-carries-what-the-walk-found.test.js +0 -58
- package/test/cut-times-timeline.test.js +0 -65
- package/test/cuts-follow-published-grid.test.js +0 -109
- package/test/data-channel-frame.test.js +0 -63
- package/test/data-channel-viewer-lifecycle.test.js +0 -193
- package/test/dead-torrent-handle.test.js +0 -52
- package/test/declared-rates.test.js +0 -116
- package/test/declared-tracks.test.js +0 -43
- package/test/decode-cost-fit.test.js +0 -202
- package/test/decode-cost.test.js +0 -475
- package/test/delivery-probe-field.test.js +0 -173
- package/test/delivery-probe.test.js +0 -382
- package/test/demand-register.test.js +0 -206
- package/test/dht-bootstrap.test.js +0 -72
- package/test/drain-threat.test.js +0 -65
- package/test/duplicate-add.test.js +0 -48
- package/test/encode-admission.test.js +0 -170
- package/test/encode-cost.test.js +0 -275
- package/test/encode-exit.test.js +0 -111
- package/test/encode-orchestrator.test.js +0 -426
- package/test/encode-plan-viewers.test.js +0 -725
- package/test/encode-plan.test.js +0 -545
- package/test/encode-run-state.test.js +0 -314
- package/test/encode-run.test.js +0 -248
- package/test/encode-slope.test.js +0 -46
- package/test/encoded-output.test.js +0 -39
- package/test/encoder-kinds.test.js +0 -122
- package/test/encoder-readings.test.js +0 -68
- package/test/episode-naming.test.js +0 -131
- package/test/every-claimant-is-told-its-share.test.js +0 -152
- package/test/failed-encoder-still-serves-what-exists.test.js +0 -354
- package/test/failed-start-breaker.test.js +0 -202
- package/test/fastest-wires.test.js +0 -143
- package/test/ffmpeg-stream-counts.test.js +0 -101
- package/test/file-edges.test.js +0 -191
- package/test/files-in-use.test.js +0 -34
- package/test/fixtures/audio-frame-boundary.json +0 -1
- package/test/fixtures/refused-audio-20261002.json +0 -10
- package/test/fmp4-presentation-clock.test.js +0 -148
- package/test/fmp4-self-contained.test.js +0 -80
- package/test/fmp4-timestamps.test.js +0 -140
- package/test/fmp4-track-completeness.test.js +0 -41
- package/test/format-keyed-outputs.test.js +0 -78
- package/test/health-metrics.test.js +0 -36
- package/test/held-read-ownership.test.js +0 -77
- package/test/held-request-width.test.js +0 -157
- package/test/helpers/encode-run.js +0 -248
- package/test/helpers/held-file.js +0 -77
- package/test/helpers/manager.js +0 -62
- package/test/helpers/matroska-file.js +0 -296
- package/test/helpers/output-spec.js +0 -63
- package/test/host-load.test.js +0 -68
- package/test/index-accuracy-is-about-the-file.test.js +0 -128
- package/test/init-compat.test.js +0 -219
- package/test/input-lost-quiets-the-plan.test.js +0 -261
- package/test/input-unavailable.test.js +0 -48
- package/test/installation-id.test.js +0 -39
- package/test/keeping-period.test.js +0 -83
- package/test/keyframe-index-accuracy.test.js +0 -188
- package/test/keyframe-table-budget.test.js +0 -123
- package/test/keyframes-belong-to-the-file.test.js +0 -249
- package/test/learned-median.test.js +0 -37
- package/test/letting-go-asks-who-is-watching.test.js +0 -191
- package/test/limit-row-by-area.test.js +0 -60
- package/test/link-budget.test.js +0 -111
- package/test/link-probe.test.js +0 -56
- package/test/local-encoding-data.test.js +0 -273
- package/test/logger-repeats.test.js +0 -134
- package/test/look-ahead-coverage.test.js +0 -56
- package/test/manager-surface.test.js +0 -291
- package/test/matroska-blocks.test.js +0 -0
- package/test/matroska-cluster-discovery.test.js +0 -323
- package/test/matroska-cues-track.test.js +0 -192
- package/test/media-time.test.js +0 -62
- package/test/memory-budget.test.js +0 -390
- package/test/move-cost.test.js +0 -216
- package/test/mp4-composition-times.test.js +0 -0
- package/test/mp4-subtitles.test.js +0 -173
- package/test/one-authority.test.js +0 -285
- package/test/one-budget.test.js +0 -149
- package/test/one-output-one-session.test.js +0 -273
- package/test/one-resource-divided.test.js +0 -185
- package/test/one-serving-output-per-height.test.js +0 -458
- package/test/orchestrator-wired.test.js +0 -207
- package/test/output-catalog.test.js +0 -39
- package/test/output-shape.test.js +0 -21
- package/test/output-spec.test.js +0 -251
- package/test/output-speed.test.js +0 -92
- package/test/outputs-being-prepared.test.js +0 -40
- package/test/packet-witness-ring.test.js +0 -236
- package/test/packet-witness.test.js +0 -148
- package/test/piece-completeness.test.js +0 -78
- package/test/piece-disk-store.test.js +0 -401
- package/test/piece-from-whole-file.test.js +0 -129
- package/test/piece-lru.test.js +0 -319
- package/test/piece-reader.test.js +0 -162
- package/test/piece-selection-offset.test.js +0 -85
- package/test/piece-store-eviction.test.js +0 -595
- package/test/piece-store-never-refuses.test.js +0 -153
- package/test/piece-store-reservations.test.js +0 -403
- package/test/piece-store-slow-disk.test.js +0 -159
- package/test/piece-tail.test.js +0 -97
- package/test/plan-host-timings.test.js +0 -68
- package/test/plan-is-steady.test.js +0 -225
- package/test/playback-readiness.test.js +0 -518
- package/test/playback-start-regressions.test.js +0 -101
- package/test/priority-map-download.test.js +0 -174
- package/test/priority-map-emptied.test.js +0 -204
- package/test/priority-map-per-output.test.js +0 -215
- package/test/priority-map.test.js +0 -163
- package/test/probe-wedge-certainty.test.js +0 -60
- package/test/produced-copy-choice.test.js +0 -213
- package/test/published-timeline.test.js +0 -83
- package/test/quality-offer.test.js +0 -160
- package/test/quality-variants.test.js +0 -1274
- package/test/rate-control-in-the-output.test.js +0 -181
- package/test/read-survives-withdrawal.test.js +0 -164
- package/test/read-window.test.js +0 -365
- package/test/reads-not-yet-arrived.test.js +0 -218
- package/test/resume-warm.test.js +0 -39
- package/test/run-graph-drift.test.js +0 -37
- package/test/run-inputs.test.js +0 -80
- package/test/run-intervals.test.js +0 -100
- package/test/run-position-follows-published-grid.test.js +0 -89
- package/test/run-progress.test.js +0 -64
- package/test/same-height-switch.test.js +0 -663
- package/test/seek-frees-the-viewers-requests.test.js +0 -217
- package/test/seek-landing.test.js +0 -109
- package/test/seek-target-not-superseded.test.js +0 -195
- package/test/segment-closed-on-both-branches.test.js +0 -114
- package/test/segment-cut-times.test.js +0 -63
- package/test/segment-demand.test.js +0 -80
- package/test/segment-hold-supersede.test.js +0 -91
- package/test/segment-judged-by-its-own-header.test.js +0 -222
- package/test/segment-serve-wiring.test.js +0 -481
- package/test/segment-store-eviction.test.js +0 -247
- package/test/segment-store.test.js +0 -352
- package/test/segment-true-start.test.js +0 -86
- package/test/segments-are-shared.test.js +0 -176
- package/test/send-chunk-bytes.test.js +0 -86
- package/test/serving-existing-output.test.js +0 -111
- package/test/serving-output.test.js +0 -102
- package/test/shared-piece-store.test.js +0 -310
- package/test/sidecar-naming.test.js +0 -142
- package/test/soundtrack-rate-bound.test.js +0 -289
- package/test/source-file.test.js +0 -133
- package/test/source-files-route.test.js +0 -113
- package/test/source-registry.test.js +0 -18
- package/test/split-a-stretch.test.js +0 -139
- package/test/stale-request-after-seek.test.js +0 -158
- package/test/startup-readings.test.js +0 -124
- package/test/stream-route.test.js +0 -237
- package/test/subtitle-cue-framing.test.js +0 -200
- package/test/subtitle-cue-source.test.js +0 -102
- package/test/subtitle-cue-walk.test.js +0 -385
- package/test/subtitle-cursor.test.js +0 -63
- package/test/subtitle-defaults.test.js +0 -118
- package/test/subtitle-language.test.js +0 -252
- package/test/subtitle-metadata.test.js +0 -15
- package/test/subtitle-plan-waits.test.js +0 -125
- package/test/subtitle-track-numbering.test.js +0 -391
- package/test/supply-margin.test.js +0 -190
- package/test/swarm-follows-readers.test.js +0 -174
- package/test/swarm-reach.test.js +0 -130
- package/test/swarm-selection.test.js +0 -220
- package/test/tail-duplication.test.js +0 -167
- package/test/the-channel-has-both-ends.test.js +0 -91
- package/test/the-torrent-thread-serves-bytes.test.js +0 -107
- package/test/thread-pool.test.js +0 -53
- package/test/timeline.test.js +0 -84
- package/test/torrent-contents.test.js +0 -235
- package/test/torrent-cost.test.js +0 -71
- package/test/torrent-files.test.js +0 -221
- package/test/torrent-naming.test.js +0 -255
- package/test/tracks-begin-together.test.js +0 -209
- package/test/tunnel-renewal.test.js +0 -167
- package/test/two-viewers-one-picture.test.js +0 -508
- package/test/upload-hurry.test.js +0 -186
- package/test/usrsctp-state.test.js +0 -131
- package/test/video-facts.test.js +0 -102
- package/test/viewer-assignments.test.js +0 -143
- package/test/viewer-outputs.test.js +0 -285
- package/test/viewer-presence.test.js +0 -116
- package/test/viewer-requests-admission.test.js +0 -92
- package/test/viewer-starts-on-map.test.js +0 -27
- package/test/viewer-states.test.js +0 -192
- package/test/viewer-subtitle-subscription.test.js +0 -96
- package/test/viewer.test.js +0 -139
- package/test/viewing-generations.test.js +0 -390
- package/test/visible-rung.test.js +0 -37
- package/test/wait-ledger.test.js +0 -100
- package/test/webrtc-shim.test.js +0 -149
- package/test/wedge-certainty.test.js +0 -131
- package/test/whole-file-held-read.test.js +0 -30
- package/test/withdraw-piece-claim.test.js +0 -212
- package/test/worker-channel.test.js +0 -158
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file The packet witness's gating rules and command construction.
|
|
3
|
-
*
|
|
4
|
-
* Roadmap item 10: a send queue wedged longer than ~30 s must start a bounded
|
|
5
|
-
* tcpdump on its own, because the 2026-08-24 episode proved no counter above
|
|
6
|
-
* the wire can name the cause. Everything here is the part that decides WHEN
|
|
7
|
-
* and WITH WHAT ARGUMENTS — the spawning itself is thin glue around these.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import assert from "node:assert/strict";
|
|
11
|
-
import test from "node:test";
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
buildTcpdumpArgs,
|
|
15
|
-
createPacketWitness,
|
|
16
|
-
isWitnessCapture,
|
|
17
|
-
isWitnessRingFile,
|
|
18
|
-
normalizeRemoteAddress,
|
|
19
|
-
shouldStartCapture,
|
|
20
|
-
WITNESS_RING_FILE_MB,
|
|
21
|
-
WITNESS_RING_FILES,
|
|
22
|
-
WITNESS_RTO_CEILING_SECONDS,
|
|
23
|
-
WITNESS_TAIL_SECONDS
|
|
24
|
-
} from "../services/transport/packet-witness.js";
|
|
25
|
-
|
|
26
|
-
test("an IPv4 literal survives unchanged", () => {
|
|
27
|
-
assert.equal(normalizeRemoteAddress("192.168.178.57"), "192.168.178.57");
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("an IPv6 literal survives unchanged", () => {
|
|
31
|
-
assert.equal(
|
|
32
|
-
normalizeRemoteAddress("2001:1c00:a603:2100:a129:a1a1:7f07:3f0b"),
|
|
33
|
-
"2001:1c00:a603:2100:a129:a1a1:7f07:3f0b"
|
|
34
|
-
);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test("a zone suffix is stripped", () => {
|
|
38
|
-
assert.equal(normalizeRemoteAddress("fe80::2aca:8001:3ba6:f16f%18"), "fe80::2aca:8001:3ba6:f16f");
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test("hostnames, garbage and shell text are rejected", () => {
|
|
42
|
-
assert.equal(normalizeRemoteAddress("homeassistant.local"), null);
|
|
43
|
-
assert.equal(normalizeRemoteAddress("8.8.8.8; rm -rf /"), null);
|
|
44
|
-
assert.equal(normalizeRemoteAddress("999.1.1.1"), null);
|
|
45
|
-
assert.equal(normalizeRemoteAddress(""), null);
|
|
46
|
-
assert.equal(normalizeRemoteAddress(undefined), null);
|
|
47
|
-
assert.equal(normalizeRemoteAddress(42), null);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test("the tcpdump command line is bounded and filtered to one peer", () => {
|
|
51
|
-
const args = buildTcpdumpArgs({
|
|
52
|
-
host: "2001:db8::1",
|
|
53
|
-
port: 9090,
|
|
54
|
-
filePrefix: "/data/packet-witness.e2b5ef39.1787600000.pcap"
|
|
55
|
-
});
|
|
56
|
-
assert.deepEqual(args, [
|
|
57
|
-
"-n",
|
|
58
|
-
"-S",
|
|
59
|
-
"-s",
|
|
60
|
-
"128",
|
|
61
|
-
"-i",
|
|
62
|
-
"any",
|
|
63
|
-
"-w",
|
|
64
|
-
"/data/packet-witness.e2b5ef39.1787600000.pcap",
|
|
65
|
-
"-C",
|
|
66
|
-
String(WITNESS_RING_FILE_MB),
|
|
67
|
-
"-W",
|
|
68
|
-
String(WITNESS_RING_FILES),
|
|
69
|
-
"udp",
|
|
70
|
-
"and",
|
|
71
|
-
"port",
|
|
72
|
-
"9090",
|
|
73
|
-
"and",
|
|
74
|
-
"host",
|
|
75
|
-
"2001:db8::1"
|
|
76
|
-
]);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test("rotation is by size, so the ring files cannot collapse onto one name", () => {
|
|
80
|
-
// `-G` with a name carrying no strftime field overwrote a single file, which
|
|
81
|
-
// is why both field captures held 28 s instead of the intended 120.
|
|
82
|
-
const args = buildTcpdumpArgs({ port: 9090, filePrefix: "/data/ring.pcap" });
|
|
83
|
-
assert.equal(args.includes("-G"), false);
|
|
84
|
-
assert.equal(args[args.indexOf("-C") + 1], String(WITNESS_RING_FILE_MB));
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test("with no peer named the ring records every peer on the port", () => {
|
|
88
|
-
const args = buildTcpdumpArgs({ port: 9090, filePrefix: "/data/ring.pcap" });
|
|
89
|
-
assert.equal(args.includes("host"), false);
|
|
90
|
-
assert.deepEqual(args.slice(-4), ["udp", "and", "port", "9090"]);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
test("the tail outlasts three retransmission timeouts", () => {
|
|
94
|
-
assert.equal(WITNESS_TAIL_SECONDS, WITNESS_RTO_CEILING_SECONDS * 3);
|
|
95
|
-
// A zero-window probe is due once per timeout, so a window shorter than the
|
|
96
|
-
// ceiling could not tell silence from a probe that had not come round yet.
|
|
97
|
-
assert.ok(WITNESS_TAIL_SECONDS > WITNESS_RTO_CEILING_SECONDS);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test("ring files are told apart from the copies kept as evidence", () => {
|
|
101
|
-
assert.equal(isWitnessRingFile("packet-witness-ring.pcap"), true);
|
|
102
|
-
assert.equal(isWitnessRingFile("packet-witness-ring.pcap3"), true);
|
|
103
|
-
assert.equal(isWitnessRingFile("packet-witness.e2b5ef39.1787600000.before1.pcap"), false);
|
|
104
|
-
assert.equal(isWitnessCapture("packet-witness-ring.pcap3"), false);
|
|
105
|
-
assert.equal(isWitnessCapture("packet-witness.e2b5ef39.1787600000.before1.pcap"), true);
|
|
106
|
-
assert.equal(isWitnessCapture("packet-witness.e2b5ef39.1787600000.tail.pcap1"), true);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test("one capture runs at a time", () => {
|
|
110
|
-
assert.equal(shouldStartCapture({ running: true, lastStartedAt: Date.now() }), false);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test("the first capture of a process is always allowed", () => {
|
|
114
|
-
assert.equal(shouldStartCapture({ running: false, lastStartedAt: 0, now: 1000 }), true);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test("a capture within the cooldown is refused, one after it is allowed", () => {
|
|
118
|
-
const state = { running: false, lastStartedAt: 10_000 };
|
|
119
|
-
assert.equal(shouldStartCapture({ ...state, now: 10_000 + 599_999 }), false);
|
|
120
|
-
assert.equal(shouldStartCapture({ ...state, now: 10_000 + 600_000 }), true);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test("capture files are recognised by name, rotations included", () => {
|
|
124
|
-
assert.equal(isWitnessCapture("packet-witness.e2b5ef39.1787600000.pcap"), true);
|
|
125
|
-
assert.equal(isWitnessCapture("packet-witness.e2b5ef39.1787600000.pcap20260825T120000"), true);
|
|
126
|
-
assert.equal(isWitnessCapture("core.WorkerThread.81.1787600000"), false);
|
|
127
|
-
assert.equal(isWitnessCapture("proxy.log"), false);
|
|
128
|
-
assert.equal(isWitnessCapture("../packet-witness.x.pcap"), false);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test("a trigger without a usable remote endpoint is refused without touching anything", () => {
|
|
132
|
-
const lines = [];
|
|
133
|
-
const witness = createPacketWitness({
|
|
134
|
-
log: (message) => lines.push(message),
|
|
135
|
-
dir: "",
|
|
136
|
-
port: 9090
|
|
137
|
-
});
|
|
138
|
-
const started = witness.maybeCapture({
|
|
139
|
-
sessionId: "e2b5ef39-0000",
|
|
140
|
-
tag: "e2b5ef39",
|
|
141
|
-
label: "proxy",
|
|
142
|
-
remote: null,
|
|
143
|
-
queuedBytes: 160_000_000,
|
|
144
|
-
stuckForMs: 31_000
|
|
145
|
-
});
|
|
146
|
-
assert.equal(started, false);
|
|
147
|
-
assert.deepEqual(lines, []);
|
|
148
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Whether a closed piece holds the whole of its stretch of film.
|
|
3
|
-
*
|
|
4
|
-
* Decided by the encoding from the cut table and the piece's own media; the
|
|
5
|
-
* segment store only keeps what it is given.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import test from "node:test";
|
|
9
|
-
import assert from "node:assert/strict";
|
|
10
|
-
import { cutOf, judgePiece, originOf, productionOf } from "../services/encode/piece-completeness.js";
|
|
11
|
-
import { SEGMENT_CUT_TIME_DELTA_SECONDS } from "../services/encode/output/index.js";
|
|
12
|
-
import { readFileSync } from "node:fs";
|
|
13
|
-
import { fmp4Format } from "../services/encode/segment-formats/fmp4.js";
|
|
14
|
-
|
|
15
|
-
const evidence = JSON.parse(readFileSync(new URL("./fixtures/refused-audio-20261002.json", import.meta.url)));
|
|
16
|
-
const captured = (name) => fmp4Format.readMediaRanges(Buffer.from(evidence.files[name], "base64"));
|
|
17
|
-
|
|
18
|
-
/** Media ending where stated, in the shape a format's reading has. */
|
|
19
|
-
const endingAt = (seconds) => ({ end: seconds });
|
|
20
|
-
const format = { producedThroughSeconds: (ranges) => ranges?.end ?? null };
|
|
21
|
-
|
|
22
|
-
/** Cuts every ten seconds, ten pieces. */
|
|
23
|
-
const timeline = { segmentCount: 10, publishedStartOf: (index) => index * 10 };
|
|
24
|
-
|
|
25
|
-
test("a piece must reach its next cut less the delta the muxer is given", () => {
|
|
26
|
-
assert.equal(cutOf(timeline, 3), 40 - SEGMENT_CUT_TIME_DELTA_SECONDS);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test("the final piece has no next cut", () => {
|
|
30
|
-
assert.equal(cutOf(timeline, 9), undefined);
|
|
31
|
-
assert.deepEqual(judgePiece(format, endingAt(95), cutOf(timeline, 9)), { whole: true, throughSeconds: 95 });
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test("an audio piece ending within the delta of its cut is whole", () => {
|
|
35
|
-
// Field 2026-10-01: AAC frames end 4.7389 s into a piece cut at 4.755 s.
|
|
36
|
-
const cut = 4.755 - SEGMENT_CUT_TIME_DELTA_SECONDS;
|
|
37
|
-
assert.equal(judgePiece(format, endingAt(4.738913832199547), cut).whole, true);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
test("a piece closed short of its cut is not whole", () => {
|
|
41
|
-
// A run killed mid-piece: 84 ms of film where ten seconds were cut.
|
|
42
|
-
assert.deepEqual(judgePiece(format, endingAt(456.084), 466), { whole: false, throughSeconds: 456.084 });
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test("a piece with no playable media is not whole, whatever its cut", () => {
|
|
46
|
-
assert.deepEqual(judgePiece(format, null, undefined), { whole: false, throughSeconds: null });
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test("captured whole AAC pieces survive movie-time truncation and decimal cut subtraction", () => {
|
|
50
|
-
for (const [name, next] of [["making-0-00013.mp4", 81.415], ["making-0-00090.mp4", 618.076]]) {
|
|
51
|
-
const cut = cutOf({ segmentCount: 2, publishedStartOf: () => next }, 0);
|
|
52
|
-
const ranges = captured(name);
|
|
53
|
-
assert.equal(ranges.tracks[0].positionErrorTicks, 48n);
|
|
54
|
-
assert.equal(judgePiece(fmp4Format, ranges, cut).whole, true, name);
|
|
55
|
-
ranges.tracks[0].ranges.at(-1).end -= 1024n;
|
|
56
|
-
assert.equal(judgePiece(fmp4Format, ranges, cut).whole, false, "one lost AAC frame remains a refusal");
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test("a restarted AAC cut follows its first packet rather than the requested seek", () => {
|
|
61
|
-
const ranges = captured("repair-13.mp4");
|
|
62
|
-
assert.equal(originOf(ranges, 81_364_000n, "soun"), 71_550_667n);
|
|
63
|
-
// The captured first packet is 71.5506667 s, 21.333 ms before -ss 71.572.
|
|
64
|
-
// segment.c adds it to the relative cut (81.415 - 71.572 = 9.843).
|
|
65
|
-
ranges.production = productionOf({ originMicros: 71_550_667n, endMicros: 81_364_000n }, [9.843], 0, "soun");
|
|
66
|
-
assert.equal(ranges.production.cutMicros, 81_343_667n);
|
|
67
|
-
assert.equal(judgePiece(fmp4Format, ranges, 81.365).whole, true);
|
|
68
|
-
ranges.production.endMicros -= 1024n * 1_000_000n / 48_000n;
|
|
69
|
-
assert.equal(judgePiece(fmp4Format, ranges, 81.365).whole, false);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test("a muxer's reference clock cannot conceal a shorter multiplexed track", () => {
|
|
73
|
-
const ranges = captured("making-0-00013.mp4");
|
|
74
|
-
ranges.production = productionOf({ originMicros: 0n, endMicros: 81_365_333n }, [81.415], 0, "soun");
|
|
75
|
-
const audio = ranges.tracks[0];
|
|
76
|
-
ranges.tracks.push({ ...audio, kind: "vide", ranges: audio.ranges.map(range => ({ ...range, end: range.end - 4800n })) });
|
|
77
|
-
assert.equal(judgePiece(fmp4Format, ranges, 81.365).whole, false);
|
|
78
|
-
});
|
|
@@ -1,401 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file The spilled pieces are bounded, and the bound returns disk.
|
|
3
|
-
*
|
|
4
|
-
* What these pin is the difference between this store and the tier it replaced.
|
|
5
|
-
* That one wrote into one sparse file and answered `forget` by dropping a
|
|
6
|
-
* number: nothing it did returned a block, and a store holding 400 MB had
|
|
7
|
-
* written 14.4 GB to the disk in fifty minutes (field 2026-08-31). So the
|
|
8
|
-
* assertions here are about the DISK, read back from the file system, not about
|
|
9
|
-
* the store's own bookkeeping — the bookkeeping was never what was wrong.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import test from "node:test";
|
|
13
|
-
import assert from "node:assert/strict";
|
|
14
|
-
import fs from "node:fs/promises";
|
|
15
|
-
import os from "node:os";
|
|
16
|
-
import path from "node:path";
|
|
17
|
-
import { PieceDiskStore } from "../services/storage/piece-store/piece-disk-store.js";
|
|
18
|
-
|
|
19
|
-
const PIECE = 4096;
|
|
20
|
-
|
|
21
|
-
test("bytes held before a memory wait cannot be forgotten or evicted", async () => {
|
|
22
|
-
const { store } = await makeStore(PIECE);
|
|
23
|
-
try {
|
|
24
|
-
await store.write(0, Buffer.alloc(PIECE, 7));
|
|
25
|
-
const release = store.hold(0);
|
|
26
|
-
store.forget(0);
|
|
27
|
-
store.forgetBehind([1]);
|
|
28
|
-
await store.write(1, Buffer.alloc(PIECE, 8));
|
|
29
|
-
const target = Buffer.alloc(PIECE);
|
|
30
|
-
assert.equal(await store.read(0, target), PIECE);
|
|
31
|
-
assert.equal(target[0], 7);
|
|
32
|
-
release();
|
|
33
|
-
release();
|
|
34
|
-
store.forget(0);
|
|
35
|
-
assert.equal(store.has(0), false);
|
|
36
|
-
} finally {
|
|
37
|
-
await store.destroy();
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @param {number | null} allowanceBytes
|
|
43
|
-
* @returns {Promise<{ store: PieceDiskStore, directory: string, clock: { at: number } }>}
|
|
44
|
-
*/
|
|
45
|
-
async function makeStore(allowanceBytes) {
|
|
46
|
-
const directory = await fs.mkdtemp(path.join(os.tmpdir(), "piece-disk-test-"));
|
|
47
|
-
const clock = { at: 1000 };
|
|
48
|
-
const store = new PieceDiskStore({
|
|
49
|
-
directory,
|
|
50
|
-
name: "pieces",
|
|
51
|
-
chunkLength: PIECE,
|
|
52
|
-
allowanceBytes,
|
|
53
|
-
now: () => clock.at
|
|
54
|
-
});
|
|
55
|
-
return { store, directory, clock };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* What the store's directory actually holds, in bytes and in files.
|
|
60
|
-
*
|
|
61
|
-
* @param {PieceDiskStore} store
|
|
62
|
-
* @returns {Promise<{ files: number, bytes: number }>}
|
|
63
|
-
*/
|
|
64
|
-
async function onDisk(store) {
|
|
65
|
-
let names = [];
|
|
66
|
-
try {
|
|
67
|
-
names = await fs.readdir(store.path);
|
|
68
|
-
} catch {
|
|
69
|
-
return { files: 0, bytes: 0 };
|
|
70
|
-
}
|
|
71
|
-
let bytes = 0;
|
|
72
|
-
for (const name of names) {
|
|
73
|
-
const stat = await fs.stat(path.join(store.path, name));
|
|
74
|
-
bytes += stat.size;
|
|
75
|
-
}
|
|
76
|
-
return { files: names.length, bytes };
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const pieceOf = (index) => Buffer.alloc(PIECE, index % 251);
|
|
80
|
-
|
|
81
|
-
test("told nothing, it holds everything — which is what it did before it could count", async () => {
|
|
82
|
-
const { store, directory } = await makeStore(null);
|
|
83
|
-
try {
|
|
84
|
-
for (let index = 0; index < 8; index += 1) {
|
|
85
|
-
await store.write(index, pieceOf(index));
|
|
86
|
-
}
|
|
87
|
-
assert.equal(store.size, 8, "a store with no allowance threw something away");
|
|
88
|
-
assert.equal(store.bytes, 8 * PIECE);
|
|
89
|
-
assert.deepEqual(await onDisk(store), { files: 8, bytes: 8 * PIECE });
|
|
90
|
-
} finally {
|
|
91
|
-
await store.destroy();
|
|
92
|
-
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test("over its allowance it throws the least recently used away, and the disk shrinks with it", async () => {
|
|
97
|
-
const { store, directory, clock } = await makeStore(3 * PIECE);
|
|
98
|
-
try {
|
|
99
|
-
for (const index of [0, 1, 2]) {
|
|
100
|
-
clock.at += 100;
|
|
101
|
-
await store.write(index, pieceOf(index));
|
|
102
|
-
}
|
|
103
|
-
assert.deepEqual(await onDisk(store), { files: 3, bytes: 3 * PIECE }, "the store did not fill");
|
|
104
|
-
|
|
105
|
-
// Piece 0 is the oldest and nobody has read it since.
|
|
106
|
-
clock.at += 100;
|
|
107
|
-
await store.write(3, pieceOf(3));
|
|
108
|
-
await store.settled();
|
|
109
|
-
|
|
110
|
-
assert.equal(store.has(0), false, "the oldest piece was kept");
|
|
111
|
-
assert.equal(store.has(3), true, "the arriving piece was not stored");
|
|
112
|
-
assert.equal(store.bytes, 3 * PIECE, "the store counts more than its allowance");
|
|
113
|
-
// THE POINT: not the count in memory, the blocks on the disk.
|
|
114
|
-
assert.deepEqual(
|
|
115
|
-
await onDisk(store),
|
|
116
|
-
{ files: 3, bytes: 3 * PIECE },
|
|
117
|
-
"the disk kept the bytes of the piece that was thrown away"
|
|
118
|
-
);
|
|
119
|
-
assert.equal(store.stats().evictions, 1);
|
|
120
|
-
} finally {
|
|
121
|
-
await store.destroy();
|
|
122
|
-
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
test("reading a piece keeps it: the oldest is not the least wanted", async () => {
|
|
127
|
-
const { store, directory, clock } = await makeStore(3 * PIECE);
|
|
128
|
-
try {
|
|
129
|
-
for (const index of [0, 1, 2]) {
|
|
130
|
-
clock.at += 100;
|
|
131
|
-
await store.write(index, pieceOf(index));
|
|
132
|
-
}
|
|
133
|
-
// Piece 0 is read, which makes piece 1 the oldest.
|
|
134
|
-
clock.at += 100;
|
|
135
|
-
await store.read(0, Buffer.alloc(PIECE));
|
|
136
|
-
|
|
137
|
-
clock.at += 100;
|
|
138
|
-
await store.write(3, pieceOf(3));
|
|
139
|
-
await store.settled();
|
|
140
|
-
|
|
141
|
-
assert.equal(store.has(0), true, "a piece that was just read was thrown away");
|
|
142
|
-
assert.equal(store.has(1), false, "the piece nobody had touched was kept");
|
|
143
|
-
} finally {
|
|
144
|
-
await store.destroy();
|
|
145
|
-
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
test("a piece being read is never the victim, however old it is", async () => {
|
|
150
|
-
const { store, directory, clock } = await makeStore(3 * PIECE);
|
|
151
|
-
try {
|
|
152
|
-
for (const index of [0, 1, 2]) {
|
|
153
|
-
clock.at += 100;
|
|
154
|
-
await store.write(index, pieceOf(index));
|
|
155
|
-
}
|
|
156
|
-
// Piece 0 is the oldest AND is being read. The read is not awaited, so the
|
|
157
|
-
// write below decides while it is still outstanding.
|
|
158
|
-
const reading = store.read(0, Buffer.alloc(PIECE));
|
|
159
|
-
clock.at += 100;
|
|
160
|
-
await store.write(3, pieceOf(3));
|
|
161
|
-
const bytes = await reading;
|
|
162
|
-
await store.settled();
|
|
163
|
-
|
|
164
|
-
assert.equal(bytes, PIECE, "the read did not complete");
|
|
165
|
-
assert.equal(store.has(0), true, "a piece being read was thrown away under the reader");
|
|
166
|
-
assert.equal(store.has(1), false, "the next oldest should have gone instead");
|
|
167
|
-
} finally {
|
|
168
|
-
await store.destroy();
|
|
169
|
-
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
test("a piece thrown away is answered as absent, so the swarm is asked for it again", async () => {
|
|
174
|
-
const { store, directory, clock } = await makeStore(PIECE);
|
|
175
|
-
try {
|
|
176
|
-
await store.write(0, pieceOf(0));
|
|
177
|
-
clock.at += 100;
|
|
178
|
-
await store.write(1, pieceOf(1));
|
|
179
|
-
await store.settled();
|
|
180
|
-
|
|
181
|
-
assert.equal(store.has(0), false, "the store still claims a piece it threw away");
|
|
182
|
-
await assert.rejects(
|
|
183
|
-
() => store.read(0, Buffer.alloc(PIECE)),
|
|
184
|
-
/Piece 0 is not on disk/,
|
|
185
|
-
"reading a thrown-away piece must say so rather than answer bytes"
|
|
186
|
-
);
|
|
187
|
-
} finally {
|
|
188
|
-
await store.destroy();
|
|
189
|
-
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
test("a piece wanted again after being thrown away is written, not refused", async () => {
|
|
194
|
-
const { store, directory, clock } = await makeStore(PIECE);
|
|
195
|
-
try {
|
|
196
|
-
await store.write(0, pieceOf(0));
|
|
197
|
-
clock.at += 100;
|
|
198
|
-
await store.write(1, pieceOf(1));
|
|
199
|
-
clock.at += 100;
|
|
200
|
-
// Piece 0 again, while its own removal may still be in flight.
|
|
201
|
-
await store.write(0, pieceOf(0));
|
|
202
|
-
await store.settled();
|
|
203
|
-
|
|
204
|
-
assert.equal(store.has(0), true, "the piece did not come back");
|
|
205
|
-
const target = Buffer.alloc(PIECE);
|
|
206
|
-
await store.read(0, target);
|
|
207
|
-
assert.ok(target.equals(pieceOf(0)), "the piece came back wrong");
|
|
208
|
-
assert.equal(store.bytes, PIECE, "the store is over its allowance");
|
|
209
|
-
} finally {
|
|
210
|
-
await store.destroy();
|
|
211
|
-
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
test("lowering the allowance frees nothing by itself, and binds the next write", async () => {
|
|
216
|
-
const { store, directory, clock } = await makeStore(null);
|
|
217
|
-
try {
|
|
218
|
-
for (const index of [0, 1, 2]) {
|
|
219
|
-
clock.at += 100;
|
|
220
|
-
await store.write(index, pieceOf(index));
|
|
221
|
-
}
|
|
222
|
-
store.reviseAllowance(PIECE);
|
|
223
|
-
assert.equal(store.size, 3, "lowering the allowance threw pieces away on its own");
|
|
224
|
-
|
|
225
|
-
clock.at += 100;
|
|
226
|
-
await store.write(3, pieceOf(3));
|
|
227
|
-
await store.settled();
|
|
228
|
-
assert.equal(store.size, 1, "the next write did not bring it within the allowance");
|
|
229
|
-
assert.deepEqual(await onDisk(store), { files: 1, bytes: PIECE });
|
|
230
|
-
} finally {
|
|
231
|
-
await store.destroy();
|
|
232
|
-
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
test("an allowance smaller than one piece keeps the arriving piece rather than losing it", async () => {
|
|
237
|
-
// A piece the swarm has already paid for is not thrown away because the
|
|
238
|
-
// arithmetic says there is no room for anything: the alternative is fetching
|
|
239
|
-
// it again, which costs ~1430 ms against a write measured in milliseconds.
|
|
240
|
-
const { store, directory } = await makeStore(1);
|
|
241
|
-
try {
|
|
242
|
-
await store.write(0, pieceOf(0));
|
|
243
|
-
await store.settled();
|
|
244
|
-
assert.equal(store.has(0), true, "the arriving piece was refused");
|
|
245
|
-
assert.equal(store.size, 1);
|
|
246
|
-
} finally {
|
|
247
|
-
await store.destroy();
|
|
248
|
-
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
test("destroying it takes the directory with it", async () => {
|
|
253
|
-
const { store, directory } = await makeStore(null);
|
|
254
|
-
await store.write(0, pieceOf(0));
|
|
255
|
-
const where = store.path;
|
|
256
|
-
await store.destroy();
|
|
257
|
-
await assert.rejects(() => fs.stat(where), /ENOENT/, "the store left its directory behind");
|
|
258
|
-
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
test("the spill ceiling is what the disk's owner said, divided between the stores", async () => {
|
|
262
|
-
const { reviseSpillBudgets, SharedPieceStore } = await import("../services/storage/piece-store/shared-piece-store.js");
|
|
263
|
-
const directory = await fs.mkdtemp(path.join(os.tmpdir(), "spill-share-"));
|
|
264
|
-
const stores = [
|
|
265
|
-
new SharedPieceStore(PIECE, { length: PIECE * 8, memoryBytes: PIECE, path: directory, name: "one" }),
|
|
266
|
-
new SharedPieceStore(PIECE, { length: PIECE * 8, memoryBytes: PIECE, path: directory, name: "two" })
|
|
267
|
-
];
|
|
268
|
-
try {
|
|
269
|
-
const revised = reviseSpillBudgets(100 * PIECE, stores);
|
|
270
|
-
assert.deepEqual(
|
|
271
|
-
revised.map((store) => store.allowanceBytes),
|
|
272
|
-
[50 * PIECE, 50 * PIECE],
|
|
273
|
-
"one thread's share is divided equally between its stores"
|
|
274
|
-
);
|
|
275
|
-
|
|
276
|
-
// Nobody has said yet: nothing is thrown away, which is what it always did.
|
|
277
|
-
assert.deepEqual(
|
|
278
|
-
reviseSpillBudgets(null, stores).map((store) => store.allowanceBytes),
|
|
279
|
-
[null, null]
|
|
280
|
-
);
|
|
281
|
-
} finally {
|
|
282
|
-
for (const store of stores) {
|
|
283
|
-
await new Promise((resolve) => store.destroy(resolve));
|
|
284
|
-
}
|
|
285
|
-
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
test("what lies behind every reader goes without waiting for the disk to be short", async () => {
|
|
290
|
-
// THE SECOND RULE. The ceiling is a share of free space, and on a roomy host
|
|
291
|
-
// that is tens of gigabytes against a measured growth of 14 400 MB in one
|
|
292
|
-
// viewing — so the ceiling alone never binds and nothing is removed until the
|
|
293
|
-
// torrent itself goes. A piece behind every read head has been read.
|
|
294
|
-
const { store, directory } = await makeStore(1000 * PIECE);
|
|
295
|
-
try {
|
|
296
|
-
for (const index of [0, 1, 2, 3, 4, 5]) {
|
|
297
|
-
await store.write(index, pieceOf(index));
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
const removed = store.forgetBehind([3, 4]);
|
|
301
|
-
await store.settled();
|
|
302
|
-
|
|
303
|
-
assert.equal(removed, 3, "the three behind the earliest reader should have gone");
|
|
304
|
-
assert.deepEqual([0, 1, 2].map((index) => store.has(index)), [false, false, false]);
|
|
305
|
-
assert.deepEqual([3, 4, 5].map((index) => store.has(index)), [true, true, true]);
|
|
306
|
-
assert.equal(store.stats().behind, 3);
|
|
307
|
-
} finally {
|
|
308
|
-
await store.destroy();
|
|
309
|
-
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
test("with no reader at all, nothing is thrown away", async () => {
|
|
314
|
-
// A store between reads is not a store nobody wants. What empties it whole is
|
|
315
|
-
// the torrent going idle, which removes the store and its directory.
|
|
316
|
-
const { store, directory } = await makeStore(1000 * PIECE);
|
|
317
|
-
try {
|
|
318
|
-
for (const index of [0, 1, 2]) {
|
|
319
|
-
await store.write(index, pieceOf(index));
|
|
320
|
-
}
|
|
321
|
-
assert.equal(store.forgetBehind([]), 0);
|
|
322
|
-
assert.equal(store.size, 3);
|
|
323
|
-
} finally {
|
|
324
|
-
await store.destroy();
|
|
325
|
-
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
test("a piece being read is not taken even when it is behind everybody", async () => {
|
|
330
|
-
const { store, directory } = await makeStore(1000 * PIECE);
|
|
331
|
-
try {
|
|
332
|
-
await store.write(0, pieceOf(0));
|
|
333
|
-
await store.write(5, pieceOf(5));
|
|
334
|
-
const reading = store.read(0, Buffer.alloc(PIECE));
|
|
335
|
-
const removed = store.forgetBehind([5]);
|
|
336
|
-
await reading;
|
|
337
|
-
await store.settled();
|
|
338
|
-
|
|
339
|
-
assert.equal(removed, 0, "a piece under a reader was thrown away");
|
|
340
|
-
assert.equal(store.has(0), true);
|
|
341
|
-
} finally {
|
|
342
|
-
await store.destroy();
|
|
343
|
-
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
test("when there is no room, what is behind the readers goes before what is ahead", async () => {
|
|
348
|
-
const directory = await fs.mkdtemp(path.join(os.tmpdir(), "piece-disk-heads-"));
|
|
349
|
-
const clock = { at: 1000 };
|
|
350
|
-
// The reader stands on #5. #4 is behind it and was touched LAST, so under the
|
|
351
|
-
// old rule — least recently used — it would have been the safest piece there.
|
|
352
|
-
const store = new PieceDiskStore({
|
|
353
|
-
directory,
|
|
354
|
-
name: "pieces",
|
|
355
|
-
chunkLength: PIECE,
|
|
356
|
-
allowanceBytes: 3 * PIECE,
|
|
357
|
-
now: () => clock.at,
|
|
358
|
-
readHeads: () => [5]
|
|
359
|
-
});
|
|
360
|
-
try {
|
|
361
|
-
for (const index of [8, 7, 4]) {
|
|
362
|
-
clock.at += 100;
|
|
363
|
-
await store.write(index, pieceOf(index));
|
|
364
|
-
}
|
|
365
|
-
clock.at += 100;
|
|
366
|
-
await store.write(9, pieceOf(9));
|
|
367
|
-
await store.settled();
|
|
368
|
-
|
|
369
|
-
assert.equal(store.has(4), false, "the piece behind the reader was kept because it was touched last");
|
|
370
|
-
assert.deepEqual([7, 8, 9].map((index) => store.has(index)), [true, true, true]);
|
|
371
|
-
} finally {
|
|
372
|
-
await store.destroy();
|
|
373
|
-
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
test("a store takes up the pieces a previous life left in its directory", async () => {
|
|
378
|
-
const root = await fs.mkdtemp(path.join(os.tmpdir(), "adopt-"));
|
|
379
|
-
try {
|
|
380
|
-
const first = new PieceDiskStore({ directory: root, name: "film.pieces", chunkLength: 1024 });
|
|
381
|
-
await first.write(7, Buffer.alloc(1024, 7));
|
|
382
|
-
await first.write(9, Buffer.alloc(1024, 9));
|
|
383
|
-
await first.close();
|
|
384
|
-
|
|
385
|
-
// A torrent torn down and added again gets a NEW store over the same
|
|
386
|
-
// directory. Before 2026-09-11 its index started empty, so every piece it
|
|
387
|
-
// in fact had read as missing and the film was downloaded a second time
|
|
388
|
-
// while the first copy sat beside it.
|
|
389
|
-
const second = new PieceDiskStore({ directory: root, name: "film.pieces", chunkLength: 1024 });
|
|
390
|
-
assert.equal(second.size, 2, "the pieces already on disk were not taken up");
|
|
391
|
-
assert.equal(second.bytes, 2048, "nor were their bytes counted");
|
|
392
|
-
assert.ok(second.has(7) && second.has(9));
|
|
393
|
-
|
|
394
|
-
const target = Buffer.alloc(1024);
|
|
395
|
-
await second.read(7, target);
|
|
396
|
-
assert.ok(target.equals(Buffer.alloc(1024, 7)), "and they read back as themselves");
|
|
397
|
-
await second.destroy();
|
|
398
|
-
} finally {
|
|
399
|
-
await fs.rm(root, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
400
|
-
}
|
|
401
|
-
});
|