nx_quic_relay.nx source
↩ module page · 29 lines · 1524 B
1// nx_quic_relay.nx -- RUNG 8b of the sovereign QUIC transport: the relay's datagram FAN-OUT. The family
2// video room is a relay: a DATAGRAM (R1) arriving from one peer is re-framed and broadcast to every OTHER
3// peer (never echoed to the sender). The relay forwards the payload OPAQUELY -- it never inspects the FEC
4// (R8a), so each receiving peer recovers its own losses end-to-end. This is the server-side core of the
5// live wire-in, gated in isolation (no sockets, no live call). Composes R1's DATAGRAM frame. No float.
6// license_tier: ORIGINAL
7import "nx_quic_wire.nx"
8
9// broadcast a datagram payload from peer `from_idx` to all other peers (0..n_peers). For each recipient,
10// a fresh DATAGRAM frame is appended to its output buffer (out_bufs is flat: peer i owns [i*buf_cap ..]),
11// advancing out_lens[i]. Returns the number of peers delivered to. The sender is skipped (no echo).
12func quic_relay_broadcast(n_peers: i64, from_idx: i64, payload: *u8, plen: i64, out_bufs: *u8, buf_cap: i64, out_lens: *i64) -> i64 {
13 var delivered: i64 = 0
14 var i: i64 = 0
15 while i < n_peers {
16 if i != from_idx {
17 if out_lens[i] + plen + 9 <= buf_cap {
18 let dst: *u8 = (out_bufs as i64 + i * buf_cap + out_lens[i]) as *u8
19 let fl: i64 = quic_datagram_encode(dst, payload, plen)
20 out_lens[i] = out_lens[i] + fl
21 delivered = delivered + 1
22 }
23 }
24 i = i + 1
25 }
26 return delivered
27}
28
29func main() -> i64 { return 0 }