diff --git a/project/Cargo.lock b/project/Cargo.lock index a155c2c..8692ef8 100644 --- a/project/Cargo.lock +++ b/project/Cargo.lock @@ -115,6 +115,12 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" version = "0.2.151" @@ -131,6 +137,12 @@ dependencies = [ "scopeguard", ] +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + [[package]] name = "memchr" version = "2.7.2" @@ -157,6 +169,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num_cpus" version = "1.16.0" @@ -188,6 +210,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "parking_lot" version = "0.12.1" @@ -387,6 +415,15 @@ dependencies = [ "syn", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -446,6 +483,18 @@ dependencies = [ "rustls", "tokio", "tokio-util", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", ] [[package]] @@ -509,6 +558,63 @@ dependencies = [ "tokio", ] +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "nu-ansi-term", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", +] + [[package]] name = "unicode-ident" version = "1.0.12" @@ -521,12 +627,40 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/project/Cargo.toml b/project/Cargo.toml index 49b7c87..144ce90 100644 --- a/project/Cargo.toml +++ b/project/Cargo.toml @@ -21,3 +21,5 @@ rand = "0.8.5" ring = "0.17.8" tokio = { version = "1.37.0", features = ["full"] } tokio-util = { version = "0.7.11" } +tracing = "0.1.40" +tracing-subscriber = "0.3.18" diff --git a/project/src/main.rs b/project/src/main.rs index 46a75aa..22dab61 100644 --- a/project/src/main.rs +++ b/project/src/main.rs @@ -1,7 +1,20 @@ use quic::{terror, ServerConfig}; +use tracing::Level; +use tracing_subscriber::FmtSubscriber; + +fn main() { + let subscriber = FmtSubscriber::builder() + .with_max_level(Level::DEBUG) + .finish(); + + tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed"); + + let _ = run(); +} + #[tokio::main] -async fn main() -> Result<(), terror::Error> { +async fn run() -> Result<(), terror::Error> { let mut cert_path = std::env::current_dir().unwrap(); cert_path.push("cert"); cert_path.push("cert.der"); diff --git a/project/src/quic/lib.rs b/project/src/quic/lib.rs index ddd53ef..5bf6d77 100644 --- a/project/src/quic/lib.rs +++ b/project/src/quic/lib.rs @@ -25,6 +25,7 @@ use tokio::{ sync::{mpsc, oneshot, RwLock}, task::JoinHandle, }; +use tracing::{debug, debug_span, error, info, warn, Instrument}; use transport_parameters::{ InitialSourceConnectionId, OriginalDestinationConnectionId, StatelessResetTokenTP, TransportConfig, @@ -73,19 +74,29 @@ impl Acceptor { async fn accept(&mut self) -> Option { let (packet, remote, header, tsd, socket) = self.rx.recv().await.unwrap(); - //TODO refactor unwrap panic with proper error handling let (connection, ready) = - Connection::early_connection((packet, remote, header), tsd, socket) + match Connection::early_connection((packet, remote, header), tsd, socket) + .instrument(debug_span!("accepting new connection")) .await - .unwrap(); + { + Ok((c, r)) => (c, r), + Err(e) => { + // if we encounter an error within the initial packet, the connection is + // immediately abandoned + // TODO send close connection frame, remove conn from Distributor + error!("encountered error while accepting new connection: {}", e); + return None; + } + }; + //send connection close frame match ready.await { Ok(terror::QuicTransportError::NoError) => return Some(connection), Ok(quic_error) => { - eprintln!("Connection could not be established: {}", quic_error); + error!("Connection could not be established: {}", quic_error); } Err(error) => { - eprintln!("Error retrieving connection state: {}", error); + error!("Error retrieving connection state: {}", error); } } @@ -135,6 +146,8 @@ impl ServerConfig { } }; + debug!("loaded cert from {} and key from {}", cert_path, key_path); + let server_cfg = rustls::ServerConfig::builder_with_provider(provider) .with_protocol_versions(&[&rustls::version::TLS13]) .unwrap() @@ -211,6 +224,8 @@ impl Endpoint { let dist = self.distributor.clone(); let cancellation_token = { dist.read().await.cancellation_token.clone() }; + info!("listening on {}", &self.address); + self.recv_loop_handle = Some(tokio::spawn(async move { loop { let mut buffer = std::iter::repeat(0) @@ -224,7 +239,7 @@ impl Endpoint { continue; } }; - println!("Received {:?} bytes from {:?}", size, src_addr); + info!("Received {:?} bytes from {:?}", size, src_addr); //truncate vector to correct size buffer.truncate(size); @@ -233,33 +248,30 @@ impl Endpoint { Err(error) => panic!("Error: {}", error), }; - print!("I: "); - partial_decode.debug_print(); - - //stop accepting new connections when entering graceful shutdown - if partial_decode.is_inital() && !cancellation_token.is_cancelled() { - tx_initial - .send(( - buffer, - src_addr.to_string(), - partial_decode, - dist.clone(), - socket.clone(), - )) + debug!("I: {}", partial_decode); + + //match incoming packet to connection + if let Some(handle) = dist + .read() + .await + .connection_send_handles + .get(&partial_decode.dcid) + { + handle + .send((buffer, src_addr.to_string(), partial_decode)) .await .unwrap(); } else { - print!("Got packet of known connection: "); - partial_decode.debug_print(); - //TODO make search with source address and retry cid ... - if let Some(handle) = dist - .read() - .await - .connection_send_handles - .get(&partial_decode.dcid) - { - handle - .send((buffer, src_addr.to_string(), partial_decode)) + //stop accepting new connections when entering graceful shutdown + if partial_decode.is_inital() && !cancellation_token.is_cancelled() { + tx_initial + .send(( + buffer, + src_addr.to_string(), + partial_decode, + dist.clone(), + socket.clone(), + )) .await .unwrap(); } @@ -314,6 +326,11 @@ impl Connection { &head.dcid, ); + debug!( + origin = src_addr, + "initial keys ready for dcid {}", &head.dcid + ); + let header_length = match head.decrypt(&mut buffer, ikp.remote.header.as_ref()) { Ok(s) => s, Err(error) => panic!("Error: {}", error), @@ -346,7 +363,8 @@ impl Connection { decrypted_payload_raw.len() }; - //truncate payload to length returned by decrypting packet payload + //truncate payload to length returned by decrypting packet payload, may cause problems with + //coalesced packets buffer.truncate(dec_len); let initial_local_scid = ConnectionId::generate_with_length(8); @@ -450,11 +468,11 @@ impl Connection { self.loop_handle = Some(tokio::spawn(async move { while let Some(mut msg) = recv_q.recv().await { - println!("received datagram inside connection {:?}", msg.1); + debug!(origin = msg.1, "received datagram. processing..."); //process if let Err(error) = conn.recv(&mut msg) { - eprint!("error processing datagram: {}", error); + error!("error processing datagram: {}", error); }; //send back ack at least, check for data in outgoing streams @@ -469,7 +487,7 @@ impl Connection { } }; - println!("sent {} bytes to {}", size, &dgram.1); + info!(destination = dgram.1, "sent {} bytes", size); } Ok(0) })); @@ -484,7 +502,7 @@ impl Connection { } }; - println!("sent {} bytes to {}", size, &dgram.1); + info!(destination = dgram.1, "sent {} bytes", size); Ok(()) } @@ -586,7 +604,6 @@ impl Inner { //fully decrypts packet header and payload, does tls stuff and passes packet to process_payload fn recv(&mut self, datagram: &mut packet::EarlyDatagram) -> Result<(), terror::Error> { //decrypt header and payload - datagram.2.debug_print(); //TODO handle coalesced packets self.process_payload(&datagram.2, &mut datagram.0)?; @@ -600,13 +617,14 @@ impl Inner { self.process_payload(header, packet_raw)?; if let Some(tpc) = self.tls_session.quic_transport_parameters() { - self.remote_tpc.update(tpc).unwrap(); + self.remote_tpc.update(tpc)?; } if *self.remote_tpc.initial_source_connection_id.get().unwrap() != self.initial_remote_scid { - return Err(terror::Error::quic_protocol_violation( + return Err(terror::Error::quic_transport_error( "scids from packet header and transport parameters differ", + terror::QuicTransportError::TransportParameterError, )); } @@ -678,12 +696,7 @@ impl Inner { .split_at(stream_frame.offset.unwrap() as usize) .unwrap(); } - - println!( - "stream_id {:#x} len {:#x}", - stream_frame.stream_id, - stream_data.len(), - ); + debug!("stream data: {:?}", stream_data); } //STREAM 0x10 => { let _max_data = payload.get_varint().unwrap(); @@ -730,14 +743,14 @@ impl Inner { } //CONNECTION_CLOSE_FRAME 0x1e => { if self.side == Side::Server { - eprintln!("Received HANDSHAKE_DONE frame as server"); + error!("Received HANDSHAKE_DONE frame as server"); self.transmit_ready(terror::QuicTransportError::ProtocolViolation); continue; } self.transmit_ready(terror::QuicTransportError::NoError); } // HANDSHAKE_DONE - _ => eprintln!( + _ => warn!( "Error while processing frames: unrecognised frame {:#x} at {:#x}", frame_code, payload.off() @@ -765,10 +778,13 @@ impl Inner { fn process_crypto_data(&mut self, crypto_frame: &CryptoFrame) { match self.tls_session.read_hs(crypto_frame.data()) { - Ok(()) => println!("Successfully read handshake data"), + Ok(()) => debug!( + "consumed {} bytes from crypto frame", + crypto_frame.data().len() + ), Err(err) => { - eprintln!("Error reading crypto data: {}", err); - eprintln!("{:?}", self.tls_session.alert().unwrap()); + error!("Error reading crypto data: {}", err); + error!("{:?}", self.tls_session.alert().unwrap()); } } @@ -781,7 +797,6 @@ impl Inner { || has_server_name || !self.tls_session.is_handshaking() { - println!("Handshake data has been proccessed successfully"); let _ = true; } } @@ -791,10 +806,15 @@ impl Inner { //writing handshake data prompts a keychange because the packet number space is promoted if let Some(kc) = self.tls_session.write_hs(&mut buf) { + debug!("generated {} bytes of crypto data", buf.len()); //get keys from keychange let keys = match kc { - KeyChange::Handshake { keys } => keys, + KeyChange::Handshake { keys } => { + debug!("handshake keyset ready"); + keys + } KeyChange::OneRtt { keys, next } => { + debug!("data (1-rtt) keyset ready"); self.next_secrets = Some(next); keys } @@ -821,7 +841,7 @@ impl Inner { return; } - println!("Crypto {:?}", buf.len()); + //println!("Crypto {:?}", buf.len()); //create outgoing crypto frame let offset = self.packet_spaces[space_id].outgoing_crypto_offset; @@ -893,7 +913,7 @@ impl Inner { //maybe its cheapest to create huge vec at beginning and just trim it at the end //TODO replace with max mtu let mut data = vec![0u8; 65535]; - let mut size = 0; + let size: usize; { let mut buf = octets::OctetsMut::with_slice(&mut data); diff --git a/project/src/quic/packet.rs b/project/src/quic/packet.rs index 0393945..26fe60c 100644 --- a/project/src/quic/packet.rs +++ b/project/src/quic/packet.rs @@ -2,8 +2,9 @@ use crate::{terror, token::StatelessResetToken, ConnectionId, TSDistributor}; use octets::Octets; use rustls::quic::HeaderProtectionKey; +use tracing::{debug, info}; -use std::{collections::VecDeque, marker::PhantomData, sync::Arc}; +use std::{collections::VecDeque, fmt, marker::PhantomData, sync::Arc}; const MAX_PKT_NUM_LEN: usize = 4; const SAMPLE_LEN: usize = 16; @@ -88,6 +89,8 @@ impl DatagramBuilder { i += 1; } + debug!("built datagram with {} packets ({} bytes)", size, offset); + dgram.resize(offset, 0x00); Ok((dgram, address)) @@ -197,12 +200,10 @@ impl PacketBuilder<(PacketBody, PacketHeader, C)> { // encodes the packet and its header into the datagram, can only be called after body and // header have been specified fn encode(&self, dgram: &mut [u8]) -> Result<(), terror::Error> { - println!("AVAILIBLE SPACE: {:?}", dgram.len()); + debug!("encoding packet on buffer with size {}", dgram.len()); let mut b = octets::OctetsMut::with_slice(dgram); - self.header.debug_print(); - //encode header if let Err(err) = self.header.to_bytes(&mut b) { return Err(terror::Error::buffer_size_error(format!( @@ -314,19 +315,19 @@ impl AckFrame { pub fn from_packet_number_vec(packet_numbers: &[u64], ack_delay: u64) -> Self { let mut ack = Self::empty(ack_delay); ack.len = 1; - println!("len + 1 from frame code"); + //println!("len + 1 from frame code"); let mut last_pn: u64 = 0; for (i, range) in Self::range_iterator_descending(packet_numbers).enumerate() { if i == 0 { //first range contains highest ack ack.add_highest_range(range[0], (range.len() - 1) as u64); - println!("first ack range: ha {:?} r {:?}", range[0], range.len() - 1); + //println!("first ack range: ha {:?} r {:?}", range[0], range.len() - 1); last_pn = range[range.len() - 1]; } else { //append to ranges let gap: u64 = last_pn - range[0] - 1; - println!("gap {:?} = lpn {:?} - r0 {:?}", gap, last_pn, range[0]); + //println!("gap {:?} = lpn {:?} - r0 {:?}", gap, last_pn, range[0]); last_pn = range[range.len() - 1]; ack.add_range(gap, (range.len() - 1) as u64); } @@ -337,13 +338,13 @@ impl AckFrame { + varint_length(ack.ack_range_count) + varint_length(ack.first_ack_range); - println!( + /*println!( "len + {:?} from la", varint_length(ack.largest_acknowledged) ); println!("len + {:?} from ad", varint_length(ack.ack_delay)); println!("len + {:?} from arc", varint_length(ack.ack_range_count)); - println!("len + {:?} from far", varint_length(ack.first_ack_range)); + println!("len + {:?} from far", varint_length(ack.first_ack_range));*/ ack } @@ -388,8 +389,8 @@ impl AckFrame { self.len += varint_length(gap); self.len += varint_length(range); - println!("len + {:?} from gap", varint_length(gap)); - println!("len + {:?} from range", varint_length(range)); + //println!("len + {:?} from gap", varint_length(gap)); + //println!("len + {:?} from range", varint_length(range)); } //TODO add support for ecn counts @@ -990,31 +991,21 @@ impl Header { 0x01000000..=0xffffffff => 3, } } +} - pub fn debug_print(&self) { - println!( - "{:#04x?} version: {:#06x?} pn: {:#010x?} dcid: 0x{} scid: 0x{} token:{:x?} length:{:?} raw_length:{:?}", - ((self.hf & LONG_PACKET_TYPE) >> 4), +impl fmt::Display for Header { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{:#b} version: {:#06x?} pn: {:#010x?} dcid: {} scid: 0x{} token:{:x?} length:{:?} raw_length:{:?}", + self.hf, self.version, self.packet_num, - self.dcid - .id - .iter() - .map(|val| format!("{:x}", val)) - .collect::>() - .join(""), + self.dcid, self.scid .clone() - .unwrap_or(ConnectionId::from_vec(Vec::new())) - .id - .iter() - .map(|val| format!("{:x}", val)) - .collect::>() - .join(""), + .unwrap_or(ConnectionId::from_vec(Vec::new())), self.token.as_ref().unwrap_or(&vec![0u8; 0]), self.length, - self.raw_length, - ); + self.raw_length) } } diff --git a/project/src/quic/terror.rs b/project/src/quic/terror.rs index 2fce354..4a67dd4 100644 --- a/project/src/quic/terror.rs +++ b/project/src/quic/terror.rs @@ -22,24 +22,29 @@ macro_rules! taurus_error { } impl Error { - taurus_error!(fatal, 0x00); - taurus_error!(unknown_connection, 0x01); - taurus_error!(socket_error, 0x02); - taurus_error!(header_encoding_error, 0x03); - taurus_error!(packet_encoding_error, 0x04); - taurus_error!(buffer_size_error, 0x05); - taurus_error!(no_cipher_suite, 0x06); - taurus_error!(crypto_error, 0x07); - taurus_error!(quic_protocol_violation, 0x0a); + pub fn kind(&self) -> u64 { + self.code + } + + taurus_error!(fatal, 0x11); + taurus_error!(unknown_connection, 0x12); + taurus_error!(socket_error, 0x13); + taurus_error!(header_encoding_error, 0x14); + taurus_error!(packet_encoding_error, 0x15); + taurus_error!(buffer_size_error, 0x16); + taurus_error!(no_cipher_suite, 0x17); + taurus_error!(crypto_error, 0x18); taurus_error!(taurus_misc_error, 0xff); pub fn quic_transport_error(reason: T, code: QuicTransportError) -> Self where T: Into, { + let mut msg = format!("{code} "); + msg.push_str(&reason.into()); Self { code: code as u64, - msg: reason.into(), + msg, } } } @@ -81,27 +86,27 @@ pub enum QuicTransportError { impl fmt::Display for QuicTransportError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - QuicTransportError::NoError => write!(f, "0x00 no error"), - QuicTransportError::InternalError => write!(f, "0x01 internal error"), - QuicTransportError::ConnectionRefused => write!(f, "0x02 connection refused"), - QuicTransportError::FlowControlError => write!(f, "0x03 flow control error"), - QuicTransportError::StreamLimitError => write!(f, "0x04 stream limit error"), - QuicTransportError::StreamStateError => write!(f, "0x05 stream state error"), - QuicTransportError::FinalSizeError => write!(f, "0x06 final size error"), - QuicTransportError::FrameEncodingError => write!(f, "0x07 frame encoding error"), + QuicTransportError::NoError => write!(f, "no error"), + QuicTransportError::InternalError => write!(f, "internal error"), + QuicTransportError::ConnectionRefused => write!(f, "connection refused"), + QuicTransportError::FlowControlError => write!(f, "flow control error"), + QuicTransportError::StreamLimitError => write!(f, "stream limit error"), + QuicTransportError::StreamStateError => write!(f, "stream state error"), + QuicTransportError::FinalSizeError => write!(f, "final size error"), + QuicTransportError::FrameEncodingError => write!(f, "frame encoding error"), QuicTransportError::TransportParameterError => { - write!(f, "0x08 transport parameter error") + write!(f, "transport parameter error") } QuicTransportError::ConnectionIdLimitError => { - write!(f, "0x09 connection id limit error") + write!(f, "connection id limit error") } - QuicTransportError::ProtocolViolation => write!(f, "0x0a protocol violation"), - QuicTransportError::InvalidToken => write!(f, "0x0b invalid token"), - QuicTransportError::ApplicationError => write!(f, "0x0c application error"), - QuicTransportError::CryptoBufferExceeded => write!(f, "0x0d crypto buffer exceeded"), - QuicTransportError::KeyUpdateError => write!(f, "0x0e key update error"), - QuicTransportError::AeadLimitReached => write!(f, "0x0f aead limit reached"), - QuicTransportError::NoViablePath => write!(f, "0x10 no viable path"), + QuicTransportError::ProtocolViolation => write!(f, "protocol violation"), + QuicTransportError::InvalidToken => write!(f, "invalid token"), + QuicTransportError::ApplicationError => write!(f, "application error"), + QuicTransportError::CryptoBufferExceeded => write!(f, "crypto buffer exceeded"), + QuicTransportError::KeyUpdateError => write!(f, "key update error"), + QuicTransportError::AeadLimitReached => write!(f, "aead limit reached"), + QuicTransportError::NoViablePath => write!(f, "no viable path"), } } } diff --git a/project/src/quic/transport_parameters.rs b/project/src/quic/transport_parameters.rs index abea541..8f42d86 100644 --- a/project/src/quic/transport_parameters.rs +++ b/project/src/quic/transport_parameters.rs @@ -196,10 +196,11 @@ macro_rules! transport_parameter { } fn decode(buf: &mut Octets) -> Result { - Ok(Self { + Self { value: >::decode(buf) .map_err(|e| terror::Error::buffer_size_error(format!("{}", e)))?, - }) + } + .validate() } fn encode(&self, buf: &mut OctetsMut) -> Result<(), terror::Error> { @@ -302,7 +303,7 @@ transport_parameter!(MaxUdpPayloadSize, 0x03, VarInt, 0xfff7.into()); impl MaxUdpPayloadSize { fn validate(self) -> Result { - if (1200..=65527).contains(&self.value.value) { + if !(1200..=65527).contains(&self.value.value) { return Err(terror::Error::quic_transport_error( format!("invalid maximum udp payload size of {:?}", self.value.value), terror::QuicTransportError::TransportParameterError,