code wiki / _hdl_build / nx_office_daemon.nx

nx_office_daemon.nx

buildroot/runtime/_hdl_build/nx_office_daemon.nx

15024 B275 linesdepth 16pulls 66 transitivereach 0 importersview sourcekind servicetopic office
docsdependenciesstructsconstsfunctions

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

nx_office_serve.nx nx_opaque_login.nx nx_sysload.nx nx_office_daemon.nx

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

main of_atoi of_seq p olg_ctx_setup olg_ctx_setup_ttl nx_uas_server_keys_load_or sys_mmap nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable nxa_dump_sizes sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_munmap 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 ↻ u256_alloc nx_scratch nx_opq_hash_to_scalar

structs

none

consts

29const OD_PORT: i64 = 0x1f5e // 8030 (the nishifamily instance)
30const OD_KEYS: *u8 = "opaque_keys.bin"
31const OD_ASTORE: *u8 = "opaque_store.log"
32const OD_IDX: *u8 = "nishi_uid_handle.tsv" // the login daemon's uid(hex)->handle index (authz keys off handle)
33const OD_REALM: *u8 = "nishi_site_admin"
34const OD_REALM_LABEL: *u8 = "Nishi site admin"
35const OD_ROOT: *u8 = "office"
36const OD_BASE: *u8 = "/office"
40const OD_REQCAP: i64 = 8388608
41const OD_RESCAP: i64 = 1048576
42const OD_MODE_OPEN: i64 = 0
43const OD_MODE_CLOSED: i64 = 1
44const OD_ARG_PORT: i64 = 1
45const OD_ARG_KEYS: i64 = 2
46const OD_ARG_STORE: i64 = 3
47const OD_ARG_REALM: i64 = 4
48const OD_ARG_ROOT: i64 = 5
49const OD_ARG_BASE: i64 = 6
50const OD_ARG_IDX: i64 = 7
51const OD_ARG_MODE: i64 = 8
52const OD_ARG_AZ: i64 = 9
54const OD_CTX_SZ: i64 = 256
55const OD_TOK_CAP: i64 = 600
56const OD_UID_CAP: i64 = 64
57const OD_HANDLE_CAP: i64 = 256
58const OD_ADDR_SZ: i64 = 16
59const OD_LISTEN_BACKLOG: i64 = 16
60const OD_I64_SZ: i64 = 16
63const OD_KSF_M: i64 = 256
64const OD_KSF_T: i64 = 2
65const OD_KSF_P: i64 = 1
68const OD_CPU_RESERVE: i64 = 2
69const OD_MIN_WORKERS: i64 = 1
71const OD_MAP_PFX: *u8 = "MAP "
72const OD_HEXUID: i64 = 64

functions

74func d_addr(out: *u8, port: i64) -> i64
called by 1: main
87func od_resolve_handle(idxpath: *u8, uid: *u8, uidn: i64, out_h: *u8, cap: i64) -> i64
126func od_reap_done(wst: *i64) -> i64
called by 1: main
136func od_worker_cap() -> i64
called by 1: main calls 1: sl_ncpu
145func od_session(ctx: *NxAuthContext, reqb: *u8, rn: i64, tokb: *u8, qsb: *u8, uid: *u8, uidn: *i64, idx: *u8, hbuf: *u8) -> i64
185func main(argc: i64, argv: *i64) -> i64