code wiki / (root) / nx_quic_fec.nx

nx_quic_fec.nx source

↩ module page · 43 lines · 2153 B

1// nx_quic_fec.nx -- RUNG 8a of the sovereign QUIC transport: forward error correction over DATAGRAM 2// frames. THIS is the resilience exceed: a block of N source datagrams + a parity datagram lets the 3// receiver RECONSTRUCT a lost source packet with ZERO retransmit -- so on the lossy Belarus<->Texas link, 4// a dropped video packet is recovered in-place instead of stalling the TCP/ARQ way (the measured 16-vs-118 5// frozen-frames win). Systematic XOR parity (recovers 1 loss per block; interleave M blocks -> a burst of 6// M is recovered, 1 per block). Composes with R1's DATAGRAM frame. No float. license_tier: ORIGINAL 7import "nx_quic_wire.nx" 8 9// encode: parity[len] = XOR of the N source packets (each `len` bytes), laid out flat in source[N*len]. 10func quic_fec_encode(source: *u8, n: i64, len: i64, parity: *u8) -> i64 { 11 var j: i64 = 0; while j < len { parity[j] = 0 as u8; j = j + 1 } 12 var i: i64 = 0 13 while i < n { 14 j = 0 15 while j < len { parity[j] = ((parity[j] as i64) ^ (source[i*len+j] as i64)) as u8; j = j + 1 } 16 i = i + 1 17 } 18 return 0 19} 20 21// recover the single missing source packet. present[i]=1 if source i arrived; parity_present=1 if the 22// parity arrived. Writes the recovered packet to out[len] and returns its index, or -1 if not exactly one 23// source is missing (XOR parity recovers exactly one erasure per block). 24func quic_fec_recover_one(source: *u8, present: *i64, n: i64, len: i64, parity: *u8, parity_present: i64, out: *u8) -> i64 { 25 if parity_present == 0 { return 0 - 1 } 26 var missing: i64 = 0 - 1; var miss_count: i64 = 0 27 var i: i64 = 0 28 while i < n { if present[i] == 0 { missing = i; miss_count = miss_count + 1 } i = i + 1 } 29 if miss_count != 1 { return 0 - 1 } 30 // out = parity XOR (all present sources) == the missing source 31 var j: i64 = 0; while j < len { out[j] = parity[j]; j = j + 1 } 32 i = 0 33 while i < n { 34 if present[i] == 1 { 35 j = 0 36 while j < len { out[j] = ((out[j] as i64) ^ (source[i*len+j] as i64)) as u8; j = j + 1 } 37 } 38 i = i + 1 39 } 40 return missing 41} 42 43func main() -> i64 { return 0 }