nx_fetch_probe.nx source
↩ module page · 61 lines · 3393 B
1// nx_fetch_probe.nx -- GENERAL fetch-reachability diagnostic: nx_fetch_probe <url>. Reports, for any URL, what
2// the sovereign fetcher sees: TLS1.3 GET status/bytes, chrome-fingerprint GET, and Range(0-65535) support
3// (206 vs 200 vs fail). Reworked (not retired) from the one-off BeerQA probe (rework-dont-retire doctrine) --
4// this is the standing "why can't we fetch X" tool that pinned nlp.stanford.edu as connect-unreachable.
5// Usage: build once via nx_sov_build_run (usage run exits 0), then: /tmp/nx_fetch_probe.sov.elf <url>
6// expect_exit: 0 license_tier: ORIGINAL
7import "nx_research_engine.nx"
8const K_MAGIC_131072: i64 = 131072
9const K_MAGIC_65535: i64 = 65535
10
11// decode a negative NX_FF_* return into a named layer (rf_putn mangles negatives, and the name pins the layer)
12func fp_rc(n: i64) -> i64 {
13 if n > 0 { rf_puts(" OK-bytes=" as *u8); rf_putn(n); return 0 }
14 if n == 0 { rf_puts(" rc=0" as *u8); return 0 }
15 if n == 0-1 { rf_puts(" FAIL=BAD_URL" as *u8); return 0 }
16 if n == 0-2 { rf_puts(" FAIL=CONNECT(dns/tcp)" as *u8); return 0 }
17 if n == 0-3 { rf_puts(" FAIL=HANDSHAKE(tls)" as *u8); return 0 }
18 if n == 0-4 { rf_puts(" FAIL=GET(read)" as *u8); return 0 }
19 if n == 0-5 { rf_puts(" FAIL=PARSE" as *u8); return 0 }
20 rf_puts(" FAIL=other(" as *u8); rf_putn(0-n); rf_puts(")" as *u8); return 0
21}
22
23func fp_get(label: *u8, url: *u8, store: *TrustStore, chrome: i64) -> i64 {
24 let cap: i64 = K_MAGIC_131072
25 let out: *u8 = sys_mmap(cap)
26 let st: *i64 = sys_mmap(16) as *i64
27 var n: i64 = 0
28 if chrome == 1 { n = nx_https_fetch_follow_chrome(url, store, out, cap, 6, st) }
29 else { n = nx_https_fetch_follow(url, store, out, cap, 6, st) }
30 rf_puts(label); rf_puts(" status="); rf_putn(st[0]); fp_rc(n)
31 if n > 0 { rf_puts(" first60=[" as *u8); var m: i64 = n; if m > 60 { m = 60 } sys_write(1, out, m); rf_puts("]" as *u8) }
32 rf_puts("\n" as *u8)
33 return n
34}
35
36func main(argc: i64, argv: *i64) -> i64 {
37 if argc < 2 { rf_puts("usage: nx_fetch_probe <url> (build once, then run /tmp/nx_fetch_probe.sov.elf <url>)\n" as *u8); return 0 }
38 let url: *u8 = argv[1] as *u8
39 let store: *TrustStore = rf_init()
40 if (store as i64) == 0 { rf_puts("no trust store\n" as *u8); return 1 }
41 rf_puts("probe: "); rf_puts(url); rf_puts("\n" as *u8)
42 fp_get(" TLS1.3-GET " as *u8, url, store, 0)
43 fp_get(" CHROME-GET " as *u8, url, store, 1)
44 // TLS 1.2 fallback path (for hosts that reject our 1.3 ClientHello)
45 let cap12: i64 = K_MAGIC_131072
46 let out12: *u8 = sys_mmap(cap12)
47 let st12: *i64 = sys_mmap(16) as *i64
48 let n12: i64 = nx_https_fetch_follow_12(url, store, out12, cap12, st12)
49 rf_puts(" TLS1.2-GET status=" as *u8); rf_putn(st12[0]); fp_rc(n12)
50 if n12 > 0 { rf_puts(" first60=[" as *u8); var m12: i64 = n12; if m12 > 60 { m12 = 60 } sys_write(1, out12, m12); rf_puts("]" as *u8) }
51 rf_puts("\n" as *u8)
52 let cap: i64 = K_MAGIC_131072
53 let out: *u8 = sys_mmap(cap)
54 let st: *i64 = sys_mmap(16) as *i64
55 let rn: i64 = nx_https_fetch_range(url, store, out, cap, 0, K_MAGIC_65535, st, 0)
56 rf_puts(" RANGE-GET status="); rf_putn(st[0]); rf_puts(" rc="); rf_putn(rn)
57 if st[0] == 206 { rf_puts(" (server honors Range = chunkable)" as *u8) }
58 if st[0] == 200 { rf_puts(" (Range ignored, full body)" as *u8) }
59 rf_puts("\n" as *u8)
60 return 0
61}