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
11 changes: 4 additions & 7 deletions neqo-http3/src/conn_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use std::cmp::min;

use neqo_common::qwarn;
use neqo_common::qdebug;
use neqo_qpack as qpack;
use neqo_transport::ConnectionParameters;

Expand Down Expand Up @@ -145,13 +145,12 @@

#[must_use]
pub fn get_http3_datagram(&self) -> bool {
if self.http3_datagram && self.conn_params.get_datagram_size() == 0 {

Check warning on line 148 in neqo-http3/src/conn_params.rs

View workflow job for this annotation

GitHub Actions / Find mutants

Missed mutant

replace == with != in Http3Parameters::get_http3_datagram

Check warning on line 148 in neqo-http3/src/conn_params.rs

View workflow job for this annotation

GitHub Actions / Find mutants

Missed mutant

replace && with || in Http3Parameters::get_http3_datagram
qwarn!(
"HTTP/3 setting SETTINGS_HTTP3_DATAGRAM is enabled but QUIC transport parameter max_datagram_frame_size is 0."
qdebug!(
"HTTP/3 setting SETTINGS_H3_DATAGRAM is enabled but QUIC transport parameter max_datagram_frame_size is 0. Datagrams will be sent via HTTP DATAGRAM Capsules."
);
debug_assert!(false);
}
self.http3_datagram

Check warning on line 153 in neqo-http3/src/conn_params.rs

View workflow job for this annotation

GitHub Actions / Find mutants

Missed mutant

replace Http3Parameters::get_http3_datagram -> bool with true
}
}

Expand All @@ -163,9 +162,7 @@
use crate::Http3Parameters;

#[test]
#[cfg(debug_assertions)]
#[should_panic(expected = "assertion failed: false")]
fn get_http3_datagram_debug_panic_on_mismatch() {
fn http3_datagram_with_capsules_only() {
let params = Http3Parameters::default()
.connection_parameters(ConnectionParameters::default().datagram_size(0))
.http3_datagram(true);
Expand Down
24 changes: 18 additions & 6 deletions neqo-http3/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,13 +866,17 @@
]
}
Some(ConnectType::Extended(protocol)) => {
vec![
let mut h = vec![
Header::new(":method", request.method),
Header::new(":scheme", request.target.scheme()),
Header::new(":authority", request.target.authority()),
Header::new(":path", request.target.path()),
Header::new(":protocol", protocol.to_string()),
]
];
if protocol == ExtendedConnectType::ConnectUdp {
h.push(Header::new("capsule-protocol", "?1"));
}
h
}
};

Expand Down Expand Up @@ -1331,9 +1335,14 @@
Ok(())
}
(Some(s), Some(_r), SessionAcceptAction::Accept) => {
let mut response_headers = vec![Header::new(":status", "200")];
if connect_type == ExtendedConnectType::ConnectUdp {

Check warning on line 1339 in neqo-http3/src/connection.rs

View workflow job for this annotation

GitHub Actions / Find mutants

Missed mutant

replace == with != in Http3Connection::extended_connect_session_accept
response_headers.push(Header::new("capsule-protocol", "?1"));
}

if s.http_stream()
.ok_or(Error::InvalidStreamId)?
.send_headers(&[Header::new(":status", "200")], conn)
.send_headers(&response_headers, conn)
.is_ok()
{
let extended_conn = Rc::new(RefCell::new(
Expand Down Expand Up @@ -1536,8 +1545,9 @@
conn: &mut Connection,
buf: &[u8],
id: I,
now: Instant,
) -> Res<()> {
self.extended_connect_send_datagram(session_id, conn, buf, id)
self.extended_connect_send_datagram(session_id, conn, buf, id, now)
}

pub fn connect_udp_send_datagram<I: Into<DatagramTracking>>(
Expand All @@ -1546,8 +1556,9 @@
conn: &mut Connection,
buf: &[u8],
id: I,
now: Instant,
) -> Res<()> {
self.extended_connect_send_datagram(session_id, conn, buf, id)
self.extended_connect_send_datagram(session_id, conn, buf, id, now)
}

fn extended_connect_send_datagram<I: Into<DatagramTracking>>(
Expand All @@ -1556,14 +1567,15 @@
conn: &mut Connection,
buf: &[u8],
id: I,
now: Instant,
) -> Res<()> {
self.recv_streams
.get_mut(&session_id)
.ok_or(Error::InvalidStreamId)?
.extended_connect_session()
.ok_or(Error::InvalidStreamId)?
.borrow_mut()
.send_datagram(conn, buf, id)
.send_datagram(conn, buf, id, now)
}

/// If the control stream has received frames `MaxPushId`, `Goaway`, `PriorityUpdateRequest` or
Expand Down
6 changes: 4 additions & 2 deletions neqo-http3/src/connection_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,10 +830,11 @@ impl Http3Client {
session_id: StreamId,
buf: &[u8],
id: I,
now: Instant,
) -> Res<()> {
qtrace!("webtransport_send_datagram session:{session_id:?}");
self.base_handler
.webtransport_send_datagram(session_id, &mut self.conn, buf, id)
.webtransport_send_datagram(session_id, &mut self.conn, buf, id, now)
}

/// Send `ConnectUdp` datagram.
Expand All @@ -848,10 +849,11 @@ impl Http3Client {
session_id: StreamId,
buf: &[u8],
id: I,
now: Instant,
) -> Res<()> {
qtrace!("connect_udp_send_datagram session:{session_id:?}");
self.base_handler
.connect_udp_send_datagram(session_id, &mut self.conn, buf, id)
.connect_udp_send_datagram(session_id, &mut self.conn, buf, id, now)
}

/// Returns the current max size of a datagram that can fit into a packet.
Expand Down
6 changes: 4 additions & 2 deletions neqo-http3/src/connection_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,11 @@ impl Http3ServerHandler {
session_id: StreamId,
buf: &[u8],
id: I,
now: Instant,
) -> Res<()> {
self.needs_processing = true;
self.base_handler
.webtransport_send_datagram(session_id, conn, buf, id)
.webtransport_send_datagram(session_id, conn, buf, id, now)
}

pub fn connect_udp_send_datagram<I: Into<DatagramTracking>>(
Expand All @@ -272,10 +273,11 @@ impl Http3ServerHandler {
session_id: StreamId,
buf: &[u8],
id: I,
now: Instant,
) -> Res<()> {
self.needs_processing = true;
self.base_handler
.connect_udp_send_datagram(session_id, conn, buf, id)
.connect_udp_send_datagram(session_id, conn, buf, id, now)
}

/// Process HTTTP3 layer.
Expand Down
98 changes: 71 additions & 27 deletions neqo-http3/src/features/extended_connect/connect_udp_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
time::Instant,
};

use neqo_common::{Bytes, Decoder, Encoder};
use neqo_common::{Bytes, Decoder, Encoder, qdebug, qtrace};
use neqo_transport::{Connection, StreamId};

use crate::{
Error, RecvStream, Res,
Error, RecvStream, Res, SendStream,
features::extended_connect::{
CloseReason, ExtendedConnectEvents, ExtendedConnectType, Protocol,
session::{DgramContextIdError, State},
},
frames::{ConnectUdpFrame, FrameReader, StreamReaderRecvStreamWrapper},
frames::{FrameReader, StreamReaderRecvStreamWrapper, capsule::Capsule},
};

#[derive(Debug)]
Expand Down Expand Up @@ -55,32 +55,45 @@
control_stream_recv: &mut Box<dyn RecvStream>,
now: Instant,
) -> Res<Option<State>> {
let (f, fin) = self
.frame_reader
.receive::<ConnectUdpFrame>(
&mut StreamReaderRecvStreamWrapper::new(conn, control_stream_recv),
now,
)
.map_err(|_| Error::HttpGeneralProtocolStream)?;

if let Some(f) = f {
// TODO: Implement HTTP Datagram <https://github.com/mozilla/neqo/issues/2843>.
match f {}
}
loop {
let (capsule, fin) = self
.frame_reader
.receive::<Capsule>(
&mut StreamReaderRecvStreamWrapper::new(conn, control_stream_recv),
now,
)
.map_err(|_| Error::HttpGeneralProtocolStream)?;

let capsule_is_some = capsule.is_some();

if fin {
events.session_end(
ExtendedConnectType::ConnectUdp,
self.session_id,
CloseReason::Clean {
error: 0,
message: String::new(),
match capsule {
Some(Capsule::Datagram { payload }) => match self.dgram_context_id(payload) {
Ok(slice) => {
events.new_datagram(self.session_id, slice, self.connect_type());
}
Err(e) => {
qdebug!("[{self}]: received capsule with invalid context identifier: {e}");
}
},
None,
);
Ok(Some(State::Done))
} else {
Ok(None)
None => {}
}

if fin {
events.session_end(
ExtendedConnectType::ConnectUdp,
self.session_id,
CloseReason::Clean {
error: 0,
message: String::new(),
},
None,
);
return Ok(Some(State::Done));
}

if !capsule_is_some {
return Ok(None);
}
}
}

Expand All @@ -104,6 +117,37 @@
}
}
}

fn datagram_capsule_support(&self) -> bool {
true
}

fn write_datagram_capsule(
&self,
control_stream_send: &mut Box<dyn SendStream>,
conn: &mut Connection,
buf: &[u8],
now: Instant,
) -> Res<()> {
let mut dgram_data = Encoder::default();
self.write_datagram_prefix(&mut dgram_data);
dgram_data.encode(buf);

if conn.stream_avail_send_space(self.session_id)? < dgram_data.len() {

Check warning on line 136 in neqo-http3/src/features/extended_connect/connect_udp_session.rs

View workflow job for this annotation

GitHub Actions / Find mutants

Missed mutant

replace < with <= in <impl Protocol for Session>::write_datagram_capsule

Check warning on line 136 in neqo-http3/src/features/extended_connect/connect_udp_session.rs

View workflow job for this annotation

GitHub Actions / Find mutants

Missed mutant

replace < with == in <impl Protocol for Session>::write_datagram_capsule
qdebug!("Not enough space to send datagram capsule, dropping it.");
return Ok(());
}
// TODO: Make Capsule abstract over either an owned (Bytes) or borrowed (&[u8]) type
// to avoid this allocation.
let capsule = Capsule::Datagram {
Comment thread
WaterWhisperer marked this conversation as resolved.
Resolved
payload: Bytes::from(Vec::from(dgram_data)),
};
let mut enc = Encoder::default();
capsule.encode(&mut enc);
control_stream_send.send_data_atomic(conn, enc.as_ref(), now)?;
qtrace!("[{self}] sent datagram via HTTP DATAGRAM Capsule");
Ok(())
}
}

#[cfg(test)]
Expand Down
46 changes: 37 additions & 9 deletions neqo-http3/src/features/extended_connect/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,25 +377,40 @@ impl Session {

/// # Errors
///
/// Returns an error if the datagram exceeds the remote datagram size limit.
/// Returns an error if:
/// - The session is not in Active state (`Error::Unavailable`).
/// - QUIC datagram or HTTP DATAGRAM Capsule sending fails.
pub(crate) fn send_datagram<I: Into<DatagramTracking>>(
&self,
&mut self,
conn: &mut Connection,
buf: &[u8],
id: I,
now: Instant,
) -> Res<()> {
qtrace!("[{self}] send_datagram state={:?}", self.state);
if self.state == State::Active {
let mut dgram_data = Encoder::default();
dgram_data.encode_varint(self.id.as_u64() / 4);
self.protocol.write_datagram_prefix(&mut dgram_data);
dgram_data.encode(buf);
conn.send_datagram(dgram_data.into(), id)?;
} else {
if self.state != State::Active {
qdebug!("[{self}]: cannot send datagram in {:?} state.", self.state);
debug_assert!(false);
return Err(Error::Unavailable);
}

if conn.remote_datagram_size() == 0 && self.protocol.datagram_capsule_support() {
qtrace!("[{self}] remote_datagram_size is 0, trying HTTP DATAGRAM Capsule");
return self.protocol.write_datagram_capsule(
&mut self.control_stream_send,
conn,
buf,
now,
);
}

let mut dgram_data = Encoder::default();
dgram_data.encode_varint(self.id.as_u64() / 4);
self.protocol.write_datagram_prefix(&mut dgram_data);
dgram_data.encode(buf);

conn.send_datagram(dgram_data.into(), id)?;
qtrace!("[{self}] sent datagram via QUIC datagram");
Ok(())
}

Expand Down Expand Up @@ -565,6 +580,19 @@ pub(crate) trait Protocol: Debug + Display {
fn write_datagram_prefix(&self, encoder: &mut Encoder);

fn dgram_context_id(&self, datagram: Bytes) -> Result<Bytes, DgramContextIdError>;

/// Whether the extended CONNECT protocol supports sending datagrams as HTTP
/// DATAGRAM Capsules when QUIC datagrams are unavailable.
fn datagram_capsule_support(&self) -> bool;

/// Write a datagram as an HTTP DATAGRAM Capsule to the control stream.
fn write_datagram_capsule(
&self,
_control_stream_send: &mut Box<dyn SendStream>,
_conn: &mut Connection,
_buf: &[u8],
_now: Instant,
) -> Res<()>;
}

#[derive(Debug, Error)]
Expand Down
Loading
Loading