nx_content_put_client.nx
buildroot/runtime/nx_content_put_client.nx
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
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
structs
| none |
consts
| 55 | const CC_DIGEST: i64 = 32 |
| 56 | const CC_SHAHEX: i64 = 64 |
| 57 | const CC_RESP: i64 = 262144 |
| 58 | const CC_REQ: i64 = 262144 |
| 59 | const CC_NUMBUF: i64 = 32 |
| 63 | const CC_POLLS: i64 = 40 |
| 64 | const CC_POLL_MS: i64 = 3000 |
| 67 | const CC_CHUNK_TRIES: i64 = 3 |
| 68 | const CC_CHUNK_RETRY_MS: i64 = 4000 |
| 69 | const CC_PATHCAP: i64 = 4096 |
| 70 | const CC_MODE_RW: i64 = 420 |
| 75 | const CC_MAXCHUNKS: i64 = 65536 |
| 83 | const 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:[" |
| 84 | const CC_TAIL: *u8 = "}}}" |
| 85 | const CC_QUOTE: i64 = 34 |
| 86 | const CC_BACKSLASH: i64 = 92 |
| 87 | const CC_SPACE: i64 = 32 |
| 88 | const CC_DEL: i64 = 127 |
| 210 | const CC_IDEM_SHA16: i64 = 16 |
functions
| 90 | func cc_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 91 | func cc_out(s: *u8) -> i64 { sys_write(1, s, cc_slen(s)); return 0 } called by 5: cc_resume_from_statuscc_post_chunkcc_flush_reusecc_send_cdcmain calls 2: sys_writecc_slen |
| 92 | func cc_eo(s: *u8) -> i64 { sys_write(2, s, cc_slen(s)); return 0 } |
| 93 | func cc_num(v: i64) -> i64 called by 5: cc_resume_from_statuscc_post_chunkcc_flush_reusecc_send_cdcmain calls 2: sys_mmapsys_write |
| 103 | func cc_itoa(v: i64, out: *u8) -> i64 called by 6: cc_put_idemcc_resume_from_statuscc_post_chunkcc_flush_reusecc_send_cdcmain calls 1: sys_mmap |
| 113 | func cc_hex_into(d: *u8, out: *u8) -> i64 |
| 128 | func cc_json_safe(s: *u8, n: i64) -> i64 |
| 142 | func cc_find(buf: *u8, n: i64, needle: *u8) -> i64 called by 7: cc_int_aftercc_mark_missingcc_resume_from_statuscc_post_chunkcc_flush_reusecc_send_cdc+1 calls 1: cc_slen |
| 158 | func cc_int_after(buf: *u8, n: i64, key: *u8) -> i64 |
| 178 | func cc_put_arg(req: *u8, off: i64, val: *u8, vlen: i64, first: i64) -> i64 |
| 189 | func cc_streq(a: *u8, b: *u8) -> i64 called by 1: main |
| 195 | func cc_put_lit(req: *u8, off: i64, lit: *u8) -> i64 called by 6: cc_put_idemcc_resume_from_statuscc_post_chunkcc_flush_reusecc_send_cdcmain calls 1: cc_slen |
| 211 | func cc_put_idem(req: *u8, off: i64, stage: *u8, shahex: *u8, a: i64, b: i64, t0: i64) -> i64 called by 5: cc_resume_from_statuscc_post_chunkcc_flush_reusecc_send_cdcmain calls 3: cc_put_litsys_mmapcc_itoa |
| 248 | func cc_state_path(lpath: *u8, out: *u8) -> i64 called by 1: main |
| 260 | func cc_mark_missing(resp: *u8, n: i64, miss: *i64, nch: i64) -> i64 |
| 288 | func cc_is_readcap(a: *u8) -> i64 called by 1: main |
| 309 | func cc_resume_from_status(store_i: i64, url: *u8, spath: *u8, shahex: *u8, |
| 368 | func cc_post_chunk(store_i: i64, url: *u8, req: *u8, resp: *u8, rcraw: *u8, rclen: i64, capraw: *u8, caplen: i64, |
| 463 | func cc_flush_reuse(store_i: i64, url: *u8, req: *u8, resp: *u8, rcraw: *u8, rclen: i64, capraw: *u8, caplen: i64, |
| 494 | func cc_send_cdc(store_i: i64, url: *u8, req: *u8, resp: *u8, rcraw: *u8, rclen: i64, capraw: *u8, caplen: i64, |
| 687 | func main(argc: i64, argv: *i64) -> i64 |