code wiki / (root) / nx_fin_md_probe.nx

nx_fin_md_probe.nx source

↩ module page · 39 lines · 2079 B

1// nx_fin_md_probe.nx -- ground-truth probe: is the finance dashboard actually LIVE on the public edge? 2// Hits nishifamily.com/finance (the question) + nishifamily.com/api/tools (control, known-live). A status 3// code = reached; 404/302 = route not there / redirect. Throwaway diagnostic over the sovereign fetcher. 4// license_tier: ORIGINAL 5import "nx_syscalls.nx" 6import "nx_x509_trust_store.nx" 7import "nx_trust_store_load_from_certdata.nx" 8import "nx_https_fetch_follow.nx" 9const K_MAGIC_4194304: i64 = 4194304 10const K_MAGIC_8388608: i64 = 8388608 11 12func pp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 13func pn(v: i64) -> i64 { 14 if v==0 { sys_write(1,"0" as *u8,1); return 0 } 15 var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m } 16 let d: *u8=sys_mmap(24); var k: i64=0 17 while m>0 { d[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } 18 var i: i64=k-1; while i>=0 { let o: *u8=sys_mmap(1); o[0]=d[i]; sys_write(1,o,1); i=i-1 } 19 return 0 20} 21func probe(label: *u8, url: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 { 22 let status: *i64=sys_mmap(8) as *i64 23 let n: i64=nx_https_fetch_follow(url, store, out, cap, 6, status) 24 pp("\n== " as *u8); pp(label); pp(" ==\n status=" as *u8); pn(status[0]); pp(" bytes=" as *u8); pn(n) 25 if n<=0 { pp(" FETCH-FAIL (neg=TLS/conn err)\n" as *u8); return 0 } 26 var m: i64=n; if m>200 { m=200 } 27 pp("\n --- first bytes ---\n" as *u8); sys_write(1, out, m); pp("\n --- end ---\n" as *u8) 28 return 1 29} 30func main() -> i64 { 31 let r: i64=nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 32 if r<=0 { pp("certdata load failed\n" as *u8); return 1 } 33 let store: *TrustStore=r as *TrustStore 34 let cap: i64=K_MAGIC_8388608 35 let out: *u8=sys_mmap(cap) 36 probe("nishifamily.com/finance (is it LIVE?)" as *u8, "https://nishifamily.com/finance" as *u8, store, out, cap) 37 probe("nishifamily.com/api/tools (control = known live)" as *u8, "https://nishifamily.com/api/tools" as *u8, store, out, cap) 38 return 0 39}