Sens-O-Matic / RLC code
Sens-O-Matic, sliding-window RLC code: SensOMaticRlcSender + SensOMaticRlcReceiver
The second erasure code of the Sens-O-Matic
protocol. Where the block Reed-Solomon code groups items into blocks of k
source + r parity shards, the sliding-window linear code
(rlc_fec
) ships items as source symbols interleaved with
repair symbols and recovers a lost symbol from the next repair -
rather than waiting for the rest of a block, which is the lower-latency
recovery shape on a streaming workload. The two codes share the GF(2^8)
field and the committed SIMD multiply ladder; this one lives in
sens_rlc
, types SensOMaticRlcSender /
SensOMaticRlcReceiver.
The coefficients are a published table of constants, not values either end generates. A repair multiplies the newest symbol in its window by the first tap, the one before it by the second, and so on, with one tap for every position the widest window can hold. The density threshold says what fraction of the window carries a coefficient, spread across its whole depth rather than filling the newest end: at full density every position is in, at the lowest one position in sixteen, and at every depth either way. (Reading the density as a reach instead would cap a repair at the first sixteen symbols however wide the window, which makes the controller’s answer to a long burst - widening the window - do nothing.)
A fixed generator is enough because the code is convolutional: successive repairs cover windows that have shifted, so their equations differ although the generator does not. Each repair names its generator in the high nibble of its density byte, so a decoder reads the choice off the stream rather than from its own configuration, and a repair naming a generator this build does not read is counted and dropped rather than decoded with the wrong coefficients.
It adds two things the block-RS code does not have: an adaptive controller and optional TLS 1.3.
Adaptive coding from the control plane
A sensing controller (RlcController
) retunes the live coding
on every feedback frame from what the receiver measures: the window size
(how far back a repair reaches - sized to the burst length), the repair
cadence (code rate - sized to the loss rate), the coefficient density, and
whether to code at all (disable-on-clean reclaims the parity overhead on a
provably-clean link). Protection escalates immediately and relaxes only
after a sustained quiet run, so a loss spike is covered the instant it
appears.
Packet-pair rate control for a variable path
On a bufferless internet path the usable rate sits below the raw link rate
at a sharp cliff, and every loss-derived rate signal (goodput, NAKs, a
congestion classifier) is confounded - random loss looks identical to a
cliff overshoot. The sender’s with_adaptive_push mode measures the path
capacity from packet-pair dispersion: the bottleneck spaces two
back-to-back packets by its per-packet transmission time regardless of how
many other packets it drops, so the gap measures capacity independently
of loss. The sender cruises just under the measured capacity and lets the
FEC cover the residual loss, rather than probing into the cliff.
One window per peer
The connection id identifies the session, and the receiver keeps a decode window per id: its own delivery frontier, loss estimate, gap tracking and path validation. A node receiving from several peers at once - a replication mesh, where every member ships to every other - decodes each stream independently, so nothing one peer sends can stall or displace another’s.
That is also what makes a restart ordinary rather than special. A restarted process draws a new id, so it opens a new window; the dead session’s window simply goes quiet. There is no replacement step, because a session is never rebound to a different id.
poll_from() returns (connection_id, item) and is the call a
multi-peer node wants. poll() is the same drain with the tag
dropped. Ordering is guaranteed within a connection id; nothing orders
one peer against another, since they are independent streams.
live_sessions() lists the ids with a window.
Independence holds below the decode windows as well. A peer that leaves makes the receiver’s control sends draw an ICMP port-unreachable, which on Windows displaces a datagram belonging to whichever peer was next; the receiver disables that at bind, so one peer’s departure costs the others nothing. See a peer that leaves, on Windows .
Where a window starts
Source ids count up from zero (wire format, section 4.1), so a window that holds id 0, received or recovered from repairs, starts there, and so does one that receives a repair whose window starts at 0, since the sender built it from a symbol it still holds. A window that has seen neither cannot tell a stream whose first datagrams were lost from one it joined partway through, as a receiver restarted under a live sender does. The first has to wait for its lost head; the second can never have the ids the sender released when the previous receiver acknowledged them.
So the window asks the sender. Until it knows, it delivers nothing and sends no ACK, so the sender releases nothing, and each NAK round names id 0, then the ids just below the lowest id seen, then that lowest id itself, last: the canary. The sender resends a NAK’d id only while it still holds it and has not sent it within 1.2 round trips (at least 18 ms, and 240 ms before its first round-trip sample), and it serves a NAK in order. Every id below the canary was sent before it, so by the time the canary comes back, each of them the sender holds has come back ahead of it.
- Id 0 back starts the window at 0.
- A round in which the canary came back and nothing below it did is empty, and two empty rounds in a row start the window at the canary.
- Ids that came back move the lowest down. When the whole range a round named came back, the next round reaches twice as deep, up to the 55 ids one NAK holds beside id 0 and the canary.
Nothing in the probe waits on a clock: a sender slow to resend delays
the start and cannot move it. A lost head costs the sender’s resend
delay, which recovering it costs anyway, and a join costs two resend
intervals. The probe is ordinary NAKs, so the wire format is unchanged
and a sender needs nothing new to answer it. At a code switch the
unified layer names the start outright with skip_to.
Admitting a peer
The first id a receiver sees is admitted outright: there is no
established session for a forgery to disturb, and that is the ordinary
point-to-point case. Every id after that is challenged. A datagram
carrying an unfamiliar id arms a PATH_CHALLENGE with that id and a
fresh nonce, and the window opens only when the nonce returns from the
address it was sent to. The provoking datagram is not delivered
meanwhile, and an unanswered challenge is retired after
CHALLENGE_TIMEOUT. A pending challenge is resent at most once per
ADMISSION_RESEND_INTERVAL (50 ms), and the unified sender’s reader
thread echoes challenges at wire latency, so admission completes in
one round trip regardless of how often the sender services its
socket.
Admission is gated on the answer rather than on the id alone because the two are indistinguishable from a datagram: without the challenge, anyone able to guess the 4-tuple could make a receiver allocate a decode window with a single packet. What the answer proves is return-routability - the responder echoes the challenge without inspecting the id - which is what an off-path attacker cannot supply.
A frame that names no window goes nowhere. Only DATA and REPAIR carry a
connection id, and a PATH_RESPONSE carries the id of the window it
answers, which is where it is routed. Anything else - an unknown type
byte, a TLS sender’s handshake frames arriving at a cleartext receiver,
an answer for an id that holds no window and is under no admission
challenge - is counted in unattributed_frames() with its type byte and
reaches no session, so no window’s address moves on the word of a frame
that could have come from anyone. A DATA or REPAIR frame too short for
its header is counted in malformed_frames() by the window it named.
There is no ceiling on windows unless one is declared.
with_session_ceiling(max) bounds the live windows and the candidates
under challenge, and session_refusals() counts every peer turned away
by it, so a refused peer is never indistinguishable from one that never
sent.
The datagrams a peer sends during its challenge round trip are not delivered, so an admitted window finds its start like any other (where a window starts ): a fresh sender still holds its head and resends it, and one a restarted receiver admits partway through its stream is resumed where that stream stands.
| Call | Answers |
|---|---|
take_session_changed() | whether a window was admitted since the last call; edge-triggered |
session_adoption_counts() | (admitted, challenges_that_went_unanswered); a refused forgery raises the second without the first |
session_admissions_for(cid) | the address that id answered from, or None if it holds no window |
peer_of(cid) / live_sessions() | where one peer is bound, and which ids are live |
session_refusals() | peers turned away by a declared ceiling, or by TLS already holding its one handshake |
sens_rlc::socket_buffer_refusals() | a free function: sockets whose kernel refused the 4 MiB send or receive buffer, summed over the process; the socket keeps the kernel default, where a burst can overflow the queue and read as link loss (FreeBSD’s default kern.ipc.maxsockbuf refuses it) |
session_frontier(cid) | one window’s (delivered_through, highest_seen); highest_seen ahead of delivered_through is a window holding frames behind a gap, or one still finding where its stream starts, which holds delivered_through at 0 |
session_control(cid) | one window’s (naks_sent, acks_sent, sends_skipped, peer_validated); sends_skipped counts control frames dropped for a missing peer address or an exhausted anti-amplification budget |
path_validations() / path_validation_failures() | address validations completed and challenges that timed out, summed over every session |
session_service_errors() | sessions that could not be serviced; each is a peer left without the feedback that tick would have sent |
unattributed_frames() | (frames, last_type_byte) for frames that named no window - no connection id and not a PATH_RESPONSE, or a PATH_RESPONSE for an id with no window that answered no admission challenge; none reached a session or moved an address; the byte is 0 for an empty datagram |
malformed_frames() | DATA / REPAIR frames too short for their header, summed over every window; each was dropped without a decode |
A session’s control-plane send failure stays with that session: every window is serviced each poll, and a tick’s delivered items reach the caller whether or not some peer’s feedback send failed. The failure is counted and named once on stderr rather than discarded, since from the peer’s side an undelivered NAK is indistinguishable from a receiver that stopped asking.
An ACK leaves immediately whenever the delivery frontier advanced; an unmoved frontier re-acks at most once per 10 ms. The cumulative frontier plus the SACK bitmap carries the full receive state, so each ACK supersedes every prior one.
A loss the coding window cannot cover is repaired by retransmission,
and either side can start it: the receiver NAKs a hole once it has been
missing longer than its jitter-scaled reorder grace, and the sender
resends its lowest unacked symbols when the cumulative ACK stops
advancing, or at the end of a stream. The sender’s retransmits()
counts the symbols it sent again, whichever asked.
take_session_changed(), session_adoption_counts() and
poll_from() are also on UnifiedSensReceiver, whose
multi-peer contract
stops at delivery.
Optional TLS 1.3
with_tls_client / with_tls_server wrap the transport in a rustls TLS
1.3 handshake (driven over the transport’s own reliable Crypto-frame
exchange) and seal every datagram with the 1-RTT key. FEC stays over the
cleartext; the AEAD is per-packet with no extra round trips, so the
encrypted path’s latency matches the plaintext path’s to within
microseconds. This is what the head-to-head calls rlctls.
A receiver serving several TLS senders at once - each with its own
handshake, keys and packet numbers - is the unified endpoint’s
listen_tls
.
Performance
Measured on real wire between separate OS processes (an Ubuntu 24.04 and a
FreeBSD 15.0 host) and over a real ~22 ms internet path - full matrix,
confidence intervals, and methodology in
TRANSPORT_COMPARISON.md
.
On the clean LAN the RLC code moves ~890 Mbit/s (FEC parity is the gap to
the raw stream bridges). Under loss it holds where the TCP bridges collapse:
~870 Mbit/s at 3% LAN loss and ~550 at 8%, versus ~115 and ~10 for the TCP
bridges, with a ~30 ms p99 round-trip against their 204-255 ms (a lost TCP
segment head-of-line-blocks the whole stream; the RLC code recovers in-band).
Over the real internet it holds ~260 Mbit/s through 3-8% loss where
TcpTlsBridge collapses to single digits, statistically tied with QUIC at
0-5% loss.
Verify
use std::time::Duration;
use subetha_cxc::sens_rlc::{SensOMaticRlcReceiver, SensOMaticRlcSender};
const SYMBOL_LEN: usize = 64;
// Receiver on a loopback port, 15% injected loss so the RLC repairs engage.
let mut recv = SensOMaticRlcReceiver::bind("127.0.0.1:0", SYMBOL_LEN)?
.with_debug_loss(15, 7);
let addr = recv.local_addr()?;
let rx = std::thread::spawn(move || {
let mut got = Vec::new();
while got.len() < 1000 {
for item in recv.poll().unwrap() {
got.push(u64::from_le_bytes(item[..8].try_into().unwrap()));
}
}
got
});
// Sender: window 16, one repair per 2 source symbols, dense coefficients.
let mut send = SensOMaticRlcSender::bind("127.0.0.1:0", addr, 16, 2, 15, SYMBOL_LEN)?;
for i in 0..1000u64 {
send.send_item(&i.to_le_bytes())?;
}
send.drain_until_acked(1000, Duration::from_secs(15))?;
assert_eq!(rx.join().unwrap(), (0..1000).collect::<Vec<_>>());
# Ok::<(), std::io::Error>(())The full transport (TLS, packet-pair rate control, migration) runs in
rlc_transport_e2e
and the cross-host head-to-head in
bridge_lan
(--transport sens --fec rlc --tls).
References
- Sens-O-Matic / block Reed-Solomon code
- the
MDS,
std-only sibling code of the same protocol. QuicBridge- the ARQ-based encrypted transport it is measured against.