Skip to content
Draft
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
26 changes: 19 additions & 7 deletions neqo-http3/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1694,9 +1694,25 @@ impl Http3Connection {
send_group_id: SendGroupId,
send_order: SendOrder,
) -> Res<DatagramQueueOutcome> {
// QUIC DATAGRAM needs SETTINGS_H3_DATAGRAM = 1 sent and received (RFC 9297, Section 2.1.1).
let quic_datagrams = conn.remote_datagram_size() > 0
&& matches!(
&self.settings_state,
// Not `ZeroRtt`: no extended CONNECT session is negotiated from 0-RTT settings.
Http3RemoteSettingsState::Received(s) if s.get(HSettingType::EnableH3Datagram) == 1
)
&& self.local_params.get_http3_datagram();
self.validate_extended_connect_session(session_id)?
.borrow_mut()
.send_datagram(conn, buf, id, now, send_group_id, send_order)
.send_datagram(
conn,
buf,
id,
now,
send_group_id,
send_order,
quic_datagrams,
)
}

pub(crate) fn webtransport_session_set_max_buffered_datagrams(
Expand Down Expand Up @@ -1812,12 +1828,8 @@ impl Http3Connection {
HSettingType::MaxTableCapacity,
HSettingType::BlockedStreams,
HSettingType::EnableConnect,
// [RFC 9297, Section 2.1.1](https://www.rfc-editor.org/rfc/rfc9297.html#section-2.1.1)
// requires a client that stored SETTINGS_H3_DATAGRAM with its
// 0-RTT state to terminate the connection with H3_SETTINGS_ERROR
// if the server's new value is smaller than the stored one.
// [draft-ietf-webtrans-http3, Section 3.2](https://datatracker.ietf.org/doc/html/draft-ietf-webtrans-http3#section-3.2)
// states the same rule for the WebTransport setting.
// A client rejects a lower value than stored for 0-RTT with H3_SETTINGS_ERROR
// (RFC 9297, Section 2.1.1; draft-ietf-webtrans-http3, Section 3.2).
HSettingType::EnableWebTransport,
HSettingType::EnableH3Datagram,
] {
Expand Down
13 changes: 9 additions & 4 deletions neqo-http3/src/features/extended_connect/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ impl Session {
self.control_stream_send.send_data(conn, buf, now)
}

/// Send a datagram, as a QUIC datagram or, when the peer offers no QUIC
/// datagram support, an HTTP DATAGRAM Capsule (connect-udp only).
/// Send a datagram, as a QUIC datagram or, when `quic_datagrams` is false
/// (QUIC DATAGRAM not negotiated), an HTTP DATAGRAM Capsule (connect-udp only).
///
/// # Errors
///
Expand All @@ -472,6 +472,10 @@ impl Session {
///
/// On success, returns the queue's backpressure signal (see
/// [`DatagramQueueOutcome`]) so the caller can throttle further writes.
#[expect(
clippy::too_many_arguments,
reason = "only the caller knows whether QUIC DATAGRAM is negotiated"
)]
pub(crate) fn send_datagram<I: Into<DatagramTracking>>(
&mut self,
conn: &mut Connection,
Expand All @@ -480,22 +484,23 @@ impl Session {
now: Instant,
send_group_id: SendGroupId,
send_order: SendOrder,
quic_datagrams: bool,
) -> Res<DatagramQueueOutcome> {
trace!("[{self}] send_datagram state={:?}", self.state);
if self.state != State::Active {
debug!("[{self}]: cannot send datagram in {:?} state.", self.state);
return Err(Error::Unavailable);
}

if conn.remote_datagram_size() == 0 {
if !quic_datagrams {
if !self.protocol.datagram_capsule_support() {
// WebTransport only negotiates with a peer that supports QUIC
// DATAGRAM, and connect-udp always has the Capsule fallback.
debug_assert!(false, "no datagram path to the peer");
debug!("[{self}]: peer supports neither QUIC DATAGRAM nor the Capsule fallback");
return Err(Error::Transport(neqo_transport::Error::NotAvailable));
}
trace!("[{self}] remote_datagram_size is 0, trying HTTP DATAGRAM Capsule");
trace!("[{self}] QUIC DATAGRAM not negotiated, trying HTTP DATAGRAM Capsule");
// The Capsule path errors when the control stream's flow-control
// window is exhausted, then emits a resume event once the stream is
// writable again (see `stream_writable`).
Expand Down
60 changes: 53 additions & 7 deletions neqo-http3/tests/connect_udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,24 +775,36 @@ fn establish_capsule_session(
neqo_http3::StreamId,
ServerSession,
) {
fixture_init();
neqo_common::log::init(None);

// `datagram_size(0)` forces the HTTP DATAGRAM Capsule path.
let mut proxy_params = ConnectionParameters::default().datagram_size(0);
if let Some(v) = proxy_max_stream_data {
proxy_params = proxy_params.max_stream_data(StreamDataLimit::BiDiRemote, v);
}
let mut client = http3_client_with_params(
establish_session_with_params(
Http3Parameters::default()
.connect(true)
.connection_parameters(ConnectionParameters::default().datagram_size(0)),
);
let mut proxy = http3_server_with_params(
Http3Parameters::default()
.connect(true)
.connection_parameters(proxy_params),
);
)
}

/// Establish a connect-udp session between a client and a proxy built from the given parameters.
fn establish_session_with_params(
client_params: Http3Parameters,
proxy_params: Http3Parameters,
) -> (
Http3Client,
Http3Server,
neqo_http3::StreamId,
ServerSession,
) {
fixture_init();
neqo_common::log::init(None);

let mut client = http3_client_with_params(client_params);
let mut proxy = http3_server_with_params(proxy_params);

let out = test_fixture::connect_peers(&mut client, &mut proxy);
if let Some(dgram) = out
Expand Down Expand Up @@ -992,3 +1004,37 @@ fn connect_udp_session_rejected_by_webtransport_datagram_setters() {
Err(Error::InvalidStreamId)
);
}

/// Without `SETTINGS_H3_DATAGRAM = 1` on both sides, datagrams use capsules in both directions.
#[test]
fn datagram_capsule_without_h3_datagram_setting() {
let (mut client, mut proxy, session_id, proxy_session) = establish_session_with_params(
Http3Parameters::default().connect(true),
Http3Parameters::default()
.connect(true)
.http3_datagram(false),
);

assert_eq!(
client.connect_udp_send_datagram(session_id, PING, None, now()),
Ok(DatagramQueueOutcome::Ok)
);
assert_eq!(
proxy_session.send_datagram(PONG, None, now()),
Ok(DatagramQueueOutcome::Ok)
);
exchange_packets(&mut client, &mut proxy, false, None);

assert!(proxy.events().any(|e| matches!(
e,
Http3ServerEvent::ConnectUdp(ServerEvent::Datagram { session, datagram })
if session.stream_id() == session_id && &datagram == PING
)));
assert!(client.events().any(|e| matches!(
e,
Http3ClientEvent::ConnectUdp(ConnectUdpEvent::Datagram { session_id: id, datagram })
if id == session_id && &datagram == PONG
)));
assert_eq!(client.transport_stats().frame_tx.datagram, 0);
assert_eq!(client.transport_stats().frame_rx.datagram, 0);
}
Loading