code wiki / _hdl_build / nx_connect_graceful_degrade.nx
nx_connect_graceful_degrade.nx source
↩ module page · 65 lines · 4378 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_connect_graceful_degrade.nx -- CONNECT capability: GRACEFUL DEGRADATION in censored/degraded regions
4// (CIQ roadmap vision cell; incumbents score 0 -- dead call buttons in the Gulf, hard-blocked in RU/CN, no
5// fallback). Nishi keeps CORE function (message delivery) alive across a severity ladder of network
6// conditions via an ordered transport fallback: direct -> fallback-TLS -> bridge-relay -> store-and-forward
7// (the last ALWAYS works: queue locally, deliver on reconnect). A naive client uses only the direct
8// transport and dies the moment it is blocked. MEASURED head-to-head: count conditions where core function
9// is PRESERVED. Naive preserves it only while direct is up; Nishi preserves it in EVERY condition, BY
10// CONSTRUCTION (store-and-forward backstop). 100% sovereign, integer. license_tier: ORIGINAL expect_exit: 0
11import "nx_syscalls.nx"
12
13const GD_C: i64 = 5 // network conditions on the censorship/degradation ladder
14const GD_T: i64 = 4 // transports: 0=direct 1=fallback-TLS 2=bridge-relay 3=store-and-forward(always)
15
16func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
17" as *u8); return ok }
18
19func main() -> i64 {
20 // transport availability per condition (1=usable). store-and-forward[3] is always 1 (local queue).
21 // C0 OPEN, C1 THROTTLED, C2 DPI-FILTERED, C3 GREY-LISTED, C4 HARD-BLOCK
22 let av: *i64 = sys_mmap(8 * GD_C * GD_T) as *i64
23 // C0 OPEN: direct up
24 av[0*GD_T+0]=1; av[0*GD_T+1]=1; av[0*GD_T+2]=1; av[0*GD_T+3]=1
25 // C1 THROTTLED: direct up (slow), fallback off
26 av[1*GD_T+0]=1; av[1*GD_T+1]=0; av[1*GD_T+2]=1; av[1*GD_T+3]=1
27 // C2 DPI-FILTERED: direct blocked, fallback-TLS up
28 av[2*GD_T+0]=0; av[2*GD_T+1]=1; av[2*GD_T+2]=1; av[2*GD_T+3]=1
29 // C3 GREY-LISTED: direct+fallback blocked, bridge up
30 av[3*GD_T+0]=0; av[3*GD_T+1]=0; av[3*GD_T+2]=1; av[3*GD_T+3]=1
31 // C4 HARD-BLOCK: no live path -> store-and-forward only (deferred delivery)
32 av[4*GD_T+0]=0; av[4*GD_T+1]=0; av[4*GD_T+2]=0; av[4*GD_T+3]=1
33
34 let names: *i64 = sys_mmap(8 * GD_C) as *i64
35 names[0]="OPEN" as *u8 as i64; names[1]="THROTTLED" as *u8 as i64; names[2]="DPI-FILTERED" as *u8 as i64; names[3]="GREY-LISTED" as *u8 as i64; names[4]="HARD-BLOCK" as *u8 as i64
36 let tnames: *i64 = sys_mmap(8 * GD_T) as *i64
37 tnames[0]="direct" as *u8 as i64; tnames[1]="fallback-TLS" as *u8 as i64; tnames[2]="bridge-relay" as *u8 as i64; tnames[3]="store-and-forward(deferred)" as *u8 as i64
38
39 gw("=== nx_connect_graceful_degrade -- core-function survival across a censorship/degradation ladder ===\n" as *u8)
40 var naive_ok: i64 = 0
41 var nishi_ok: i64 = 0
42 var nishi_live: i64 = 0
43 var c: i64 = 0
44 while c < GD_C {
45 // naive: direct only
46 let nv: i64 = av[c*GD_T+0]
47 // nishi: first usable transport in ladder order
48 var used: i64 = 0 - 1
49 var t: i64 = 0
50 while t < GD_T { if used < 0 { if av[c*GD_T+t] == 1 { used = t } } t = t + 1 }
51 if nv == 1 { naive_ok = naive_ok + 1 }
52 if used >= 0 { nishi_ok = nishi_ok + 1; if used < 3 { nishi_live = nishi_live + 1 } }
53 gw(" " as *u8); gw(names[c] as *u8); gw(": naive=" as *u8); if nv==1 { gw("DELIVER" as *u8) } else { gw("FAIL" as *u8) }
54 gw(" nishi=" as *u8); if used>=0 { gw("DELIVER via " as *u8); gw(tnames[used] as *u8) } else { gw("FAIL" as *u8) } gw("\n" as *u8)
55 c = c + 1
56 }
57 gw("core-function preserved: naive=" as *u8); gn(naive_ok); gw("/" as *u8); gn(GD_C); gw(" nishi=" as *u8); gn(nishi_ok); gw("/" as *u8); gn(GD_C); gw(" (nishi live=" as *u8); gn(nishi_live); gw(", deferred=" as *u8); gn(nishi_ok - nishi_live); gw(")\n" as *u8)
58
59 // MEASURED gate: nishi preserves core function in EVERY condition AND strictly beats the naive client.
60 var ok: i64 = 0
61 if nishi_ok == GD_C { if naive_ok < nishi_ok { ok = 1 } }
62 gw("--- gate --- nishi core-preserved in all conditions & > naive: " as *u8); if ok==1 { gw("PASS" as *u8) } else { gw("FAIL" as *u8) } gw("\n" as *u8)
63 if ok == 1 { gw("GRACEDEGRADEGATE verdict=GREEN (Nishi keeps people connected where incumbents go dark; exceed by construction)\n" as *u8); sys_exit(0); return 0 }
64 gw("GRACEDEGRADEGATE verdict=RED\n" as *u8); sys_exit(1); return 1
65}