code wiki / (root) / nx_dist_verify.nx

nx_dist_verify.nx source

↩ module page · 37 lines · 2619 B

1// nx_dist_verify.nx -- verify the PUBLIC /dist download route end to end: sovereign TLS-1.3 GET of 2// https://nishifamily.com/dist/<cid>/<name> -> should return the real file the hub published (proving sites.elf 3// routes /dist -> the loopback download server). Prints HTTP status + byte count + the first bytes. expect_exit: 0 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_1048576: i64 = 1048576 11 12func v_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 13func v_putn(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} let d:*u8=sys_mmap(24); var k:i64=0; while m>0{d[k]=(48+(m%10)) as u8;m=m/10;k=k+1} 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} return 0 } 14 15func main() -> i64 { 16 v_puts("=== nx_dist_verify: public GET https://nishifamily.com/dist/<cid>/... ===\n" as *u8) 17 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 18 if r<=0 { v_puts("certdata load FAILED\n" as *u8); sys_exit(1); return 1 } 19 let store: *TrustStore = r as *TrustStore 20 let cap: i64 = K_MAGIC_1048576 21 let out: *u8 = sys_mmap(cap) 22 let status: *i64 = sys_mmap(8) as *i64 23 let url: *u8 = "https://nishifamily.com/dist/509b6d9d22987cf7b1067a7cc6b74b88cf0c8c2739748fe5e85a4da0f69ebf1a/Apertus-8B-Instruct-2509-model.safetensors.index.json" as *u8 24 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status) 25 v_puts(" HTTP status=" as *u8); v_putn(status[0]); v_puts(" bytes=" as *u8); v_putn(n); v_puts("\n" as *u8) 26 if n>0 { 27 v_puts(" --- first bytes ---\n" as *u8) 28 var show: i64 = n; if show>360 { show=360 } 29 sys_write(1, out, show); v_puts("\n" as *u8) 30 // is it the model index (contains the weight_map marker)? 31 var has: i64=0; var i: i64=0 32 while i+11<=n { var ok: i64=1; var j: i64=0; let pat: *u8="weight_map" as *u8; while j<10 { if out[i+j]!=pat[j] { ok=0 } j=j+1 } if ok==1 { has=1; i=n } else { i=i+1 } } 33 if status[0]==200 { if has==1 { v_puts("\n=== GREEN: public /dist route serves the real published file ===\n" as *u8); sys_exit(0); return 0 } } 34 v_puts("\n=== got a response but not the expected file (route not landed / wrong backend) ===\n" as *u8) 35 } else { v_puts(" no body (route not live / unreachable)\n" as *u8) } 36 sys_exit(1); return 1 37}