nx_research_reach_probe_test.nx source
↩ module page · 44 lines · 2290 B
1// nx_research_reach_probe_test.nx -- probe whether real game-engine research
2// sources are reachable via the upgraded sovereign fetcher (F-1 redirect + F-2
3// follow), and whether they arrive as readable HTML or forced-gzip (needs F-3).
4// expect_exit: 0 license_tier: ORIGINAL
5
6import "nx_syscalls.nx"
7import "nx_x509_trust_store.nx"
8import "nx_trust_store_load_from_certdata.nx"
9import "nx_https_fetch_follow.nx"
10
11func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
12func wn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
13func contains(hay: *u8, hn: i64, ndl: *u8, nn: i64) -> i64 {
14 var i: i64 = 0
15 while i + nn <= hn { var j: i64=0; while j<nn { if hay[i+j]!=ndl[j]{break} j=j+1 } if j==nn{return 1} i=i+1 }
16 return 0
17}
18
19func probe(url: *u8, store: *TrustStore, out: *u8) -> i64 {
20 let st: *i64 = (sys_mmap(8)) as *i64
21 let n: i64 = nx_https_fetch_follow(url, store, out, 8388608, 6, st)
22 w(url); w(" status=" as *u8); wn(st[0]); w(" bytes=" as *u8); wn(n)
23 if n < 0 { w(" ERR\n" as *u8); return 0 }
24 var gz: i64 = 0
25 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } }
26 if gz == 1 { w(" [GZIP -> needs F-3]\n" as *u8); return 0 }
27 if contains(out, n, "<" as *u8, 1) == 1 { w(" [HTML readable]\n" as *u8); return 1 }
28 w(" [non-html]\n" as *u8)
29 return 0
30}
31
32func main() -> i64 {
33 let r: i64 = nx_trust_store_load_from_certdata("/tmp/mozilla_certdata.txt" as *u8, 300, 4194304)
34 if r <= 0 { w("STORE-FAIL\n" as *u8); return 1 }
35 let store: *TrustStore = r as *TrustStore
36 let out: *u8 = sys_mmap(8388608)
37 var ok: i64 = 0
38 ok = ok + probe("https://en.wikipedia.org/wiki/Game_engine" as *u8, store, out)
39 ok = ok + probe("https://en.wikipedia.org/wiki/Real-time_strategy" as *u8, store, out)
40 ok = ok + probe("https://www.w3.org/TR/webgpu/" as *u8, store, out)
41 ok = ok + probe("https://gpuweb.github.io/gpuweb/" as *u8, store, out)
42 w("READABLE SOURCES: " as *u8); wn(ok); w(" / 4\n" as *u8)
43 return 0
44}