code wiki / _hdl_build / nx_hub_gw.nx
nx_hub_gw.nx
buildroot/runtime/_hdl_build/nx_hub_gw.nx
about
nx_hub_gw.nx -- the HUB gateway DAEMON (loopback HTTP), the live shell over the gated maturity router.
Sits behind sites_daemon's fail-closed /hub reverse-proxy (mirrors the /wiki -> wiki_gw topology). Per
request it: resolves the OPAQUE no-cookie X-Nishi-Session token -> handle (the PROVEN chain olg_whoami ->
uid -> hex -> idx_lookup), re-reads the maturity registry + roles (HOT, leak-free -> a flag edit is live
with NO restart = the can't-crash-hosting property), calls mr_route, and acts FAIL-CLOSED:
SERVE -> 200 (artifact body, path-traversal-checked) DENY/no-session -> 302 /login
DENY/under-level -> 403 NOTFOUND / TIER_MISMATCH -> 404 (no leak)
ISOLATED from the login daemon ON PURPOSE: a bug here can never regress login/whoami/register.
LEAK DISCIPLINE: every per-request read uses hgw_read_file (bounded sys_read into a REUSED buffer), NOT
sys_read_file (which reserves 4 GiB/call and never unmaps -- the F-class root). All buffers are mmap'd
ONCE before the accept loop and reused -> the daemon's virtual footprint is flat across requests.
Sovereign: nx_opaque_login (auth) + nx_maturity_registry (mr_route) + nx_hub_gw_decide (parsers). ORIGINAL.
dependencies 6 imports · 0 importers
imports: nx_opaque_login.nxnx_hub_gw_decide.nxnx_maturity_registry.nxnx_site_lock_lib.nxnx_access_lib.nxnx_hub_render.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 20 | const HGW_MAGIC_65536: i64 = 65536 |
| 21 | const HGW_MAGIC_16400: i64 = 16400 |
| 22 | const HGW_MAGIC_131072: i64 = 131072 |
| 23 | const HGW_MAGIC_32768: i64 = 32768 |
| 24 | const HGW_MAGIC_262144: i64 = 262144 |
| 25 | const HGW_MAGIC_524288: i64 = 524288 |
| 26 | const HGW_MAGIC_1024: i64 = 1024 |
| 27 | const HGW_MAGIC_1280: i64 = 1280 |
| 28 | const HGW_MAGIC_16383: i64 = 16383 |
| 29 | const HGW_MAGIC_2097152: i64 = 2097152 |
| 31 | const HGW_REG: *u8 = "/volume1/ai/hub/maturity.tsv" |
| 32 | const HGW_ROLES: *u8 = "/volume1/ai/hub/roles.tsv" |
| 33 | const HGW_DOCROOT: *u8 = "/volume1/ai/hub/pages" |
| 34 | const HGW_IDX: *u8 = "/volume1/homes/elderwesto/nishihost/nishi_uid_handle.tsv" |
| 39 | const HGW_BOOTSTRAP: *u8 = "<!DOCTYPE html><html lang='en'><head><meta charset='utf-8'><meta name='viewport' content='width=device-width, initial-scale=1'><title>Nishi Hub</title></head><body><script>(function(){var t=sessionStorage.getItem('nsess');if(!t){location='/login';return}fetch(location.pathname,{headers:{'X-Nishi-Session':t}}).then(function(r){return r.ok?r.text():null}).then(function(x){if(x){document.open();document.write(x);document.close()}else{location='/login'}})})();</script></body></html>" |
functions
| 41 | func hgw_atoi(s: *u8) -> i64 { var v: i64=0; var i: i64=0; while s[i]!=(0 as u8){ let c: i64=s[i] as i64; if c<48{return v} if c>57{return v} v=v*10+(c-48); i=i+1 } return v } |
| 42 | func hgw_cat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64=off; var i: i64=0; while s[i]!=(0 as u8){dst[o]=s[i]; o=o+1; i=i+1} return o } |
| 43 | func hgw_catb(dst: *u8, off: i64, src: *u8, n: i64) -> i64 { var o: i64=off; var i: i64=0; while i<n {dst[o]=src[i]; o=o+1; i=i+1} return o } called by 1: hgw_send |
| 54 | func hgw_itoa(dst: *u8, off: i64, v: i64) -> i64 { if (hgw_scr_t as i64)==0 { hgw_scr_t=sys_mmap(28) } let t: *u8=hgw_scr_t; var m: i64=v; var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var o: i64=off; var q: i64=k-1; while q>=0{dst[o]=t[q];o=o+1;q=q-1} return o } called by 1: hgw_send |
| 55 | func hgw_hex(dst: *u8, off: i64, src: *u8, n: i64) -> i64 { let hx: *u8="0123456789abcdef" as *u8; var o: i64=off; var i: i64=0; while i<n { let c: i64=(src[i] as i64)&0xff; dst[o]=hx[(c>>4)&15]; dst[o+1]=hx[c&15]; o=o+2; i=i+1 } return o } called by 1: main |
| 56 | func hgw_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 59 | func hgw_read_file(path: *u8, out: *u8, cap: i64) -> i64 |
| 79 | func hgw_level_native(handle: *u8, hlen: i64) -> i64 |
| 110 | func hgw_ncfg_to_buf(prefix: *u8, tag: *u8, keys: *i64, nkeys: i64, buf: *u8, cap: i64) -> i64 |
| 141 | func hgw_idx_lookup(idxbuf: *u8, idxlen: i64, uidhex: *u8, uxn: i64, out_h: *u8, cap: i64) -> i64 |
| 165 | func hgw_ctype(file: *u8, n: i64) -> *u8 |
| 182 | func hgw_path_safe(p: *u8, n: i64) -> i64 called by 1: main |
| 191 | func hgw_send(cfd: i64, scratch: *u8, status: *u8, ctype: *u8, body: *u8, blen: i64) -> i64 |
| 201 | func hgw_redirect(cfd: i64, scratch: *u8, loc: *u8) -> i64 |
| 208 | func hgw_text(cfd: i64, scratch: *u8, status: *u8, msg: *u8) -> i64 |
| 212 | func main(argc: i64, argv: *i64) -> i64 |