code wiki / _hdl_build / nx_host_router.nx

nx_host_router.nx

buildroot/runtime/_hdl_build/nx_host_router.nx

40120 B764 linesdepth 2pulls 2 transitivereach 6 importersview sourcekind librarytopic host
docsdependenciesstructsconstsfunctions

about

nx_host_router.nx -- S-class sovereign multi-site host router (pure Nishi, no TLS, no crypto). Config-driven vhost table + PER-REQUEST file serving = HOT CONTENT LOADING: push a file, it is live on the next request, NO recompile. Path-traversal-safe. This is L5 (content) of the sovereign hosting design (knowledge/research/2026-06-05-sovereign-web-hosting.md). Composed into the TLS daemon, which supplies L3/L4. license_tier: ORIGINAL

dependencies 1 imports · 6 importers

nx_syscalls.nx nx_host_router.nx nx_host_router2_test.nx nx_host_router_gate.nx nx_host_router_test.nx nx_hr_serve3_slot_gate.nx nx_sites_daemon.nx nx_sites_daemon_v2.nx

imports: nx_syscalls.nx

imported by: nx_host_router2_test.nxnx_host_router_gate.nxnx_host_router_test.nxnx_hr_serve3_slot_gate.nxnx_sites_daemon.nxnx_sites_daemon_v2.nx

structs

none

consts

7const HR_MAGIC_1024: i64 = 1024
8const HR_MAGIC_4096: i64 = 4096
9const HR_MAGIC_5120: i64 = 5120
10const HR_MAGIC_2048: i64 = 2048
11const HR_MAGIC_4095: i64 = 4095
319const HR_ASSET_MAXAGE: i64 = 3600
375const HR_S2_MISS: i64 = 0 // host known but file absent -> caller falls through to legacy routing
376const HR_S2_OK: i64 = 1 // 200 written
377const HR_S2_BAD: i64 = 2 // 400 written (traversal/malformed)
378const HR_S2_TOOBIG: i64 = 3 // 500 written (file exceeds outcap)
433const HR_S2_REDIR: i64 = 4 // 301 written to out (out_n set); caller must NOT fall through
434const HR_S2_STREAM: i64 = 5 // headers written to out; BODY handed via hr_stream_body/bodyn -- the
608const HR_SLOT_MARK: *u8 = "<!--nx-ad-slot-->" as *u8

functions

13func hr_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
15func hr_copy(dst: *u8, src: *u8, n: i64) -> i64 { var i: i64 = 0; while i < n { dst[i] = src[i]; i = i + 1 } return n }
called by 1: hr_lookup_root
17func hr_eq(a: *u8, b: *u8, n: i64) -> i64
23func hr_lower(c: u8) -> u8
called by 2: hr_ieqhr_req_host
28func hr_ieq(a: *u8, b: *u8, n: i64) -> i64
35func hr_putdec(out: *u8, v: i64) -> i64
called by 4: hr_emithr_emit_bt_pnt_pn calls 1: sys_mmap
53func hr_req_path(req: *u8, reqn: i64, out: *u8, cap: i64) -> i64
72func hr_req_query(req: *u8, reqn: i64, out: *u8, cap: i64) -> i64
98func hr_req_host(req: *u8, reqn: i64, out: *u8, cap: i64) -> i64
124func hr_lookup_root(cfg: *u8, cfgn: i64, host: *u8, hostn: i64, out: *u8, cap: i64) -> i64
158func hr_path_safe(path: *u8, pathn: i64) -> i64
171func hr_resolve(root: *u8, rootn: i64, path: *u8, pathn: i64, out: *u8, cap: i64) -> i64
called by 2: hr_servemain
207func hr_ctype(file: *u8, filen: i64) -> *u8
246func hr_emit(out: *u8, statusline: *u8, ctype: *u8, body: *u8, bodyn: i64) -> i64
called by 1: hr_serve calls 1: hr_putdec
265func hr_known_host(cfg: *u8, cfgn: i64, req: *u8, reqn: i64) -> i64
276func hr_serve(cfg: *u8, cfgn: i64, req: *u8, reqn: i64, out: *u8, outcap: i64) -> i64
321func hr_emit_b(out: *u8, outcap: i64, statusline: *u8, ctype: *u8, body: *u8, bodyn: i64) -> i64
385func hr_serve2(cfg: *u8, cfgn: i64, req: *u8, reqn: i64, out: *u8, outcap: i64, out_n: *i64) -> i64
418func hr_emit_404(out: *u8, outcap: i64) -> i64
443func hr_stream_body() -> i64 { return hr_stream_p }
444func hr_stream_bodyn() -> i64 { return hr_stream_n }
448func hr_emit_head(out: *u8, outcap: i64, statusline: *u8, ctype: *u8, bodyn: i64) -> i64
479func hr_ends2(s: *u8, n: i64, suf: *u8, sufn: i64) -> i64
488func hr_canon(path: *u8, pn: i64, loc: *u8) -> i64
508func hr_join(root: *u8, rn: i64, path: *u8, pn: i64, suffix: *u8, file: *u8, cap: i64) -> i64
525func hr_resolve_read(root: *u8, rn: i64, path: *u8, pn: i64, file: *u8, cap: i64, fnlen: *i64, dn: *i64) -> *u8
551func hr_emit_redirect(out: *u8, outcap: i64, loc: *u8, locn: i64) -> i64
568func hr_ct_is_html(ct: *u8) -> i64
573func hr_find_close_body(body: *u8, bn: i64) -> i64
586func hr_has_optout(body: *u8, bn: i64) -> i64
610func hr_find_slot_anchor(d: *u8, n: i64) -> i64
622func hr_serve3_slot(cfg: *u8, cfgn: i64, req: *u8, reqn: i64, out: *u8, outcap: i64, out_n: *i64, slot: *u8, slot_n: i64, injected: *i64) -> i64
711func hr_serve3(cfg: *u8, cfgn: i64, req: *u8, reqn: i64, out: *u8, outcap: i64, out_n: *i64) -> i64