code wiki / _hdl_build / nx_research_resilience_test.nx
nx_research_resilience_test.nx source
↩ module page · 80 lines · 5600 B
1// nx_research_resilience_test.nx -- prove the team is BOT-BLOCK-PROOF. The Researcher:
2// 1. FETCHES a live page over its own socket stack (nx_browse_text)
3// 2. EXTRACTS the cited facts (nx_research_extract)
4// 3. MIRRORS (downloads) the source INTO the Nishi Library (nx_library_cache -> disk)
5// 4. then the site is BLOCKED (we hit a dead port -> connection refused)
6// 5. and the team FALLS BACK to the library, parsing the LOCAL mirror to the SAME facts -- no network
7// 6. and FLAGS a still-missing citeable source to pull into the library next
8// If a live fetch and a library read yield identical facts while the external is unreachable, then bot
9// blocking cannot starve us. Exit 0 on 8/8. license_tier: ORIGINAL
10
11import "nx_browse_text.nx"
12import "nx_research_extract.nx"
13import "nx_library_cache.nx"
14import "nx_syscalls.nx"
15
16func rt_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
17func rt_num(v: i64) -> i64 { let bb: *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;k=1}; while m>0 {t[k]=48+(m%10); m=m/10; k=k+1}; 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// the cited facts must match whether parsed from the live web OR the local library mirror.
20func facts_ok(text: *u8, n: i64) -> i64 {
21 var ok: i64 = 1
22 if re_stat_after(text, n, "found that") != 53 { ok = 0 }
23 if re_stat_after(text, n, "longer than") != 3 { ok = 0 }
24 if re_stat_after(text, n, "within") != 10 { ok = 0 }
25 if re_has(text, n, "debunked") != 1 { ok = 0 }
26 return ok
27}
28
29func main() -> i64 {
30 rt_puts("=== RESEARCHER: fetch -> mirror into the Nishi Library -> survive a bot-block ===\n" as *u8)
31 let path: *u8 = "knowledge/library/ux-abandonment.txt" as *u8
32
33 // 1) FETCH the live page over the team's own socket stack
34 let addr: *u8 = sys_mmap(32); br_addr_ipv4(addr, 127, 0, 0, 1, 8099)
35 let scratch: *u8 = sys_mmap(16384); let out: *u8 = sys_mmap(16384)
36 let status: *i64 = sys_mmap(8) as *i64; let verdict: *i64 = sys_mmap(8) as *i64
37 let n: i64 = nx_browse_text(addr, "/" as *u8, 1, "127.0.0.1" as *u8, 9, scratch, 16384, out, 16384, status, verdict)
38 let live_ok: i64 = facts_ok(out, n)
39 rt_puts(" 1. FETCH live : status=" as *u8); rt_num(status[0]); rt_puts(" bytes=" as *u8); rt_num(n); rt_puts(" facts-ok=" as *u8); rt_num(live_ok); rt_puts("\n" as *u8)
40
41 // 2) MIRROR (download) the source into the Nishi Library
42 let w: i64 = lc_mirror(path, out, n)
43 let have: i64 = lc_have_local(path)
44 rt_puts(" 2. MIRROR lib : wrote=" as *u8); rt_num(w); rt_puts(" bytes have_local=" as *u8); rt_num(have); rt_puts(" (knowledge/library/ux-abandonment.txt)\n" as *u8)
45
46 // 3) BOT-BLOCK: the site is now unreachable (dead port 8098 -> connection refused)
47 let addr2: *u8 = sys_mmap(32); br_addr_ipv4(addr2, 127, 0, 0, 1, 8098)
48 let sc2: *u8 = sys_mmap(4096); let o2: *u8 = sys_mmap(4096)
49 let st2: *i64 = sys_mmap(8) as *i64; let vd2: *i64 = sys_mmap(8) as *i64
50 let blk: i64 = nx_browse_text(addr2, "/" as *u8, 1, "127.0.0.1" as *u8, 9, sc2, 4096, o2, 4096, st2, vd2)
51 var reachable: i64 = 0; if blk > 0 { reachable = 1 }
52 let route: i64 = lc_route(have, reachable)
53 rt_puts(" 3. BOT-BLOCK : live-fetch=" as *u8); rt_num(blk); rt_puts(" (reachable=" as *u8); rt_num(reachable); rt_puts(") route=" as *u8); rt_num(route); rt_puts(" (1=LOCAL library)\n" as *u8)
54
55 // 4) FALL BACK to the library -- parse the LOCAL mirror, no network
56 let lib: *u8 = sys_mmap(16384)
57 let ln: i64 = lc_read_mirror(path, lib, 16384)
58 let lib_ok: i64 = facts_ok(lib, ln)
59 rt_puts(" 4. LOCAL parse : read=" as *u8); rt_num(ln); rt_puts(" bytes from library facts-ok=" as *u8); rt_num(lib_ok); rt_puts(" (SAME answer, zero network)\n" as *u8)
60
61 // 5) FLAG a still-missing citeable source + score our resilience
62 let flag: i64 = lc_should_mirror(0, 1) // citeable, not yet mirrored -> pull it in
63 let res: i64 = lc_resilience_permil(2, 1) // 2 depended-on sources, 1 mirrored so far
64 rt_puts(" 5. FLAG+score : flag-to-download=" as *u8); rt_num(flag); rt_puts(" resilience=" as *u8); rt_num(res); rt_puts("/1000 mirrored\n" as *u8)
65
66 let r: *i64 = sys_mmap(8*8) as *i64
67 r[0] = 0; if status[0] == 200 { r[0] = 1 } // fetched a real 200 over a socket
68 r[1] = 0; if live_ok == 1 { r[1] = 1 } // extracted the live facts
69 r[2] = 0; if w == n { if have == 1 { r[2] = 1 } } // mirrored fully into the library
70 r[3] = 0; if reachable == 0 { if route == LC_LOCAL { r[3] = 1 } }// external blocked -> routed LOCAL
71 r[4] = 0; if ln == n { r[4] = 1 } // mirror read back byte-for-byte
72 r[5] = 0; if lib_ok == 1 { r[5] = 1 } // LOCAL parse == LIVE parse
73 r[6] = 0; if flag == 1 { r[6] = 1 } // flagged the missing source
74 r[7] = 0; if res == 500 { r[7] = 1 } // resilience accounted
75 var pass: i64 = 0; var i: i64 = 0
76 while i < 8 { pass = pass + r[i]; i = i + 1 }
77 rt_puts("----\n passed " as *u8); rt_num(pass); rt_puts("/8\n" as *u8)
78 if pass == 8 { rt_puts(" BOT-BLOCK-PROOF: the site went dark, the Nishi Library answered with the identical cited facts. The more we mirror, the less the open web can starve us.\n" as *u8); sys_exit(0); return 0 }
79 rt_puts(" FAIL\n" as *u8); sys_exit(1); return 1
80}