feat(neshub): iroh 1.3, and send each frame as one datagram batch

send_many_datagrams queues a frame's fragments under one lock hold and
one driver wake instead of one per fragment. It also rejects the whole
frame on TooLarge, so a path that shrinks mid-frame no longer leaves half
a frame on the wire for the client to time out. Eviction behaviour is
unchanged. A refused PyroWave frame now keeps its sequence number, since
nothing went out under it. pyro_bench mirrors both ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DatCaptainHorse
2026-10-05 15:57:53 +03:00
co-authored by Claude Opus 5.5
parent 030dcc5a8c
commit 10fdeddc70
6 changed files with 79 additions and 43 deletions
+23 -15
View File
@@ -102,9 +102,11 @@ impl DatagramSender {
/// used, minus the length prefix a datagram does not need.
///
/// A failure is reported but never retried. Retrying a real-time frame means
/// delivering it late, which is the behaviour this whole change removes. A
/// half-sent frame is abandoned where it stands; the receiver times its
/// fragments out and asks for a keyframe.
/// delivering it late, which is the behaviour this whole change removes. The
/// frame goes out whole or not at all: every fragment is queued under one
/// hold of the connection lock, so a path that shrinks mid-frame rejects the
/// frame rather than leaving half of it on the wire for the receiver to time
/// out.
pub fn send_frame(&self, seq: u16, body: &[u8]) -> Result<(), SendFrameError> {
// Ask QUIC what fits right now rather than assuming. The estimate moves
// over a connection's life as path MTU discovery runs, and it can shrink
@@ -142,18 +144,24 @@ impl DatagramSender {
buf.extend_from_slice(&body[start..end]);
}
for index in 0..total {
let start = index * payload_size;
let end = (start + payload_size).min(body.len());
let datagram = buf.split_to(DGRAM_HDR_LEN + (end - start)).freeze();
// Deliberately not `send_datagram_wait`: that waits for buffer space
// under congestion, which prioritises old datagrams over new ones.
// For live media the opposite is right — drop the backlog, send the
// frame that is actually current.
self.conn
.send_datagram(datagram)
.map_err(SendFrameError::Quic)?;
}
let datagrams: Vec<Bytes> = (0..total)
.map(|index| {
let start = index * payload_size;
let end = (start + payload_size).min(body.len());
buf.split_to(DGRAM_HDR_LEN + (end - start)).freeze()
})
.collect();
// One call for the whole frame: one lock hold and one driver wake rather
// than one per fragment, and a `TooLarge` rejects every fragment instead
// of the ones after the path shrank. Like `send_datagram`, it evicts the
// oldest queued datagrams to make room -- deliberately not the waiting
// kind, which prioritises old datagrams over new ones. For live media
// the opposite is right: drop the backlog, send the frame that is
// actually current.
self.conn
.send_many_datagrams(&datagrams)
.map_err(SendFrameError::Quic)?;
Ok(())
}
+17 -10
View File
@@ -71,16 +71,23 @@ impl PyroSender {
// Taking the `Vec` is free, and each datagram is a slice of it.
let buf = Bytes::from(datagrams.buf);
let mut at = 0;
for len in datagrams.lens {
debug_assert!(len >= PYRO_DGRAM_HDR_LEN);
let datagram = buf.slice(at..at + len);
at += len;
// Not `send_datagram_wait`, for the reason `dgram::send_frame`
// gives; the guard above is what keeps this from evicting.
if let Err(e) = self.conn.send_datagram(datagram) {
debug!("{label}: PyroWave frame {} cut short: {e}", frame.frame);
break;
}
let batch: Vec<Bytes> = datagrams
.lens
.iter()
.map(|&len| {
debug_assert!(len >= PYRO_DGRAM_HDR_LEN);
let datagram = buf.slice(at..at + len);
at += len;
datagram
})
.collect();
// Evicting, for the reason `dgram::send_frame` gives; the guard above is
// what keeps it from evicting anything. The batch is queued whole or
// not at all, so a refused frame put nothing on the wire and its
// sequence number goes to the next frame.
if let Err(e) = self.conn.send_many_datagrams(&batch) {
debug!("{label}: PyroWave frame {} not sent: {e}", frame.frame);
return;
}
self.seq = self.seq.wrapping_add(1);
}