nx_infra_sota_fetch.nx source
↩ module page · 69 lines · 4582 B
1// nx_infra_sota_fetch.nx -- DEEP SOTA for the INFRASTRUCTURE domains (operator 2026-07-04: measure our HOSTING,
2// ROUTING, NETWORK vs the real bar). Real sources, not wikipedia: the RFCs that DEFINE SOTA hosting/transport/
3// routing/naming + reference-server READMEs. Same sovereign stack as nx_voicegen_sota_fetch: own TLS-1.3,
4// Mozilla CA, idempotent have-skip. Saves knowledge/fetched/infra_*.raw. expect_exit: 0 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 if_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 if_putn(v: i64) -> i64 {
14 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
15 var m: i64 = v
16 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
17 let d: *u8 = sys_mmap(24); var k: i64 = 0
18 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
19 var j: i64 = k - 1
20 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 }
21 return 0
22}
23func have_file(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
24func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 {
25 if have_file(opath) == 1 { if_puts(opath); if_puts(" [have-skip]\n"); return 1 }
26 let status: *i64 = sys_mmap(8) as *i64
27 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status)
28 if_puts(url); if_puts(" status="); if_putn(status[0]); if_puts(" bytes="); if_putn(n)
29 if n <= 0 { if_puts(" FETCH-FAIL\n"); return 0 }
30 var gz: i64 = 0
31 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } }
32 if gz == 1 { if_puts(" [GZIP-skip]\n"); return 0 }
33 let fd: i64 = sys_openat_wr(opath, 0x1a4)
34 if fd < 0 { if_puts(" SAVE-FAIL\n"); return 0 }
35 sys_write(fd, out, n); sys_close(fd)
36 if_puts(" SAVED\n")
37 return 1
38}
39
40func main() -> i64 {
41 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304)
42 if r <= 0 { if_puts("INFRA: certdata load failed\n"); return 1 }
43 let store: *TrustStore = r as *TrustStore
44 if_puts("CA roots="); if_putn(trust_store_count(store)); if_puts("\n")
45 let cap: i64 = K_MAGIC_8388608
46 let out: *u8 = sys_mmap(cap)
47 var ok: i64 = 0
48
49 if_puts("== TRANSPORT / HOSTING RFCs (what SOTA serving actually is) ==\n")
50 ok = ok + fetch_save("https://www.rfc-editor.org/rfc/rfc9114.txt" as *u8, "knowledge/fetched/infra_http3.raw" as *u8, store, out, cap) // HTTP/3
51 ok = ok + fetch_save("https://www.rfc-editor.org/rfc/rfc9000.txt" as *u8, "knowledge/fetched/infra_quic.raw" as *u8, store, out, cap) // QUIC transport
52 ok = ok + fetch_save("https://www.rfc-editor.org/rfc/rfc7540.txt" as *u8, "knowledge/fetched/infra_http2.raw" as *u8, store, out, cap) // HTTP/2
53 ok = ok + fetch_save("https://www.rfc-editor.org/rfc/rfc8446.txt" as *u8, "knowledge/fetched/infra_tls13.raw" as *u8, store, out, cap) // TLS 1.3
54
55 if_puts("== ROUTING / NAMING RFCs ==\n")
56 ok = ok + fetch_save("https://www.rfc-editor.org/rfc/rfc4271.txt" as *u8, "knowledge/fetched/infra_bgp.raw" as *u8, store, out, cap) // BGP-4
57 ok = ok + fetch_save("https://www.rfc-editor.org/rfc/rfc1035.txt" as *u8, "knowledge/fetched/infra_dns.raw" as *u8, store, out, cap) // DNS
58 ok = ok + fetch_save("https://www.rfc-editor.org/rfc/rfc9110.txt" as *u8, "knowledge/fetched/infra_httpsem.raw" as *u8, store, out, cap) // HTTP semantics
59
60 if_puts("== REFERENCE SERVERS / SRE (README = the production bar) ==\n")
61 ok = ok + fetch_save("https://raw.githubusercontent.com/caddyserver/caddy/master/README.md" as *u8, "knowledge/fetched/infra_caddy.raw" as *u8, store, out, cap)
62 ok = ok + fetch_save("https://raw.githubusercontent.com/haproxy/haproxy/master/README" as *u8, "knowledge/fetched/infra_haproxy.raw" as *u8, store, out, cap)
63 ok = ok + fetch_save("https://raw.githubusercontent.com/google/sre-book-copy/master/README.md" as *u8, "knowledge/fetched/infra_sre.raw" as *u8, store, out, cap)
64
65 if_puts("infra SOTA: fetched/have="); if_putn(ok); if_puts(" / 10\n")
66 if ok >= 6 { if_puts("verdict=GREEN (real transport/routing RFCs + reference servers on disk; grep knowledge/fetched/infra_*.raw)\n"); sys_exit(0); return 0 }
67 if_puts("verdict=PARTIAL (re-run to resume; some hosts may block -> note which)\n")
68 sys_exit(1); return 1
69}