nx_hops_probe.nx source
↩ module page · 64 lines · 2962 B
1// nx_hops_probe.nx -- PROVE THE REDIRECT-DEPTH OBSERVABLE FIRES.
2//
3// nx_https_last_hops() was added 2026-08-16 because the fetcher walked the redirect chain and threw
4// its length away, so nothing downstream could tell a page that DELIVERED from one that BOUNCED.
5// But an observable that has only ever been read on a NON-redirecting host reads 0, and 0 is exactly
6// what a broken wire also reads. A green that never had a corresponding red is unverified.
7//
8// So this is a two-sided control, run against a caller-supplied url:
9// a direct host -> hops should be 0 (negative control: the counter is not stuck high)
10// a redirecting host -> hops should be >0 (positive control: the counter actually moves)
11// Point it at our OWN edge for the redirect case -- it issues 301s for clean urls -- so proving our
12// instrument costs no third party a single request.
13//
14// Reports NUMBERS, never a verdict: an uncalibrated observable that emits a judgement teaches people
15// to trust a bar nobody measured. license_tier: ORIGINAL
16import "nx_syscalls.nx"
17import "nx_x509_trust_store.nx"
18import "nx_trust_store_load_from_certdata.nx"
19import "nx_https_fetch_follow.nx"
20import "nx_edgar_lib.nx" // edgar_ua_header -- the ONE declared-identity definition
21
22const HP_CAP: i64 = 4194304
23const HP_TRUST: i64 = 4194304
24const HP_HOPS: i64 = 6 // same bound the shipped callers pass; not a new number
25
26func hp(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
27func hn(v: i64) -> i64 {
28 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
29 var m: i64 = v
30 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
31 let d: *u8 = sys_mmap(24); var k: i64 = 0
32 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
33 let o: *u8 = sys_mmap(24); var i: i64 = 0
34 while i < k { o[i] = d[k - 1 - i]; i = i + 1 }
35 sys_write(1, o, k)
36 return 0
37}
38
39func main(argc: i64, argv: *i64) -> i64 {
40 if argc < 2 { hp("usage: nx_hops_probe <url> (reports status, bytes, redirect hops)\n" as *u8); return 2 }
41 let url: *u8 = argv[1] as *u8
42
43 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, HP_TRUST)
44 if r <= 0 { hp("certdata load failed\n" as *u8); return 1 }
45 let store: *TrustStore = r as *TrustStore
46
47 let xh: *u8 = sys_mmap(320)
48 let xo: i64 = edgar_ua_header(xh, 320)
49
50 let buf: *u8 = sys_mmap(HP_CAP)
51 let status: *i64 = sys_mmap(16) as *i64
52 let n: i64 = nx_https_fetch_follow_hdr_best(url, store, buf, HP_CAP, HP_HOPS, status, xh, xo)
53 let hops: i64 = nx_https_last_hops()
54
55 hp("{\"tool\":\"nx_hops_probe\",\"url\":\"" as *u8); hp(url)
56 hp("\",\"status\":" as *u8); hn(status[0])
57 hp(",\"body_bytes\":" as *u8); hn(n)
58 hp(",\"redirect_hops\":" as *u8); hn(hops)
59 hp(",\"ua_declared\":" as *u8)
60 if xo > 0 { hn(1) }
61 if xo <= 0 { hn(0) }
62 hp("}\nHOPS-PROBE-OK\n" as *u8)
63 return 0
64}