code wiki / (root) / nx_content_put_client.nx

nx_content_put_client.nx

buildroot/runtime/nx_content_put_client.nx

50154 B929 linesdepth 23pulls 156 transitivereach 0 importersview sourcekind tooltopic content
docsdependenciesstructsconstsfunctions

about

nx_content_put_client.nx -- THE SOVEREIGN laptop->NAS UPLOAD CLIENT. Retires nx_content_put_client.py. WHY THIS EXISTS (operator standing order 2026-09-03: "i dont want py or js or sh or anything else in the build lanes i want us nishilang soverign", and again "dont build python wtf build nishi"). nx_content_put has been the sovereign RECEIVER since 2026-08-23; its only driver was an 8,525-byte Python script shelling out to a Python MCP wire. This is the NishiLang driver. IT WAS BLOCKED ON ONE MISSING PRIMITIVE, NOW BUILT. Driving the receiver needs POST-a-body-to-a-URL. The estate had no such thing: nx_https_post_json took a URL and a body and issued a GET (corrected to refuse, 2026-09-03), and nx_https_post_complete_xhdr needs an already-established session. hp_post_json (nx_https_post_lib.nx) is the glue, and this file is its first consumer. nx_content_put_client [dryrun] <local_path> <dest> <capfile> <url> [expect=<sha256hex>] IT REFUSES TO ESCAPE JSON RATHER THAN ESCAPING IT BADLY. Every value this client puts on the wire comes from a KNOWN-SAFE alphabet: a destination path, decimal digits, lowercase hex, base64 (A-Za-z0-9+/=) and a capability token. None of them can contain a quote, a backslash or a control byte. So instead of hand-rolling a JSON escaper -- a defect generator that is wrong in exactly the cases nobody tests -- cc_json_safe() REFUSES any argument carrying a character that would need escaping. A hand-rolled escaper fails SILENTLY and produces a malformed request the server rejects for the wrong reason; a refusal names the offending byte and stops. THE CHUNK SIZE IS THE SERVER'S, READ FROM ITS OWN RECEIPT -- NEVER COMPUTED HERE. nx_content_put derives chunk_raw from the wire body cap, the request skeleton measured at runtime, the largest observed capability token and the i64 digit bound. Recomputing that here would install a second ruler that drifts the moment the server's reserve changes, and the drift would show up as truncated uploads. The client reads chunk_raw= out of the begin receipt and uses it verbatim. A CHUNK RE-SEND IS SAFE; A COMMIT RETRY IS NOT DECIDABLE FROM HERE. The receiver treats an identical re-send as a receipted no-op and REFUSES a different body for an index that already landed (CAS), so a chunk retry can never double-apply. A lost COMMIT response is genuinely UNKNOWN -- the transfer id may be gone because it committed. This client says so and tells the caller to verify by hash rather than guessing; it does not retry commit. STATUS 2026-09-04: THE ROUND TRIP IS NOW PROVEN AND THIS ORGAN IS LIVE. It had never completed a transfer before today and had never been promoted at all -- no nx_content_put_client.elf existed in the serving root -- so the Python it claims to retire was in fact the only working shipper. Two defects stood between the two facts: this client did not follow the edge's JOB-STARTED promotion (it read the JOB id as the transfer id, both being spelled `id=`), and the shared TLS transport wrote every request as ONE record, capping a body at 8 KB against the 48,402-byte chunks the server offers.

dependencies 6 imports · 0 importers

nx_syscalls.nx nx_base64.nx nx_sha256.nx nx_cdc_lib.nx nx_https_post_lib.nx nx_jobfollow_lib.nx nx_content_put_client.nx

imports: nx_syscalls.nxnx_base64.nxnx_sha256.nxnx_cdc_lib.nxnx_https_post_lib.nxnx_jobfollow_lib.nx

imported by: nobody (leaf or entry point)

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

main cc_streq cc_eo sys_write cc_slen cc_is_readcap 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 sys_write ↻ nxa_dump_sizes sys_write ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_munmap sys_close sha256_digest sys_mmap ↻ sha256_init sys_mmap ↻ sha256_seed_allocated sha256_k sha256_update sha256_compress_ni_blocks blk_set_byte sha256_compress sha256_compress_ni blk_word

structs

none

consts

55const CC_DIGEST: i64 = 32
56const CC_SHAHEX: i64 = 64
57const CC_RESP: i64 = 262144
58const CC_REQ: i64 = 262144
59const CC_NUMBUF: i64 = 32
63const CC_POLLS: i64 = 40
64const CC_POLL_MS: i64 = 3000
67const CC_CHUNK_TRIES: i64 = 3
68const CC_CHUNK_RETRY_MS: i64 = 4000
69const CC_PATHCAP: i64 = 4096
70const CC_MODE_RW: i64 = 420
75const CC_MAXCHUNKS: i64 = 65536
83const CC_PRE: *u8 = "{\x22jsonrpc\x22:\x222.0\x22,\x22id\x22:1,\x22method\x22:\x22tools/call\x22,\x22params\x22:{\x22name\x22:\x22nx_content_put\x22,\x22arguments\x22:{\x22argv\x22:["
84const CC_TAIL: *u8 = "}}}"
85const CC_QUOTE: i64 = 34
86const CC_BACKSLASH: i64 = 92
87const CC_SPACE: i64 = 32
88const CC_DEL: i64 = 127
210const CC_IDEM_SHA16: i64 = 16

functions

90func cc_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
91func cc_out(s: *u8) -> i64 { sys_write(1, s, cc_slen(s)); return 0 }
92func cc_eo(s: *u8) -> i64 { sys_write(2, s, cc_slen(s)); return 0 }
93func cc_num(v: i64) -> i64
103func cc_itoa(v: i64, out: *u8) -> i64
113func cc_hex_into(d: *u8, out: *u8) -> i64
128func cc_json_safe(s: *u8, n: i64) -> i64
called by 2: cc_put_argmain
142func cc_find(buf: *u8, n: i64, needle: *u8) -> i64
158func cc_int_after(buf: *u8, n: i64, key: *u8) -> i64
178func cc_put_arg(req: *u8, off: i64, val: *u8, vlen: i64, first: i64) -> i64
189func cc_streq(a: *u8, b: *u8) -> i64
called by 1: main
195func cc_put_lit(req: *u8, off: i64, lit: *u8) -> i64
211func cc_put_idem(req: *u8, off: i64, stage: *u8, shahex: *u8, a: i64, b: i64, t0: i64) -> i64
248func cc_state_path(lpath: *u8, out: *u8) -> i64
called by 1: main
260func cc_mark_missing(resp: *u8, n: i64, miss: *i64, nch: i64) -> i64
called by 1: cc_resume_from_status calls 1: cc_find
288func cc_is_readcap(a: *u8) -> i64
called by 1: main
309func cc_resume_from_status(store_i: i64, url: *u8, spath: *u8, shahex: *u8,
368func cc_post_chunk(store_i: i64, url: *u8, req: *u8, resp: *u8, rcraw: *u8, rclen: i64, capraw: *u8, caplen: i64,
463func cc_flush_reuse(store_i: i64, url: *u8, req: *u8, resp: *u8, rcraw: *u8, rclen: i64, capraw: *u8, caplen: i64,
494func cc_send_cdc(store_i: i64, url: *u8, req: *u8, resp: *u8, rcraw: *u8, rclen: i64, capraw: *u8, caplen: i64,
687func main(argc: i64, argv: *i64) -> i64