code wiki / _hdl_build / nx_connect_graceful_degrade.nx

nx_connect_graceful_degrade.nx source

↩ module page · 66 lines · 4532 B

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