code wiki / _hdl_build / nx_live_reach.nx

nx_live_reach.nx source

↩ module page · 48 lines · 2731 B

1// nx_live_reach.nx -- the team's LIVE-WEB policy with graceful fallback (rule #14). It attempts the 2// live external source over the sovereign HTTPS stack (nx_https_get: DNS -> TCP -> TLS1.3 -> GET) and, 3// whatever the outcome stage, decides honestly what to do: if REACHABLE, use the live bytes AND mirror 4// them into the Nishi Library (so next time is sovereign); if blocked at any stage (DNS/TCP/TLS/HTTP), 5// fall back to the LOCAL mirror; only if there is no mirror either is the research UNANSWERABLE. 6// This is the policy LAYER the team owns; the byte-fetch + cert validation belong to nx_https_get and 7// are ENV-GATED (a populated CA trust store + open network). So a successful cert-validated live fetch 8// is not asserted here -- the guarantee proven is that a blocked live web never starves us when we have 9// mirrored. license_tier: ORIGINAL Pairs with nx_library_cache (the mirror) + nx_external_reach_probe. 10 11import "nx_syscalls.nx" 12 13// reach OUTCOME stages (mirror of nx_external_reach_probe's failure taxonomy, kept dependency-light). 14const LR_REACHABLE: i64 = 2 // live fetch succeeded (bytes in hand) 15const LR_DNS_FAIL: i64 = 3 // name did not resolve 16const LR_TCP_FAIL: i64 = 4 // could not connect (refused/timeout) -- the classic bot-block 17const LR_TLS_FAIL: i64 = 5 // TLS handshake/cert validation failed (e.g. empty trust store) 18const LR_HTTP_FAIL: i64 = 6 // connected+handshook but HTTP errored 19 20// the decision. 21const LR_USE_LIVE: i64 = 1 // serve from the live fetch (and mirror it) 22const LR_USE_MIRROR: i64 = 2 // live blocked -> serve from the Nishi Library mirror 23const LR_NO_DATA: i64 = 3 // live blocked AND no mirror -> honestly unanswerable 24 25func lr_is_reachable(outcome: i64) -> i64 { if outcome == LR_REACHABLE { return 1 } return 0 } 26 27// the graceful policy: prefer live, else mirror, else nothing. 28func lr_policy(outcome: i64, have_mirror: i64) -> i64 { 29 if outcome == LR_REACHABLE { return LR_USE_LIVE } 30 if have_mirror == 1 { return LR_USE_MIRROR } 31 return LR_NO_DATA 32} 33 34// can the research be answered at all (live OR mirror)? 35func lr_answerable(outcome: i64, have_mirror: i64) -> i64 { 36 if outcome == LR_REACHABLE { return 1 } 37 if have_mirror == 1 { return 1 } 38 return 0 39} 40 41// after a successful live fetch, mirror it now so the next read is sovereign (grow our own library). 42func lr_mirror_after_live(outcome: i64) -> i64 { if outcome == LR_REACHABLE { return 1 } return 0 } 43 44// the resilience win: live is blocked BUT the mirror covers it (bot-blocking did not starve us). 45func lr_blocked_but_covered(outcome: i64, have_mirror: i64) -> i64 { 46 if outcome != LR_REACHABLE { if have_mirror == 1 { return 1 } } 47 return 0 48}