nx_torrent_health.nx
buildroot/runtime/nx_torrent_health.nx
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
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
structs
| none |
consts
| 23 | const HS_MAGIC_1024: i64 = 1024 |
| 24 | const HS_MAGIC_8192: i64 = 8192 |
| 25 | const HS_MAGIC_2000: i64 = 2000 |
| 26 | const HS_MAGIC_8191: i64 = 8191 |
| 27 | const HS_MAGIC_276561920: i64 = 276561920 |
| 28 | const HS_MAGIC_1055: i64 = 1055 |
| 30 | const HS_BBB: *u8 = "magnet:?xt=urn:btih:dd8255ecdc7ca55fb0bbf81323d87062db1f6d1c&dn=Big+Buck+Bunny" as *u8 |
| 31 | const HS_SCRATCH: *u8 = "/tmp/_nx_thealth" as *u8 |
| 32 | const HS_MAXPOLL: i64 = 24 // 24 * 2s = 48s ceiling for the live canary |
functions
| 35 | func 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 } |
| 36 | func hs_wn(v: i64) -> i64 |
| 41 | func hs_whexb(b: *u8, len: i64) -> i64 |
| 46 | func hs_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 47 | func 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 |
| 48 | func 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 |
| 49 | func 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 |
| 51 | func 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 } |
| 54 | func hs_file_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd>=0 { sys_close(fd); return 1 } return 0 } |
| 55 | func hs_unlink(path: *u8) -> i64 { return __syscall(263, AT_FDCWD, path as i64, 0, 0, 0, 0) } // unlinkat(AT_FDCWD,path,0) |
| 56 | func hs_rmdir(path: *u8) -> i64 { return __syscall(263, AT_FDCWD, path as i64, 0x200, 0, 0, 0) } // unlinkat(...,AT_REMOVEDIR) |
| 58 | func hs_read(path: *u8, buf: *u8, cap: i64) -> i64 |
| 68 | func hs_self_dir() -> *u8 |
| 84 | func hs_status_int(buf: *u8, n: i64, key: *u8) -> i64 |
| 103 | func hs_grade(v: i64) -> i64 { if v>0 { return 1 } return 0 } // a stage is GREEN iff its counter > 0 |
| 105 | func hs_first_fail(parse: i64, bundle: i64, disc: i64, meta: i64, piece: i64) -> i64 |
| 113 | func hs_stage_name(s: i64) -> i64 |
| 125 | func hs_bundle(selfdir: *u8) -> i64 |
| 159 | func hs_canary(selfdir: *u8, magnet: *u8, out: *i64) -> i64 |
| 199 | func hs_cleanup() -> i64 |
| 219 | func hs_live(magnet: *u8) -> i64 |
| 260 | func hs_selftest() -> i64 |
| 301 | func main(argc: i64, argv: *i64) -> i64 |