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

use std::fmt::{self, Display, Formatter};

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

use crate::{
Expand Down Expand Up @@ -85,9 +85,10 @@ impl Protocol for Session {
}

fn dgram_context_id<'a>(&self, datagram: &'a [u8]) -> Result<&'a [u8], DgramContextIdError> {
match datagram.split_first() {
Some((0, remainder)) => Ok(remainder),
Some((context_id, _)) => Err(DgramContextIdError::UnknownIdentifier(*context_id)),
let mut decoder = Decoder::new(datagram);
match decoder.decode_varint() {
Some(0) => Ok(decoder.decode_remainder()),
Some(context_id) => Err(DgramContextIdError::UnknownIdentifier(context_id)),
None => {
// > all HTTP Datagrams associated with UDP Proxying request streams start with a Context ID field;
//
Expand All @@ -97,3 +98,26 @@ impl Protocol for Session {
}
}
}

#[cfg(test)]
mod tests {
use neqo_transport::StreamId;

use super::Session;
use crate::features::extended_connect::session::Protocol as _;

#[test]
fn varint_0_context_id() {
let session = Session::new(StreamId::new(42));
// Varint [0x00] is 0, i.e. a supported connect-udp context ID.
assert_eq!(
session.dgram_context_id(&[0x00, 0x00, 0x00]).unwrap(),
&[0x00, 0x00]
);
// Varint [0x40 0x00] is 0 as well, thus a supported connect-udp context ID, too.
assert_eq!(
session.dgram_context_id(&[0x40, 0x00, 0x00, 0x00]).unwrap(),
&[0x00, 0x00]
);
}
}
2 changes: 1 addition & 1 deletion neqo-http3/src/features/extended_connect/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,5 +551,5 @@ pub(crate) enum DgramContextIdError {
#[error("Missing context identifier")]
MissingIdentifier,
#[error("Unknown context identifier: {0}")]
UnknownIdentifier(u8),
UnknownIdentifier(u64),
}