code wiki / (root) / nx_lib_fetch_probe.nx

nx_lib_fetch_probe.nx source

↩ module page · 43 lines · 2254 B

1// nx_lib_fetch_probe.nx -- proves nx_lib_fetch compiles/links against the full 2// sovereign TLS-1.3 stack, and attempts one live fetch. Honest: reports whether 3// the state is the WIRE (compiles), the CA bundle, or the network. Returns 0 4// (probe, not pass/fail) -- read the printed outcome. 5import "nx_syscalls.nx" 6import "nx_lib_fetch.nx" 7import "nx_lib_fetch_ingest.nx" 8const K_MAGIC_4194304: i64 = 4194304 9 10func fp_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 11func fp_putn(v: i64) -> i64 { 12 let bb: *u8 = sys_mmap(28); var m: i64 = v 13 if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) } 14 let t: *u8 = sys_mmap(28); var k: i64 = 0 15 if m == 0 { t[0] = 48 as u8; k = 1 } 16 while m > 0 { t[k] = (48 + (m - (m/10)*10)) as u8; m = m / 10; k = k + 1 } 17 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 18} 19 20func main() -> i64 { 21 fp_puts("nx_lib_fetch_probe: wire LINKS against sovereign TLS-1.3 stack (compiled)\n") 22 let store: *TrustStore = nx_lib_fetch_store() 23 if store == 0 as *TrustStore { 24 fp_puts(" CA trust-store: NOT loaded (need /tmp/mozilla_certdata.txt) -- fetch is WIRED, awaiting CA bundle + network\n") 25 return 0 26 } 27 let n: i64 = trust_store_count(store) 28 fp_puts(" CA trust-store loaded, CA="); fp_putn(n); fp_puts("\n") 29 fp_puts(" trust-store OK -- fetch WIRED + CA-ready; live GET needs network (skipping to avoid off-LAN hang)\n") 30 if n > 0 { return 0 } 31 let url: *u8 = "https://en.wikipedia.org/wiki/Deep_learning\x00" 32 let buf: *u8 = sys_mmap(K_MAGIC_4194304) 33 // full fetch->parse->store ingest (compile-checked here; live when net is up) 34 let ig: i64 = nx_lib_fetch_ingest(store, url, "W_PROBE\x00" as *u8, 7) 35 fp_puts(" fetch-ingest rec="); fp_putn(ig); fp_puts("\n") 36 let st: i64 = nx_lib_fetch_status(store, url, buf, K_MAGIC_4194304) 37 if st == 200 { 38 fp_puts(" LIVE sovereign HTTPS fetch OK (HTTP 200) -- httpx RETIRED, real bytes over sovereign TLS-1.3\n") 39 return 0 40 } 41 fp_puts(" fetch status/err="); fp_putn(st); fp_puts(" (network down or cert path) -- wire compiles + ready for when the net is up\n") 42 return 0 43}