code wiki / _hdl_build / nx_hub_gw.nx

nx_hub_gw.nx

buildroot/runtime/_hdl_build/nx_hub_gw.nx

24554 B392 linesdepth 16pulls 55 transitivereach 0 importersview sourcekind servicetopic hub
docsdependenciesstructsconstsfunctions

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

nx_opaque_login.nx nx_hub_gw_decide.nx nx_maturity_registry.nx nx_site_lock_lib.nx nx_access_lib.nx nx_hub_render.nx nx_hub_gw.nx

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

main hgw_atoi olg_ctx_setup olg_ctx_setup_ttl nx_uas_server_keys_load_or sys_mmap sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close _uas_hex_dec _uas_nib nx_csprng_fill sys_mmap ↻ nx_csprng_urandom_path sys_openat_rd ↻ sys_read ↻ sys_close ↻ nx_opq_derive_keypair sys_mmap ↻ _voprf_load_context_string u256_alloc nx_scratch nx_opq_hash_to_scalar sys_mmap ↻ nx_h2c_expand_message_xmd_ u256_alloc ↻ _opq_reduce_48be_mod_n u256_store_be u256_load_be u256_is_zero p256_point_alloc nx_scratch ↻ u256_alloc ↻ p256_field_one p256_field_zero p256_point_load_g p256_field_one ↻

structs

none

consts

20const HGW_MAGIC_65536: i64 = 65536
21const HGW_MAGIC_16400: i64 = 16400
22const HGW_MAGIC_131072: i64 = 131072
23const HGW_MAGIC_32768: i64 = 32768
24const HGW_MAGIC_262144: i64 = 262144
25const HGW_MAGIC_524288: i64 = 524288
26const HGW_MAGIC_1024: i64 = 1024
27const HGW_MAGIC_1280: i64 = 1280
28const HGW_MAGIC_16383: i64 = 16383
29const HGW_MAGIC_2097152: i64 = 2097152
31const HGW_REG: *u8 = "/volume1/ai/hub/maturity.tsv"
32const HGW_ROLES: *u8 = "/volume1/ai/hub/roles.tsv"
33const HGW_DOCROOT: *u8 = "/volume1/ai/hub/pages"
34const HGW_IDX: *u8 = "/volume1/homes/elderwesto/nishihost/nishi_uid_handle.tsv"
39const 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

41func 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 }
42func 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 }
43func 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
54func 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
55func 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
56func hgw_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 2: hgw_textmain
59func hgw_read_file(path: *u8, out: *u8, cap: i64) -> i64
called by 1: main calls 1: sys_read
79func hgw_level_native(handle: *u8, hlen: i64) -> i64
110func hgw_ncfg_to_buf(prefix: *u8, tag: *u8, keys: *i64, nkeys: i64, buf: *u8, cap: i64) -> i64
141func hgw_idx_lookup(idxbuf: *u8, idxlen: i64, uidhex: *u8, uxn: i64, out_h: *u8, cap: i64) -> i64
165func hgw_ctype(file: *u8, n: i64) -> *u8
called by 1: main calls 1: slk_eq
182func hgw_path_safe(p: *u8, n: i64) -> i64
called by 1: main
191func hgw_send(cfd: i64, scratch: *u8, status: *u8, ctype: *u8, body: *u8, blen: i64) -> i64
201func hgw_redirect(cfd: i64, scratch: *u8, loc: *u8) -> i64
called by 1: main calls 1: hgw_cat
208func hgw_text(cfd: i64, scratch: *u8, status: *u8, msg: *u8) -> i64
called by 1: main calls 2: hgw_sendhgw_slen
212func main(argc: i64, argv: *i64) -> i64