code wiki / _hdl_build / nx_office_daemon.nx
nx_office_daemon.nx
buildroot/runtime/_hdl_build/nx_office_daemon.nx
about
nx_office_daemon.nx -- the DEPLOYABLE Nishi Office daemon (ops shell around the gated pure core nx_office_serve).
Binds 0.0.0.0:<port> (LAN-reachable on the NAS); files live under CWD "<root>/". Route /office -> this port on the
sovereign edge. R-AUTHZ: resolves the OPAQUE session (X-Nishi-Session header, the `sess` form field on a zero-JS
POST, or the `s` query parameter the docportal's no-JS links carry) -> handle, and passes it to of_handle_auth so
OWNED docs are ReBAC-gated while unowned docs stay PUBLIC in open mode. FAIL-SAFE: if the auth ctx can't init in
OPEN mode, serve PUBLIC-only (owned docs lock, public work); in CLOSED mode it refuses to start (never public).
2026-08-19 (LP3, /compare/legalpractice): ONE binary, N instances. Every instance parameter is argv with today's
nishifamily values as defaults, so the deployed daemons.reg row (`./nx_office_daemon.elf`) keeps working unchanged:
nx_office_daemon [port] [keysfile] [storefile] [realm] [root] [base] [uididx] [mode] [authzprefix]
mode = open (default) unowned documents are public -- nishifamily.com/office
mode = closed EVERY request needs a valid session of this realm -- the firm instance on a client domain; the
open-mode namespace is NEVER exposed there (a 401 names the login surface instead)
The uid->handle index may be the login daemon's TAB index OR a docportal "<storefile>.uidmap" ("MAP <hex> <handle>").
When a session is present the HTML response is rewritten so every same-app link carries ?s=<token> (no cookies, C1).
FORK-PER-REQUEST (2026-08-19, the docportal's proven shape): of_handle_auth mmaps its per-request scratch (me,
fullpath, qs, Origin/Host, the page and capture buffers) and returns from dozens of sites without unmapping --
the exact per-request leak class that took nx_opaque_login to 177 GB. A child that handles one connection and
then sys_exit(0) reclaims EVERY page BY CONSTRUCTION; the parent only accepts, forks and reaps (non-blocking
wait4 + backpressure at a ceiling DERIVED from the host's core count, never guessed). Functionally safe: sessions
are file-validated, every office write is a file write under <root>/ (versions, sign logs, authz tuples), and
the parent's request/response buffers are never mutated (the child works on its COW copy).
Build with --build-only; run deliberately. license_tier: ORIGINAL
dependencies 3 imports · 0 importers
imports: nx_office_serve.nxnx_opaque_login.nxnx_sysload.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
| 29 | const OD_PORT: i64 = 0x1f5e // 8030 (the nishifamily instance) |
| 30 | const OD_KEYS: *u8 = "opaque_keys.bin" |
| 31 | const OD_ASTORE: *u8 = "opaque_store.log" |
| 32 | const OD_IDX: *u8 = "nishi_uid_handle.tsv" // the login daemon's uid(hex)->handle index (authz keys off handle) |
| 33 | const OD_REALM: *u8 = "nishi_site_admin" |
| 34 | const OD_REALM_LABEL: *u8 = "Nishi site admin" |
| 35 | const OD_ROOT: *u8 = "office" |
| 36 | const OD_BASE: *u8 = "/office" |
| 40 | const OD_REQCAP: i64 = 8388608 |
| 41 | const OD_RESCAP: i64 = 1048576 |
| 42 | const OD_MODE_OPEN: i64 = 0 |
| 43 | const OD_MODE_CLOSED: i64 = 1 |
| 44 | const OD_ARG_PORT: i64 = 1 |
| 45 | const OD_ARG_KEYS: i64 = 2 |
| 46 | const OD_ARG_STORE: i64 = 3 |
| 47 | const OD_ARG_REALM: i64 = 4 |
| 48 | const OD_ARG_ROOT: i64 = 5 |
| 49 | const OD_ARG_BASE: i64 = 6 |
| 50 | const OD_ARG_IDX: i64 = 7 |
| 51 | const OD_ARG_MODE: i64 = 8 |
| 52 | const OD_ARG_AZ: i64 = 9 |
| 54 | const OD_CTX_SZ: i64 = 256 |
| 55 | const OD_TOK_CAP: i64 = 600 |
| 56 | const OD_UID_CAP: i64 = 64 |
| 57 | const OD_HANDLE_CAP: i64 = 256 |
| 58 | const OD_ADDR_SZ: i64 = 16 |
| 59 | const OD_LISTEN_BACKLOG: i64 = 16 |
| 60 | const OD_I64_SZ: i64 = 16 |
| 63 | const OD_KSF_M: i64 = 256 |
| 64 | const OD_KSF_T: i64 = 2 |
| 65 | const OD_KSF_P: i64 = 1 |
| 68 | const OD_CPU_RESERVE: i64 = 2 |
| 69 | const OD_MIN_WORKERS: i64 = 1 |
| 71 | const OD_MAP_PFX: *u8 = "MAP " |
| 72 | const OD_HEXUID: i64 = 64 |
functions
| 74 | func d_addr(out: *u8, port: i64) -> i64 called by 1: main |
| 87 | func od_resolve_handle(idxpath: *u8, uid: *u8, uidn: i64, out_h: *u8, cap: i64) -> i64 |
| 126 | func od_reap_done(wst: *i64) -> i64 called by 1: main |
| 136 | func od_worker_cap() -> i64 |
| 145 | func od_session(ctx: *NxAuthContext, reqb: *u8, rn: i64, tokb: *u8, qsb: *u8, uid: *u8, uidn: *i64, idx: *u8, hbuf: *u8) -> i64 |
| 185 | func main(argc: i64, argv: *i64) -> i64 |