code wiki / (root) / nx_dgram_media.nx

nx_dgram_media.nx

buildroot/runtime/nx_dgram_media.nx

12064 B263 linesdepth 0pulls 0 transitivereach 5 importersview sourcekind library
docsdependenciesstructsconstsfunctions

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

nx_dgram_media.nx nx_dgram_media_gate.nx nx_relay_loadprobe.nx nx_signaling_v2.nx nx_signaling_v2_cascade_gate.nx nx_signaling_v2_gate.nx

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

16const DGM_MTU: i64 = 1200
17const DGM_HDR: i64 = 18
18const DGM_FRAG_CAP: i64 = 1182 // DGM_MTU - DGM_HDR
19const DGM_MAX_FRAGS: i64 = 32 // frame cap = 32*1182 = 37824B (a keyframe is ~7KB; 5x headroom)
20const DGM_SENDERS: i64 = 8
21const DGM_PENDING: i64 = 4 // in-flight assemblies per sender
22const DGM_KIND_NACK: i64 = 0x4E
32const DGM_WIN: i64 = 256
33const DGM_PFIX: i64 = 40 // 5 i64 fixed fields per pending
34const DGM_PLENS: i64 = 256 // 32 x i64 per-frag lengths
35const DGM_PBUF: i64 = 37824
36const DGM_PSTRIDE: i64 = 38120 // DGM_PFIX + DGM_PLENS + DGM_PBUF
37const DGM_SSTRIDE: i64 = 152520 // 40 + 4*DGM_PSTRIDE
38const DGM_RX_REGION: i64 = 1220224 // 64 + 8*DGM_SSTRIDE

functions

41func dgm_mask_test(mp: *i64, d: i64) -> i64 { return (mp[d >> 6] >> (d & 63)) & 1 }
42func 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
43func 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
57func dgm_wr_u32(p: *u8, off: i64, v: i64) -> i64
63func dgm_rd_u32(p: *u8, off: i64) -> i64
68func dgm_pack_frame(kind: i64, sender: *u8, seq: i64, frame: *u8, n: i64, out: *u8, out_cap: i64) -> i64
100func dgm_parse_pkt(pkt: *u8, n: i64, info: *i64) -> i64
120func dgm_rx_init(mem: *u8) -> i64
125func dgm_sender_slot(mem: *u8, pkt: *u8, soff: i64) -> i64
called by 1: dgm_rx_add
149func dgm_rx_add(mem: *u8, pkt: *u8, n: i64, out: *u8, out_cap: i64, rinfo: *i64) -> i64
225func dgm_rx_gaps(mem: *u8, s: i64, out_seqs: *i64, max: i64) -> i64
called by 1: main calls 1: dgm_mask_test
242func dgm_pack_nack(sender: *u8, seqs: *i64, cnt: i64, out: *u8, out_cap: i64) -> i64
called by 1: main calls 2: dgm_wr_u32dgm_pack_frame
256func dgm_parse_nack(body: *u8, n: i64, out_seqs: *i64, max: i64) -> i64
called by 1: main calls 1: dgm_rd_u32