code wiki / (root) / nx_torrent_health.nx

nx_torrent_health.nx

buildroot/runtime/nx_torrent_health.nx

17866 B308 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic torrent
docsdependenciesstructsconstsfunctions

about

nx_torrent_health.nx -- S-CLASS FUNCTIONAL HEALTH MONITOR for /torrent (the "s-class exceed" functionality monitor). Where nx_torrent_live_probe only proves the PAGE loads, and nx_torrent_doctor only reads LOCAL download status, THIS exercises the REAL magnet pipeline end-to-end against a known-good canary (Big Buck Bunny, DHT-only -- the operator's trackerless use case) and reports a per-stage GREEN/RED LADDER that LOCALIZES any break: [1] PARSE mg_parse decodes the magnet info_hash (pure) [2] BUNDLE every spawn-sibling worker elf is present in self-dir -- catches a tmpfs-wiped bundle after a NAS reboot OR an incomplete deploy ("magnets AND other stuff dead") [3] DISCOVERY the real nx_torrent_get worker finds peers>0 (catches NAS egress / DHT block) [4] METADATA BEP-9 ut_metadata resolves the torrent size>0 [5] PIECE >=1 sha1-verified piece downloads (catches "peers connected but no data served") It RUNS THE REAL WORKER (DRY -- it tests the exact binary users use, never a reimplementation), polls download.status, then kills the worker's whole process GROUP + cleans the scratch dir. `--selftest` is a DETERMINISTIC logic gate (synthetic status fixtures + neg-controls), so the grader/localizer/parser are proven GREEN with no network; the live canary is the functional proof. usage: nx_torrent_health [--selftest | <magnet>] (default live canary = Big Buck Bunny) license_tier: ORIGINAL module: nishi-core.torrent.health depends: nishi-core.torrent.magnet, nishi-core.sys.syscalls

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_magnet.nx nx_torrent_health.nx

imports: nx_syscalls.nxnx_magnet.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main hs_streq hs_selftest hs_w sys_write hs_grade hs_first_fail sys_mkdir hs_join sys_mmap hs_cat sys_openat_wr sys_write ↻ hs_len sys_close sys_mmap ↻ hs_read sys_openat_rd sys_read sys_close ↻ hs_status_int hs_len ↻ hs_file_exists sys_openat_rd ↻ sys_close ↻ mg_parse mg_len mg_starts mg_len ↻ mg_keyeq mg_len ↻ mg_decode_btih mg_hexval mg_b32val sys_mmap ↻ mg_urldecode mg_hexval ↻ hs_unlink hs_rmdir sys_exit

structs

none

consts

23const HS_MAGIC_1024: i64 = 1024
24const HS_MAGIC_8192: i64 = 8192
25const HS_MAGIC_2000: i64 = 2000
26const HS_MAGIC_8191: i64 = 8191
27const HS_MAGIC_276561920: i64 = 276561920
28const HS_MAGIC_1055: i64 = 1055
30const HS_BBB: *u8 = "magnet:?xt=urn:btih:dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&dn=Big+Buck+Bunny" as *u8
31const HS_SCRATCH: *u8 = "/tmp/_nx_thealth" as *u8
32const HS_MAXPOLL: i64 = 24 // 24 * 2s = 48s ceiling for the live canary

functions

35func hs_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
36func hs_wn(v: i64) -> i64
called by 2: hs_bundlehs_live calls 2: sys_mmapsys_write
41func hs_whexb(b: *u8, len: i64) -> i64
called by 1: hs_live calls 2: sys_mmapsys_write
46func hs_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
47func hs_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){dst[off+i]=s[i];i=i+1} return off+i }
called by 1: hs_join
48func hs_streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8){ if a[i]!=b[i]{return 0} i=i+1 } if b[i]!=(0 as u8){return 0} return 1 }
called by 1: main
49func hs_starts(s: *u8, pre: *u8) -> i64 { var i: i64=0; while pre[i]!=(0 as u8){ if s[i]!=pre[i]{return 0} i=i+1 } return 1 }
called by 1: main
51func hs_join(dir: *u8, name: *u8) -> *u8 { let p: *u8 = sys_mmap(HS_MAGIC_1024); var o: i64 = hs_cat(p,0,dir); p[o]=47 as u8; o=o+1; o = hs_cat(p,o,name); p[o]=0 as u8; return p }
54func hs_file_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd>=0 { sys_close(fd); return 1 } return 0 }
56func hs_rmdir(path: *u8) -> i64 { return __syscall(263, AT_FDCWD, path as i64, 0x200, 0, 0, 0) } // unlinkat(...,AT_REMOVEDIR)
58func hs_read(path: *u8, buf: *u8, cap: i64) -> i64
68func hs_self_dir() -> *u8
84func hs_status_int(buf: *u8, n: i64, key: *u8) -> i64
called by 2: hs_canaryhs_selftest calls 1: hs_len
103func hs_grade(v: i64) -> i64 { if v>0 { return 1 } return 0 } // a stage is GREEN iff its counter > 0
called by 2: hs_livehs_selftest
105func hs_first_fail(parse: i64, bundle: i64, disc: i64, meta: i64, piece: i64) -> i64
called by 2: hs_livehs_selftest
113func hs_stage_name(s: i64) -> i64
called by 1: hs_live calls 1: hs_w
125func hs_bundle(selfdir: *u8) -> i64
159func hs_canary(selfdir: *u8, magnet: *u8, out: *i64) -> i64
199func hs_cleanup() -> i64
219func hs_live(magnet: *u8) -> i64
260func hs_selftest() -> i64
301func main(argc: i64, argv: *i64) -> i64