Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion quest/m1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ moves what remains of them once their claims merge.
- [Drop set](/quest/m1/drop-set.md) - the drop set's track and cursor runs are billed to the cache pool, so fragmenting drops costs what the pool holds; eviction folds final runs or ends the cursor with `TooFarBehind`
- [Media fuzz findings](/quest/m1/fuzz-findings/README.md) - the nightly media fuzz targets run clean: mp4-atom, MKV block, TS step, SPS overflow, and catalog encoder bugs they found are fixed
- [A smaller, safer API than release](/quest/m1/api-audit/README.md) - every surface added since release has a consumer or is gone, overlapping operations are collapsed, names mirror across Rust, JS, and the bindings, and every break says how to migrate
- [moq-webrtc drops the ICE wire counters nothing reads](/quest/m1/ice-wire-counters.md) - the per-packet `Wire` atomics go once #8122 makes the ICE module private
- [Routing guide](/quest/m1/routing-guide.md) - concepts and practical outbound federation setup
- [A reader on a failed copy continues on the held re-offer](/quest/m1/copy-recover.md) - a live reader keeps a group whose copy fails by continuing on the same track's re-offer at the same frame
- [Group errors are cached by kind](/quest/m1/group-error-cache.md) - permanent group errors bind every reader, retryable ones are kept only for a bounded time, and a live SUBSCRIBE_DROP or FETCH answered `Old` no longer caches it for good
Expand Down
19 changes: 0 additions & 19 deletions quest/m1/ice-wire-counters.md

This file was deleted.

28 changes: 2 additions & 26 deletions rs/moq-webrtc/src/ice/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl Agent {

while let Some((data, dst)) = self.outbox.front() {
match self.socket.send_to(data, *dst).await {
Ok(len) => self.inbound.wire.sent(len),
Ok(_) => {}
Err(err) => tracing::warn!(%err, dst = %dst, "send failed"),
}
self.outbox.pop_front();
Expand Down Expand Up @@ -316,7 +316,7 @@ impl Agent {
fn send(&mut self, data: &[u8], dst: SocketAddr) {
let dst = to_family(dst, self.socket_v6);
match self.socket.try_send_to(data, dst) {
Ok(len) => self.inbound.wire.sent(len),
Ok(_) => {}
// Changes can keep coming while the socket stays full, so the backlog is
// bounded like the inbound queue; ICE, SCTP, and RTP recover the loss.
Err(err) if err.kind() == std::io::ErrorKind::WouldBlock && self.outbox.len() < crate::ice::INBOX => {
Expand Down Expand Up @@ -476,30 +476,6 @@ mod tests {
assert_eq!(pick_local(&[v4], "[2001:db8::2]:1".parse().unwrap()), v4);
}

#[tokio::test]
async fn wire_counts_only_accepted_payload() {
let socket = Arc::new(UdpSocket::bind("127.0.0.1:0").await.unwrap());
let peer = UdpSocket::bind("127.0.0.1:0").await.unwrap();
let local = socket.local_addr().unwrap();
let inbound = crate::ice::reader(socket.clone());
let wire = inbound.wire.clone();
let socket = Socket::new(socket, vec![local], inbound).unwrap();
let mut agent = Agent::new(Rtc::builder().build(Instant::now().into_std()), socket).unwrap();

// Until tokio has seen the socket writable, a send waits in the outbox.
agent.socket.writable().await.unwrap();
agent.send(&[42; 73], peer.local_addr().unwrap());
// UDP refuses an oversized datagram, which is never counted as sent.
agent.send(&vec![0; 65_536], peer.local_addr().unwrap());
assert_eq!(wire.stats(), crate::ice::Stats { tx: 73, rx: 0 });

peer.send_to(&[7; 11], local).await.unwrap();
let (data, _) = agent.inbound.packets.recv().await.unwrap();
assert_eq!(data.len(), 11);
drop(agent);
assert_eq!(wire.stats(), crate::ice::Stats { tx: 73, rx: 11 });
}

/// An agent on a fresh socket, which tokio reports unwritable until the runtime
/// polls it, so every send waits in the outbox until the test yields.
fn unpolled() -> Agent {
Expand Down
4 changes: 1 addition & 3 deletions rs/moq-webrtc/src/ice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ mod agent;
mod wire;

pub(crate) use agent::{Agent, Error, Event, canonical};
#[cfg(test)]
pub(crate) use wire::Stats;
pub(crate) use wire::{INBOX, Inbound, Packet, Socket, Wire, reader};
pub(crate) use wire::{INBOX, Inbound, Packet, Socket, reader};
57 changes: 3 additions & 54 deletions rs/moq-webrtc/src/ice/wire.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::net::SocketAddr;
use std::sync::Arc;
use std::sync::atomic::{AtomicU64, Ordering};

use tokio::net::UdpSocket;
use tokio::sync::mpsc;
Expand Down Expand Up @@ -48,69 +47,22 @@ impl Socket {
}
}

/// The datagrams routed to one [`super::Agent`], and the counters they are tallied in.
/// The datagrams routed to one [`super::Agent`].
pub struct Inbound {
/// Ends once every sender is dropped, which ends the agent.
pub packets: mpsc::Receiver<Packet>,
/// Counts `rx` where datagrams are routed, so a full queue's drops count too;
/// the agent counts `tx`.
pub wire: Wire,
}

/// Cumulative UDP payload bytes exchanged with one peer, excluding IP and UDP
/// headers. Clones share counters, which outlive the agent.
#[derive(Clone, Debug, Default)]
pub struct Wire(Arc<Counters>);

#[derive(Debug, Default)]
struct Counters {
tx: AtomicU64,
rx: AtomicU64,
}

/// A snapshot of a [`Wire`]'s counters.
#[cfg(test)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Stats {
/// Bytes the socket accepted, including ICE, DTLS, and retransmissions.
pub tx: u64,
/// Bytes routed to the peer, including those its full queue dropped.
pub rx: u64,
}

impl Wire {
/// Read both counters without consuming them.
#[cfg(test)]
pub fn stats(&self) -> Stats {
Stats {
tx: self.0.tx.load(Ordering::Relaxed),
rx: self.0.rx.load(Ordering::Relaxed),
}
}

/// Count a datagram routed to this peer.
pub fn received(&self, bytes: usize) {
self.0.rx.fetch_add(bytes as u64, Ordering::Relaxed);
}

pub(crate) fn sent(&self, bytes: usize) {
self.0.tx.fetch_add(bytes as u64, Ordering::Relaxed);
}
}

/// Pump every datagram from a socket the caller owns 1:1 into a queue for
/// an agent, until the queue's receiver is dropped.
pub fn reader(socket: Arc<UdpSocket>) -> Inbound {
let (tx, rx) = mpsc::channel(INBOX);
let wire = Wire::default();
let counted = wire.clone();
tokio::spawn(async move {
let mut buf = vec![0u8; 65_535];
loop {
tokio::select! {
res = socket.recv_from(&mut buf) => match res {
Ok((len, src)) => {
counted.received(len);
// Bounded like a socket buffer: drop on full.
if let Err(mpsc::error::TrySendError::Closed(_)) = tx.try_send((buf[..len].to_vec(), canonical(src))) {
break;
Expand All @@ -125,7 +77,7 @@ pub fn reader(socket: Arc<UdpSocket>) -> Inbound {
}
}
});
Inbound { packets: rx, wire }
Inbound { packets: rx }
}

#[cfg(test)]
Expand All @@ -136,10 +88,7 @@ mod tests {
async fn construction_refuses_a_socket_without_advertised_candidates() {
let udp = Arc::new(UdpSocket::bind("127.0.0.1:0").await.unwrap());
let (_, packets) = mpsc::channel(INBOX);
let inbound = Inbound {
packets,
wire: Wire::default(),
};
let inbound = Inbound { packets };
let Err(err) = Socket::new(udp, Vec::new(), inbound) else {
panic!("an unusable socket escaped construction");
};
Expand Down
Loading
Loading