nx_dgram_media.nx
buildroot/runtime/nx_dgram_media.nx
about
nx_dgram_media.nx -- R1 of the SOVEREIGN DATAGRAM TRANSPORT (task #15; operator 2026-07-05: "pure nishi
sovereign -- no WebTransport; build from the hardware rung up, each rung"). The UDP-class media wire:
small MTU-safe packets, fragmentation/reassembly for codec frames (a 7KB keyframe -> ~7 frags), seq
dedupe, gap detection (feeds NACK), and the NACK packet format. TCP/WSS gave us ordering+retransmit at
the cost of head-of-line blocking (the last structural ceiling vs the UDP rivals); THIS plane gives the
opposite trade and lets the ALREADY-GATED organs finally earn their keep: nx_nack (retransmit asks),
nx_bwe (rate), nx_jitter_buffer (playout), FEC shards (loss without asks). Runs NATIVE (relay + the
native client #22 + NishiOS); 3rd-party browser tabs stay on the WSS compat lane (their sandbox has no
raw UDP -- adapter, never architecture). Flat memory + i64 API, caller owns all regions. license_tier: ORIGINAL
PACKET (<= DGM_MTU bytes):
[magic 'N''D':2][kind:1][sender:8][seq:4 LE][frag_i:1][frag_n:1][flags:1] = 18B header, payload after.
kinds: media passthrough (0x57 codec / 0x4C 0x41 audio / 0x43 chat) + 0x4E NACK (payload = [cnt:1][seq:4]xcnt).
REASSEMBLY region (caller provides DGM_RX_REGION bytes): 8 sender slots x 4 pending frames x 32 frags.
dependencies 0 imports · 5 importers
imports: none
imported by: nx_dgram_media_gate.nxnx_relay_loadprobe.nxnx_signaling_v2.nxnx_signaling_v2_cascade_gate.nxnx_signaling_v2_gate.nx
structs
| none |
consts
| 16 | const DGM_MTU: i64 = 1200 |
| 17 | const DGM_HDR: i64 = 18 |
| 18 | const DGM_FRAG_CAP: i64 = 1182 // DGM_MTU - DGM_HDR |
| 19 | const DGM_MAX_FRAGS: i64 = 32 // frame cap = 32*1182 = 37824B (a keyframe is ~7KB; 5x headroom) |
| 20 | const DGM_SENDERS: i64 = 8 |
| 21 | const DGM_PENDING: i64 = 4 // in-flight assemblies per sender |
| 22 | const DGM_KIND_NACK: i64 = 0x4E |
| 32 | const DGM_WIN: i64 = 256 |
| 33 | const DGM_PFIX: i64 = 40 // 5 i64 fixed fields per pending |
| 34 | const DGM_PLENS: i64 = 256 // 32 x i64 per-frag lengths |
| 35 | const DGM_PBUF: i64 = 37824 |
| 36 | const DGM_PSTRIDE: i64 = 38120 // DGM_PFIX + DGM_PLENS + DGM_PBUF |
| 37 | const DGM_SSTRIDE: i64 = 152520 // 40 + 4*DGM_PSTRIDE |
| 38 | const DGM_RX_REGION: i64 = 1220224 // 64 + 8*DGM_SSTRIDE |
functions
| 41 | func dgm_mask_test(mp: *i64, d: i64) -> i64 { return (mp[d >> 6] >> (d & 63)) & 1 } |
| 42 | func dgm_mask_set(mp: *i64, d: i64) -> i64 { mp[d >> 6] = mp[d >> 6] | (1 << (d & 63)); return 0 } called by 1: dgm_rx_add |
| 43 | func dgm_mask_shift(mp: *i64, s: i64) -> i64 { // left-shift the whole 256-bit window by s (new frames) called by 1: dgm_rx_add |
| 57 | func dgm_wr_u32(p: *u8, off: i64, v: i64) -> i64 |
| 63 | func dgm_rd_u32(p: *u8, off: i64) -> i64 |
| 68 | func dgm_pack_frame(kind: i64, sender: *u8, seq: i64, frame: *u8, n: i64, out: *u8, out_cap: i64) -> i64 |
| 100 | func dgm_parse_pkt(pkt: *u8, n: i64, info: *i64) -> i64 |
| 120 | func dgm_rx_init(mem: *u8) -> i64 |
| 125 | func dgm_sender_slot(mem: *u8, pkt: *u8, soff: i64) -> i64 called by 1: dgm_rx_add |
| 149 | func dgm_rx_add(mem: *u8, pkt: *u8, n: i64, out: *u8, out_cap: i64, rinfo: *i64) -> i64 |
| 225 | func dgm_rx_gaps(mem: *u8, s: i64, out_seqs: *i64, max: i64) -> i64 |
| 242 | func dgm_pack_nack(sender: *u8, seqs: *i64, cnt: i64, out: *u8, out_cap: i64) -> i64 |
| 256 | func dgm_parse_nack(body: *u8, n: i64, out_seqs: *i64, max: i64) -> i64 |