code wiki / _hdl_build / nx_torrent_caps_register.nx
nx_torrent_caps_register.nx source
↩ module page · 54 lines · 5660 B
1// nx_torrent_caps_register.nx -- registers the two new sovereign-torrent capabilities
2// (streaming/endgame piece picker + tit-for-tat/optimistic choker) via the Librarian's
3// alloc + dual-write, gated by the RACI ingest path. Engineer evidence = BOTH KAT gates
4// exit 0 (built sovereignly nx_cc->nxasm, no gcc; forked here from /tmp/*.sov.elf, RAW
5// status judged -- never $?). author != admitter; additive-only (two new modules, zero
6// deletions); documented (plan doc + memory updated). license_tier: ORIGINAL
7import "nx_cap_register.nx"
8import "nx_capreg_librarian.nx"
9import "nx_syscalls.nx"
10
11// fork+exec a prebuilt sovereign ELF, mute its stdio, return RAW wait status (0 = clean exit 0).
12func tcr_run(path: *u8) -> i64 {
13 let pid: i64 = sys_fork()
14 if pid == 0 {
15 let dn: i64 = sys_openat_wr("/dev/null" as *u8, 0x1a4)
16 if dn >= 0 { sys_dup3(dn, 1, 0); sys_dup3(dn, 2, 0) }
17 let argv: *i64 = sys_mmap(32) as *i64; argv[0] = path as i64; argv[1] = 0
18 let envp: *i64 = sys_mmap(16) as *i64; envp[0] = 0
19 sys_execve(path, argv, envp); sys_exit(127)
20 }
21 let st: *i64 = sys_mmap(16) as *i64
22 sys_wait4(pid, st, 0)
23 return st[0]
24}
25
26func main() -> i64 {
27 var allok: i64 = 1
28 if tcr_run("/tmp/nx_stream_picker_test.sov.elf" as *u8) != 0 { allok = 0 }
29 if tcr_run("/tmp/nx_choker_test.sov.elf" as *u8) != 0 { allok = 0 }
30 cr_w(1, "ENGINEER: stream_picker(24 KAT) + choker(30 KAT) both gates exit-0 = " as *u8); cr_wn(1, allok); cr_w(1, "\n" as *u8)
31
32 let eng: i64 = ig_engineer(1, 1, 1, allok)
33 let dec: i64 = ig_decision(eng, ig_council(eng, 1, 1, 2), 1)
34 if dec != IG_INGEST { cr_w(1, "HELD\n" as *u8); sys_exit(1) }
35 if cr_can_register(5, 2, 6, dec) != 1 { cr_w(1, "REFUSED\n" as *u8); sys_exit(1) }
36
37 let lp: *u8 = "/tmp/nishi_cap_registry.log" as *u8
38 let jp: *u8 = "knowledge/status/cap_registry_durable.log" as *u8
39
40 let idx1: i64 = cl_next_idx(lp, jp)
41 let ok1: i64 = cl_register_dual(lp, jp, idx1, 5, 2,
42 "GEN TORRENT STREAM-PICKER (arc=TORRENT; the modern 'watch/play WHILE you download' capability + the long-tail-killing endgame, built deterministic so the determinism exceed thesis covers selection too). nx_stream_picker.nx composes on nx_piece_manager's rarest-first (DRY, one canonical tie-break) and adds: sequential in-order pick; nx_sp_stream_pick = deadline-window-first (earliest unmet+available piece in [playhead, playhead+window) feeds the player) then rarest-first OUTSIDE the window so swarm-health is never sacrificed for streaming (BUILD intelligence, don't strip); nx_sp_is_urgent panic-window override; nx_sp_contiguous_have / nx_sp_can_play playback-starvation gate; endgame = nx_sp_in_endgame(outstanding<=thr) + nx_sp_blocks_outstanding + nx_sp_pick_block that in endgame re-races already-REQUESTED blocks across peers (cancel losers) to kill the one-slow-peer last-block stall = the dominant completion-time variance; nx_sp_pipeline_depth = BDP-derived outstanding-request count (ceil(bw*rtt/1000/block) clamped [2,256]) = the throughput lever, no magic number (caller passes measured bw/rtt). All pure integer, NO wall-clock/RNG -> bit-for-bit replayable selection. GATE nx_stream_picker_test 24/24 sovereign GREEN (nx_cc->nxasm, no gcc; run-exit=0): sequential, window-first+fallback, window-clamp, urgency 3 cases, contiguous/can-play, endgame boundary, block outstanding/pick normal+endgame-re-race, pipeline 4 cases incl MIN/MAX clamp + degenerate block. Composes nx_piece_manager. NEXT: wire into a session loop (real swarm), MSE/PE, BEP-10/9 magnet" as *u8)
43 if ok1 != 1 { cr_w(1, "DUAL-WRITE 1 FAILED\n" as *u8); sys_exit(1) }
44 cr_w(1, "CAPREG idx=" as *u8); cr_wn(1, idx1); cr_w(1, " REGISTERED -- torrent stream picker\n" as *u8)
45
46 let idx2: i64 = cl_next_idx(lp, jp)
47 let ok2: i64 = cl_register_dual(lp, jp, idx2, 5, 2,
48 "GEN TORRENT CHOKER (arc=TORRENT; 'better download rates' earned the protocol's way -- reciprocity -- and made DETERMINISTIC where mainline is not). nx_choker.nx: nx_ch_select_top_k = tit-for-tat, give the k upload slots to the k highest-rate INTERESTED peers (reward who feeds US so they keep US unchoked), highest-rate wins / lowest-index tie-break, not-interested never unchoked, k>eligible fills what it can, O(k*n) no sort/RNG; nx_ch_optimistic_slot = the rotating extra slot that discovers fast peers + bootstraps newcomers, but ROUND-ROBIN by a deterministic round counter ((round/period)%eligible over interested-but-choked) instead of mainline's RANDOM pick -> same discovery, fully replayable choke schedule (no client in the field can replay its own choke decisions); nx_ch_compute = full per-round decision (top-k + one optimistic) writing the 1/0 unchoke set; nx_ch_should_rotate scheduling helper. Defaults NX_CH_DEFAULT_SLOTS=4 / NX_CH_OPT_PERIOD=3 are documented config (caller overrides k/period -- law 11). Pure selection over caller arrays, no syscalls on the decision path, no wall-clock. GATE nx_choker_test 30/30 sovereign GREEN (nx_cc->nxasm, no gcc; run-exit=0): top-k correctness, rate ties->low index, interested filter, k>eligible, optimistic round-robin across 5 rounds incl wrap + same-interval, no-eligible->-1, full compute top2+optimistic, all-in-topk->no-optimistic, should_rotate incl period<=0. Composes nx_piece_manager/nx_stream_picker. NEXT: rate EMA from real byte counters, seed-mode (upload-rate) choker, anti-snubbing" as *u8)
49 if ok2 != 1 { cr_w(1, "DUAL-WRITE 2 FAILED\n" as *u8); sys_exit(1) }
50 cr_w(1, "CAPREG idx=" as *u8); cr_wn(1, idx2); cr_w(1, " REGISTERED -- torrent choker\n" as *u8)
51
52 sys_exit(0)
53 return 0
54}