code wiki / (root) / nx_swarm_beat.nx

nx_swarm_beat.nx

buildroot/runtime/nx_swarm_beat.nx

18698 B462 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic swarm
docsdependenciesstructsconstsfunctions

about

nx_swarm_beat.nx -- SWARM FABRIC fleet-beat store (SF-R1b): every worker reports its beacon NODE row here; the hub reads back a fresh fleet snapshot. This is deliberately its OWN small organ per [[feedback-no-risky-inplace-mgmt-api-deploy]] (NEVER bolt telemetry onto mgmt/hostctl) -- NAS-side it runs via the pinned tools/call lane; nx_node_beacon (v2) emits the row, this organ stores it, a later mgmt train may READ the snapshot (read-only swap of the hardcoded workers literal). nx_swarm_beat put <log> <snap> "<NODE row>" -- validate row; flock'd append to <log> (fa_append, the R0b torn-write floor); atomically replace-by-name in <snap> (whole-file rewrite, tmp+renameat) nx_swarm_beat put "<NODE row>" -- NAS tools/call form: default paths swarm_beats.log + node_rows.snap in CWD (tools daemon CWD = nishihost) nx_swarm_beat show <snap> <window_sec> -- print FRESH/STALE per row (ts vs wall clock; the window comes from the CALLER/conf -- no baked freshness constant, rule 11) nx_swarm_beat show <window_sec> -- default snap node_rows.snap PATH LAW (least-authority BY CONSTRUCTION -- a leaked cap must not clobber nishihost binaries): CLI paths must end .log/.snap, contain no "..", and be either bare basenames (land in CWD) or live under /tmp/ (local tests). Everything else -> REFUSED before any io. nx_swarm_beat [gate] -- self-gate: put/replace/show + neg-controls + the fabricated-liveness liar-killer (an ancient or future-forged ts can NEVER read FRESH) Row contract (v2 positional, additive -- emitted by nx_node_beacon): NODE <name> <cpu> <load> <ncpu> <lpc> <memu> <mema> <memt> <conns> <ts_us> <temp_mc> <batt_pct> v1 HONEST LIMIT: two DIFFERENT nodes putting at the same instant can lose one snap rewrite (last-writer-wins whole-file); periodic beats self-heal next cycle and the LOG never loses a row (flock'd). Serialize the rewrite under a lock file = v1.1 if beats ever collide in practice. license_tier: ORIGINAL expect_exit:0

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_framed_append.nx nx_swarm_beat.nx

imports: nx_syscalls.nxnx_framed_append.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sb_eq sb_puts sys_write fa_len sb_path_ok fa_len ↻ sb_put fa_len ↻ sys_mmap sb_validate sys_mmap ↻ sb_pint fa_append sys_mmap ↻ sys_openat_append sys_flock fa_write_all sys_write ↻ sys_close sb_snap_replace sys_mmap ↻ sb_read sys_openat_rd sys_read sys_close ↻ fa_cat fa_catn sys_mmap ↻ sys_now_us sys_mmap ↻ sys_clock_gettime_mono sys_openat_wr fa_write_all ↻ sys_close ↻ sys_renameat sys_mmap ↻ fa_catn ↻ sys_now_us ↻ sys_write ↻

structs

none

consts

31const SB_MAGIC_60000000: i64 = 60000000
32const SB_MAGIC_1000000: i64 = 1000000
33const SB_MAGIC_7200000000: i64 = 7200000000
34const SB_MAGIC_3600: i64 = 3600
35const SB_MAGIC_600000000: i64 = 600000000
37const SB_SNAP_CAP: i64 = 65536
38const SB_ROW_CAP: i64 = 512

functions

40func sb_puts(s: *u8) -> i64 { sys_write(1, s, fa_len(s)); return 0 }
called by 3: sb_showsb_gatemain calls 2: sys_writefa_len
42func sb_eq(a: *u8, b: *u8) -> i64
called by 1: main
50func sb_path_ok(p: *u8) -> i64
called by 2: sb_gatemain calls 1: fa_len
84func sb_read(path: *u8, buf: *u8, cap: i64) -> i64
98func sb_has(buf: *u8, n: i64, needle: *u8) -> i64
called by 1: sb_gate calls 1: fa_len
113func sb_pint(buf: *u8, n: i64, p: i64, vout: *i64, pend: *i64) -> i64
called by 2: sb_validatemain
134func sb_validate(row: *u8, n: i64, nso: *i64, nlo: *i64, tso: *i64) -> i64
called by 2: sb_putsb_show calls 2: sys_mmapsb_pint
177func sb_fresh(ts: i64, now: i64, window_sec: i64) -> i64
called by 2: sb_showsb_gate
185func sb_snap_replace(snap: *u8, row: *u8, rowlen: i64, ns: i64, nl: i64) -> i64
241func sb_put(log: *u8, snap: *u8, row: *u8) -> i64
259func sb_show(snap: *u8, window_sec: i64) -> i64
301func sb_mkrow(dst: *u8, name: *u8, cpu: i64, ts: i64) -> i64
called by 1: sb_gate calls 2: fa_catfa_catn
313func sb_gate() -> i64
420func main(argc: i64, argv: *i64) -> i64