From f7a269395f96ba8b601f43939dda2dbeba935850 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Thu, 17 Oct 2024 12:09:05 +0200 Subject: [PATCH 1/3] feat(transport): accept borrowed instead of owned input datagram Previously `process_input` (and the like) took a `Datagram>` as input. In other words, it required allocating each UDP datagram payload in a dedicated `Vec` before passing it to `process_input`. With this patch, `process_input` accepts a `Datagram<&[u8]>`. In other words, it accepts a `Datagram` with a borrowed view into an existing buffer (`&[u8]`), e.g. a long lived receive buffer. --- fuzz/fuzz_targets/client_initial.rs | 4 +- fuzz/fuzz_targets/server_initial.rs | 9 +- neqo-bin/src/client/http09.rs | 2 +- neqo-bin/src/client/http3.rs | 2 +- neqo-bin/src/client/mod.rs | 4 +- neqo-http3/src/connection_client.rs | 543 +++++++++--------- .../tests/webtransport/mod.rs | 30 +- .../tests/webtransport/negotiation.rs | 8 +- .../tests/webtransport/sessions.rs | 16 +- neqo-http3/src/frames/tests/mod.rs | 16 +- neqo-http3/src/frames/tests/reader.rs | 28 +- neqo-http3/src/server.rs | 181 +++--- neqo-http3/src/stream_type_reader.rs | 12 +- neqo-http3/tests/httpconn.rs | 74 +-- neqo-http3/tests/priority.rs | 24 +- neqo-http3/tests/send_message.rs | 4 +- neqo-http3/tests/webtransport.rs | 18 +- neqo-qpack/src/decoder.rs | 8 +- neqo-qpack/src/encoder.rs | 18 +- neqo-transport/src/connection/mod.rs | 75 ++- .../src/connection/tests/ackrate.rs | 14 +- neqo-transport/src/connection/tests/cc.rs | 34 +- neqo-transport/src/connection/tests/close.rs | 48 +- .../src/connection/tests/datagram.rs | 22 +- neqo-transport/src/connection/tests/ecn.rs | 34 +- .../src/connection/tests/handshake.rs | 270 ++++----- neqo-transport/src/connection/tests/idle.rs | 101 ++-- neqo-transport/src/connection/tests/keys.rs | 44 +- .../src/connection/tests/migration.rs | 82 +-- neqo-transport/src/connection/tests/mod.rs | 18 +- neqo-transport/src/connection/tests/null.rs | 4 +- .../src/connection/tests/priority.rs | 40 +- .../src/connection/tests/recovery.rs | 194 +++---- .../src/connection/tests/resumption.rs | 28 +- neqo-transport/src/connection/tests/stream.rs | 164 +++--- neqo-transport/src/connection/tests/vn.rs | 50 +- .../src/connection/tests/zerortt.rs | 42 +- neqo-transport/src/path.rs | 2 +- neqo-transport/src/server.rs | 16 +- neqo-transport/tests/common/mod.rs | 20 +- neqo-transport/tests/conn_vectors.rs | 2 +- neqo-transport/tests/connection.rs | 40 +- neqo-transport/tests/retry.rs | 122 ++-- neqo-transport/tests/server.rs | 142 ++--- test-fixture/src/lib.rs | 2 +- test-fixture/src/sim/connection.rs | 2 +- 46 files changed, 1312 insertions(+), 1301 deletions(-) diff --git a/fuzz/fuzz_targets/client_initial.rs b/fuzz/fuzz_targets/client_initial.rs index 8a0d18d5f5..1e30ce9bc6 100644 --- a/fuzz/fuzz_targets/client_initial.rs +++ b/fuzz/fuzz_targets/client_initial.rs @@ -17,7 +17,7 @@ fuzz_target!(|data: &[u8]| { }; let mut client = default_client(); - let ci = client.process(None, now()).dgram().expect("a datagram"); + let ci = client.process_output(now()).dgram().expect("a datagram"); let Some((header, d_cid, s_cid, payload)) = decode_initial_header(&ci, Role::Client) else { return; }; @@ -60,7 +60,7 @@ fuzz_target!(|data: &[u8]| { let fuzzed_ci = Datagram::new(ci.source(), ci.destination(), ci.tos(), ciphertext); let mut server = default_server(); - let _response = server.process(Some(&fuzzed_ci), now()); + let _response = server.process(Some(fuzzed_ci), now()); }); #[cfg(any(not(fuzzing), windows))] diff --git a/fuzz/fuzz_targets/server_initial.rs b/fuzz/fuzz_targets/server_initial.rs index ced07e3b63..2ff293b20c 100644 --- a/fuzz/fuzz_targets/server_initial.rs +++ b/fuzz/fuzz_targets/server_initial.rs @@ -17,12 +17,9 @@ fuzz_target!(|data: &[u8]| { }; let mut client = default_client(); - let ci = client.process(None, now()).dgram().expect("a datagram"); + let ci = client.process_output(now()).dgram().expect("a datagram"); let mut server = default_server(); - let si = server - .process(Some(&ci), now()) - .dgram() - .expect("a datagram"); + let si = server.process(Some(ci), now()).dgram().expect("a datagram"); let Some((header, d_cid, s_cid, payload)) = decode_initial_header(&si, Role::Server) else { return; @@ -64,7 +61,7 @@ fuzz_target!(|data: &[u8]| { (header_enc.len() - 1)..header_enc.len(), ); let fuzzed_si = Datagram::new(si.source(), si.destination(), si.tos(), ciphertext); - let _response = client.process(Some(&fuzzed_si), now()); + let _response = client.process(Some(fuzzed_si), now()); }); #[cfg(any(not(fuzzing), windows))] diff --git a/neqo-bin/src/client/http09.rs b/neqo-bin/src/client/http09.rs index 2f31928058..d4a1829892 100644 --- a/neqo-bin/src/client/http09.rs +++ b/neqo-bin/src/client/http09.rs @@ -183,7 +183,7 @@ impl super::Client for Connection { fn process_multiple_input<'a, I>(&mut self, dgrams: I, now: Instant) where - I: IntoIterator, + I: IntoIterator>, { self.process_multiple_input(dgrams, now); } diff --git a/neqo-bin/src/client/http3.rs b/neqo-bin/src/client/http3.rs index 0413338672..b8745a1fd6 100644 --- a/neqo-bin/src/client/http3.rs +++ b/neqo-bin/src/client/http3.rs @@ -134,7 +134,7 @@ impl super::Client for Http3Client { fn process_multiple_input<'a, I>(&mut self, dgrams: I, now: Instant) where - I: IntoIterator, + I: IntoIterator>, { self.process_multiple_input(dgrams, now); } diff --git a/neqo-bin/src/client/mod.rs b/neqo-bin/src/client/mod.rs index 8bfac59703..beac31dda3 100644 --- a/neqo-bin/src/client/mod.rs +++ b/neqo-bin/src/client/mod.rs @@ -376,7 +376,7 @@ trait Client { fn process_output(&mut self, now: Instant) -> Output; fn process_multiple_input<'a, I>(&mut self, dgrams: I, now: Instant) where - I: IntoIterator; + I: IntoIterator>; fn has_events(&self) -> bool; fn close(&mut self, now: Instant, app_error: AppError, msg: S) where @@ -462,7 +462,7 @@ impl<'a, H: Handler> Runner<'a, H> { break; } self.client - .process_multiple_input(dgrams.iter(), Instant::now()); + .process_multiple_input(dgrams.iter().map(Datagram::borrow), Instant::now()); self.process_output().await?; } diff --git a/neqo-http3/src/connection_client.rs b/neqo-http3/src/connection_client.rs index 1d5f6f7329..253e303ad1 100644 --- a/neqo-http3/src/connection_client.rs +++ b/neqo-http3/src/connection_client.rs @@ -855,7 +855,7 @@ impl Http3Client { } /// This function combines `process_input` and `process_output` function. - pub fn process(&mut self, dgram: Option<&Datagram>, now: Instant) -> Output { + pub fn process(&mut self, dgram: Option>>, now: Instant) -> Output { qtrace!([self], "Process."); if let Some(d) = dgram { self.process_input(d, now); @@ -873,14 +873,15 @@ impl Http3Client { /// packets need to be sent or if a timer needs to be updated. /// /// [1]: ../neqo_transport/enum.ConnectionEvent.html - pub fn process_input(&mut self, dgram: &Datagram, now: Instant) { + pub fn process_input(&mut self, dgram: Datagram>, now: Instant) { self.process_multiple_input(iter::once(dgram), now); } - pub fn process_multiple_input<'a, I>(&mut self, dgrams: I, now: Instant) - where - I: IntoIterator, - { + pub fn process_multiple_input( + &mut self, + dgrams: impl IntoIterator>>, + now: Instant, + ) { let mut dgrams = dgrams.into_iter().peekable(); qtrace!([self], "Process multiple datagrams"); if dgrams.peek().is_none() { @@ -1637,15 +1638,15 @@ mod tests { fn handshake_only(client: &mut Http3Client, server: &mut TestServer) -> Output { assert_eq!(client.state(), Http3State::Initializing); - let out = client.process(None, now()); + let out = client.process_output(now()); assert_eq!(client.state(), Http3State::Initializing); assert_eq!(*server.conn.state(), State::Init); - let out = server.conn.process(out.as_dgram_ref(), now()); + let out = server.conn.process(out.dgram(), now()); assert_eq!(*server.conn.state(), State::Handshaking); - let out = client.process(out.as_dgram_ref(), now()); - let out = server.conn.process(out.as_dgram_ref(), now()); + let out = client.process(out.dgram(), now()); + let out = server.conn.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_none()); let authentication_needed = |e| matches!(e, Http3ClientEvent::AuthenticationNeeded); @@ -1658,14 +1659,12 @@ mod tests { fn connect_only_transport_with(client: &mut Http3Client, server: &mut TestServer) { let out = handshake_only(client, server); - let out = client.process(out.as_dgram_ref(), now()); + let out = client.process(out.dgram(), now()); let connected = |e| matches!(e, Http3ClientEvent::StateChange(Http3State::Connected)); assert!(client.events().any(connected)); assert_eq!(client.state(), Http3State::Connected); - server - .conn - .process_input(out.as_dgram_ref().unwrap(), now()); + server.conn.process_input(out.dgram().unwrap(), now()); assert!(server.conn.state().connected()); } @@ -1679,10 +1678,8 @@ mod tests { fn send_and_receive_client_settings(client: &mut Http3Client, server: &mut TestServer) { // send and receive client settings - let out = client.process(None, now()); - server - .conn - .process_input(out.as_dgram_ref().unwrap(), now()); + let out = client.process_output(now()); + server.conn.process_input(out.dgram().unwrap(), now()); server.check_client_control_qpack_streams_no_resumption(); } @@ -1696,8 +1693,8 @@ mod tests { server.create_qpack_streams(); // Send the server's control and qpack streams data. - let out = server.conn.process(None, now()); - client.process_input(out.as_dgram_ref().unwrap(), now()); + let out = server.conn.process(None::, now()); + client.process_input(out.dgram().unwrap(), now()); // assert no error occured. assert_eq!(client.state(), Http3State::Connected); @@ -1839,10 +1836,8 @@ mod tests { ) -> StreamId { let request_stream_id = make_request(client, close_sending_side, &[]); - let out = client.process(None, now()); - server - .conn - .process_input(out.as_dgram_ref().unwrap(), now()); + let out = client.process_output(now()); + server.conn.process_input(out.dgram().unwrap(), now()); // find the new request/response stream and send frame v on it. while let Some(e) = server.conn.next_event() { @@ -1872,7 +1867,7 @@ mod tests { } let dgram = server.conn.process_output(now()).dgram(); if let Some(d) = dgram { - client.process_input(&d, now()); + client.process_input(d, now()); } request_stream_id } @@ -1900,9 +1895,9 @@ mod tests { if close_stream { server.conn.stream_close_send(stream_id).unwrap(); } - let out = server.conn.process(None, now()); - let out = client.process(out.as_dgram_ref(), now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = server.conn.process(None::, now()); + let out = client.process(out.dgram(), now()); + mem::drop(server.conn.process(out.dgram(), now())); } const PUSH_PROMISE_DATA: &[u8] = &[ @@ -1939,9 +1934,9 @@ mod tests { ) -> StreamId { let push_stream_id = send_push_data(&mut server.conn, push_id, close_push_stream); - let out = server.conn.process(None, now()); - let out = client.process(out.as_dgram_ref(), now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = server.conn.process_output(now()); + let out = client.process(out.dgram(), now()); + mem::drop(server.conn.process(out.dgram(), now())); push_stream_id } @@ -1954,9 +1949,9 @@ mod tests { ) { send_push_promise(&mut server.conn, stream_id, push_id); - let out = server.conn.process(None, now()); - let out = client.process(out.as_dgram_ref(), now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = server.conn.process_output(now()); + let out = client.process(out.dgram(), now()); + mem::drop(server.conn.process(out.dgram(), now())); } fn send_cancel_push_and_exchange_packets( @@ -1972,9 +1967,9 @@ mod tests { .stream_send(server.control_stream_id.unwrap(), d.as_ref()) .unwrap(); - let out = server.conn.process(None, now()); - let out = client.process(out.as_dgram_ref(), now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = server.conn.process_output(now()); + let out = client.process(out.dgram(), now()); + mem::drop(server.conn.process(out.dgram(), now())); } const PUSH_DATA: &[u8] = &[ @@ -2140,8 +2135,8 @@ mod tests { .conn .stream_close_send(server.control_stream_id.unwrap()) .unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); assert_closed(&client, &Error::HttpClosedCriticalStream); } @@ -2154,8 +2149,8 @@ mod tests { .conn .stream_reset_send(server.control_stream_id.unwrap(), Error::HttpNoError.code()) .unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); assert_closed(&client, &Error::HttpClosedCriticalStream); } @@ -2168,8 +2163,8 @@ mod tests { .conn .stream_reset_send(server.encoder_stream_id.unwrap(), Error::HttpNoError.code()) .unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); assert_closed(&client, &Error::HttpClosedCriticalStream); } @@ -2182,8 +2177,8 @@ mod tests { .conn .stream_reset_send(server.decoder_stream_id.unwrap(), Error::HttpNoError.code()) .unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); assert_closed(&client, &Error::HttpClosedCriticalStream); } @@ -2196,8 +2191,8 @@ mod tests { .conn .stream_stop_sending(CLIENT_SIDE_CONTROL_STREAM_ID, Error::HttpNoError.code()) .unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); assert_closed(&client, &Error::HttpClosedCriticalStream); } @@ -2210,8 +2205,8 @@ mod tests { .conn .stream_stop_sending(CLIENT_SIDE_ENCODER_STREAM_ID, Error::HttpNoError.code()) .unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); assert_closed(&client, &Error::HttpClosedCriticalStream); } @@ -2224,8 +2219,8 @@ mod tests { .conn .stream_stop_sending(CLIENT_SIDE_DECODER_STREAM_ID, Error::HttpNoError.code()) .unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); assert_closed(&client, &Error::HttpClosedCriticalStream); } @@ -2241,8 +2236,8 @@ mod tests { .conn .stream_send(control_stream, &[0x0, 0x1, 0x3, 0x0, 0x1, 0x2]); assert_eq!(sent, Ok(6)); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); assert_closed(&client, &Error::HttpMissingSettings); } @@ -2257,8 +2252,8 @@ mod tests { &[0x4, 0x6, 0x1, 0x40, 0x64, 0x7, 0x40, 0x64], ); assert_eq!(sent, Ok(8)); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); assert_closed(&client, &Error::HttpFrameUnexpected); } @@ -2271,8 +2266,8 @@ mod tests { .stream_send(server.control_stream_id.unwrap(), v) .unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); assert_closed(&client, &Error::HttpFrameUnexpected); } @@ -2320,9 +2315,9 @@ mod tests { .unwrap(); _ = server.conn.stream_send(push_stream_id, v).unwrap(); - let out = server.conn.process(None, now()); - let out = client.process(out.as_dgram_ref(), now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = server.conn.process_output(now()); + let out = client.process(out.dgram(), now()); + mem::drop(server.conn.process(out.dgram(), now())); assert_closed(&client, &Error::HttpFrameUnexpected); } @@ -2380,9 +2375,9 @@ mod tests { .conn .stream_send(new_stream_id, &[0x41, 0x19, 0x4, 0x4, 0x6, 0x0, 0x8, 0x0]) .unwrap(); - let out = server.conn.process(None, now()); - let out = client.process(out.as_dgram_ref(), now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = server.conn.process_output(now()); + let out = client.process(out.dgram(), now()); + mem::drop(server.conn.process(out.dgram(), now())); // check for stop-sending with Error::HttpStreamCreation. let mut stop_sending_event_found = false; @@ -2408,9 +2403,9 @@ mod tests { _ = server.conn.stream_send(request_stream_id, v).unwrap(); // Generate packet with the above bad h3 input - let out = server.conn.process(None, now()); + let out = server.conn.process_output(now()); // Process bad input and close the connection. - mem::drop(client.process(out.as_dgram_ref(), now())); + mem::drop(client.process(out.dgram(), now())); assert_closed(&client, &Error::HttpFrameUnexpected); } @@ -2456,77 +2451,77 @@ mod tests { // send the stream type let mut sent = server.conn.stream_send(control_stream, &[0x0]); assert_eq!(sent, Ok(1)); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); // start sending SETTINGS frame sent = server.conn.stream_send(control_stream, &[0x4]); assert_eq!(sent, Ok(1)); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); sent = server.conn.stream_send(control_stream, &[0x4]); assert_eq!(sent, Ok(1)); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); sent = server.conn.stream_send(control_stream, &[0x6]); assert_eq!(sent, Ok(1)); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); sent = server.conn.stream_send(control_stream, &[0x0]); assert_eq!(sent, Ok(1)); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); sent = server.conn.stream_send(control_stream, &[0x8]); assert_eq!(sent, Ok(1)); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); sent = server.conn.stream_send(control_stream, &[0x0]); assert_eq!(sent, Ok(1)); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); assert_eq!(client.state(), Http3State::Connected); // Now test PushPromise sent = server.conn.stream_send(control_stream, &[0x5]); assert_eq!(sent, Ok(1)); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); sent = server.conn.stream_send(control_stream, &[0x5]); assert_eq!(sent, Ok(1)); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); sent = server.conn.stream_send(control_stream, &[0x4]); assert_eq!(sent, Ok(1)); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); sent = server.conn.stream_send(control_stream, &[0x61]); assert_eq!(sent, Ok(1)); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); sent = server.conn.stream_send(control_stream, &[0x62]); assert_eq!(sent, Ok(1)); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); sent = server.conn.stream_send(control_stream, &[0x63]); assert_eq!(sent, Ok(1)); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); sent = server.conn.stream_send(control_stream, &[0x64]); assert_eq!(sent, Ok(1)); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); // PUSH_PROMISE on a control stream will cause an error assert_closed(&client, &Error::HttpFrameUnexpected); @@ -2603,14 +2598,14 @@ mod tests { let d1 = dgram(&mut client.conn); let d2 = dgram(&mut client.conn); - server.conn.process_input(&d2, now()); - server.conn.process_input(&d1, now()); + server.conn.process_input(d2, now()); + server.conn.process_input(d1, now()); let d3 = dgram(&mut server.conn); let d4 = dgram(&mut server.conn); - client.process_input(&d4, now()); - client.process_input(&d3, now()); + client.process_input(d4, now()); + client.process_input(d3, now()); let ack = client.process_output(now()).dgram(); - server.conn.process_input(&ack.unwrap(), now()); + server.conn.process_input(ack.unwrap(), now()); } /// The client should keep a connection alive if it has unanswered requests. @@ -2629,8 +2624,8 @@ mod tests { server: &mut Connection, request_stream_id: StreamId, ) { - let out = server.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.process_output(now()); + client.process(out.dgram(), now()); while let Some(e) = client.next_event() { match e { @@ -2686,8 +2681,8 @@ mod tests { assert_eq!(sent, REQUEST_BODY.len()); client.stream_close_send(request_stream_id).unwrap(); - let out = client.process(None, now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.conn.process(out.dgram(), now())); // find the new request/response stream and send response on it. while let Some(e) = server.conn.next_event() { @@ -2735,10 +2730,10 @@ mod tests { client.stream_close_send(request_stream_id).unwrap(); // We need to loop a bit until all data has been sent. - let mut out = client.process(None, now()); + let mut out = client.process_output(now()); for _i in 0..20 { - out = server.conn.process(out.as_dgram_ref(), now()); - out = client.process(out.as_dgram_ref(), now()); + out = server.conn.process(out.dgram(), now()); + out = client.process(out.dgram(), now()); } // check request body is received. @@ -2826,12 +2821,12 @@ mod tests { // Close stream. client.stream_close_send(request_stream_id).unwrap(); - let mut out = client.process(None, now()); + let mut out = client.process_output(now()); // We need to loop a bit until all data has been sent. Once for every 1K // of data. for _i in 0..SEND_BUFFER_SIZE / 1000 { - out = server.conn.process(out.as_dgram_ref(), now()); - out = client.process(out.as_dgram_ref(), now()); + out = server.conn.process(out.dgram(), now()); + out = client.process(out.dgram(), now()); } // Check received frames and send a response. @@ -3049,8 +3044,8 @@ mod tests { .stream_reset_send(request_stream_id, Error::HttpRequestRejected.code()) ); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); let mut reset = false; let mut stop_sending = false; @@ -3106,8 +3101,8 @@ mod tests { .stream_stop_sending(request_stream_id, Error::HttpRequestRejected.code()) ); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); let mut stop_sending = false; @@ -3171,8 +3166,8 @@ mod tests { .stream_reset_send(request_stream_id, Error::HttpRequestCancelled.code()) ); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); let mut reset = false; @@ -3239,8 +3234,8 @@ mod tests { .stream_stop_sending(request_stream_id, Error::HttpRequestCancelled.code()) ); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); let mut stop_sending = false; let mut header_ready = false; @@ -3292,8 +3287,8 @@ mod tests { .stream_reset_send(request_stream_id, Error::HttpRequestCancelled.code()) ); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); let mut reset = false; @@ -3382,8 +3377,8 @@ mod tests { let request_stream_id_3 = make_request(&mut client, false, &[]); assert_eq!(request_stream_id_3, 8); - let out = client.process(None, now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.conn.process(out.dgram(), now())); _ = server .conn @@ -3404,8 +3399,8 @@ mod tests { } } } - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); let mut stream_reset = false; while let Some(e) = client.next_event() { @@ -3466,8 +3461,8 @@ mod tests { let request_stream_id_3 = make_request(&mut client, false, &[]); assert_eq!(request_stream_id_3, 8); - let out = client.process(None, now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.conn.process(out.dgram(), now())); // First send a Goaway frame with an higher number _ = server @@ -3475,8 +3470,8 @@ mod tests { .stream_send(server.control_stream_id.unwrap(), &[0x7, 0x1, 0x8]) .unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); // Check that there is one reset for stream_id 8 let mut stream_reset_1 = 0; @@ -3561,8 +3556,8 @@ mod tests { .stream_send(server.control_stream_id.unwrap(), &[0x7, 0x1, 0x4]) .unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); assert_eq!(client.state(), Http3State::GoingAway(StreamId::new(4))); @@ -3572,8 +3567,8 @@ mod tests { .stream_send(server.control_stream_id.unwrap(), &[0x7, 0x1, 0x8]) .unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); assert_closed(&client, &Error::HttpGeneralProtocol); } @@ -3587,8 +3582,8 @@ mod tests { .stream_send(server.control_stream_id.unwrap(), &[0x7, 0x1, 0x9]) .unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); assert_closed(&client, &Error::HttpId); } @@ -3600,8 +3595,8 @@ mod tests { // send fin before sending any data. server.conn.stream_close_send(request_stream_id).unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); // Recv HeaderReady wo headers with fin. let e = client.events().next().unwrap(); @@ -3698,8 +3693,8 @@ mod tests { // ok NOW send fin server.conn.stream_close_send(request_stream_id).unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); // Recv DataReadable wo data with fin while let Some(e) = client.next_event() { @@ -3745,8 +3740,8 @@ mod tests { // ok NOW send fin server.conn.stream_close_send(request_stream_id).unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); // Recv HeaderReady with fin. while let Some(e) = client.next_event() { @@ -3796,8 +3791,8 @@ mod tests { .stream_send(request_stream_id, &[0x00, 0x00]) .unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); // Recv headers wo fin while let Some(e) = client.next_event() { @@ -3823,8 +3818,8 @@ mod tests { // ok NOW send fin server.conn.stream_close_send(request_stream_id).unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); // Recv no data, but do get fin while let Some(e) = client.next_event() { @@ -3893,8 +3888,8 @@ mod tests { // ok NOW send fin server.conn.stream_close_send(request_stream_id).unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); // fin wo data should generate DataReadable let e = client.events().next().unwrap(); @@ -4020,7 +4015,7 @@ mod tests { // Send the encoder instructions, but delay them so that the stream is blocked on decoding // headers. - let encoder_inst_pkt = server.conn.process(None, now()); + let encoder_inst_pkt = server.conn.process_output(now()); // Send response let mut d = Encoder::default(); @@ -4040,11 +4035,11 @@ mod tests { assert!(!client.events().any(header_ready_event)); // Let client receive the encoder instructions. - mem::drop(client.process(encoder_inst_pkt.as_dgram_ref(), now())); + mem::drop(client.process(encoder_inst_pkt.dgram(), now())); - let out = server.conn.process(None, now()); - mem::drop(client.process(out.as_dgram_ref(), now())); - mem::drop(client.process(None, now())); + let out = server.conn.process_output(now()); + mem::drop(client.process(out.dgram(), now())); + mem::drop(client.process_output(now())); let mut recv_header = false; let mut recv_data = false; @@ -4089,7 +4084,7 @@ mod tests { // Send the encoder instructions, but delay them so that the stream is blocked on decoding // headers. - let encoder_inst_pkt = server.conn.process(None, now()); + let encoder_inst_pkt = server.conn.process_output(now()); let mut d = Encoder::default(); hframe.encode(&mut d); @@ -4106,7 +4101,7 @@ mod tests { assert!(!hconn.events().any(header_ready_event)); // Let client receive the encoder instructions. - let _out = hconn.process(encoder_inst_pkt.as_dgram_ref(), now()); + let _out = hconn.process(encoder_inst_pkt.dgram(), now()); let mut recv_header = false; // Now the stream is unblocked. After headers we will receive a fin. @@ -4134,7 +4129,7 @@ mod tests { server.send_ticket(now(), &[]).expect("can send ticket"); let out = server.process_output(now()); assert!(out.as_dgram_ref().is_some()); - client.process_input(out.as_dgram_ref().unwrap(), now()); + client.process_input(out.dgram().unwrap(), now()); // We do not have a token so we need to wait for a resumption token timer to trigger. client.process_output(now() + Duration::from_millis(250)); assert_eq!(client.state(), Http3State::Connected); @@ -4174,11 +4169,11 @@ mod tests { fn zero_rtt_negotiated() { let (mut client, mut server) = start_with_0rtt(); - let out = client.process(None, now()); + let out = client.process_output(now()); assert_eq!(client.state(), Http3State::ZeroRtt); assert_eq!(*server.conn.state(), State::Init); - let out = server.conn.process(out.as_dgram_ref(), now()); + let out = server.conn.process(out.dgram(), now()); // Check that control and qpack streams are received and a // SETTINGS frame has been received. @@ -4191,10 +4186,10 @@ mod tests { ); assert_eq!(*server.conn.state(), State::Handshaking); - let out = client.process(out.as_dgram_ref(), now()); + let out = client.process(out.dgram(), now()); assert_eq!(client.state(), Http3State::Connected); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + mem::drop(server.conn.process(out.dgram(), now())); assert!(server.conn.state().connected()); assert!(client.tls_info().unwrap().resumed()); @@ -4209,11 +4204,11 @@ mod tests { make_request(&mut client, true, &[Header::new("myheaders", "myvalue")]); assert_eq!(request_stream_id, 0); - let out = client.process(None, now()); + let out = client.process_output(now()); assert_eq!(client.state(), Http3State::ZeroRtt); assert_eq!(*server.conn.state(), State::Init); - let out = server.conn.process(out.as_dgram_ref(), now()); + let out = server.conn.process(out.dgram(), now()); // Check that control and qpack streams are received and a // SETTINGS frame has been received. @@ -4226,12 +4221,12 @@ mod tests { ); assert_eq!(*server.conn.state(), State::Handshaking); - let out = client.process(out.as_dgram_ref(), now()); + let out = client.process(out.dgram(), now()); assert_eq!(client.state(), Http3State::Connected); - let out = server.conn.process(out.as_dgram_ref(), now()); + let out = server.conn.process(out.dgram(), now()); assert!(server.conn.state().connected()); - let out = client.process(out.as_dgram_ref(), now()); - assert!(out.as_dgram_ref().is_none()); + let out = client.process(out.dgram(), now()); + assert!(out.dgram().is_none()); // After the server has been connected, send a response. let res = server.conn.stream_send(request_stream_id, HTTP_RESPONSE_2); @@ -4287,19 +4282,19 @@ mod tests { assert!(client.events().any(zerortt_event)); // Send ClientHello. - let client_hs = client.process(None, now()); + let client_hs = client.process_output(now()); assert!(client_hs.as_dgram_ref().is_some()); // Create a request let request_stream_id = make_request(&mut client, false, &[]); assert_eq!(request_stream_id, 0); - let client_0rtt = client.process(None, now()); + let client_0rtt = client.process_output(now()); assert!(client_0rtt.as_dgram_ref().is_some()); - let server_hs = server.process(client_hs.as_dgram_ref(), now()); + let server_hs = server.process(client_hs.dgram(), now()); assert!(server_hs.as_dgram_ref().is_some()); // Should produce ServerHello etc... - let server_ignored = server.process(client_0rtt.as_dgram_ref(), now()); + let server_ignored = server.process(client_0rtt.dgram(), now()); assert!(server_ignored.as_dgram_ref().is_none()); // The server shouldn't receive that 0-RTT data. @@ -4307,7 +4302,7 @@ mod tests { assert!(!server.events().any(recvd_stream_evt)); // Client should get a rejection. - let client_out = client.process(server_hs.as_dgram_ref(), now()); + let client_out = client.process(server_hs.dgram(), now()); assert!(client_out.as_dgram_ref().is_some()); let recvd_0rtt_reject = |e| e == Http3ClientEvent::ZeroRttRejected; assert!(client.events().any(recvd_0rtt_reject)); @@ -4318,7 +4313,7 @@ mod tests { assert_eq!(res.unwrap_err(), Error::InvalidStreamId); // Client will send Setting frame and open new qpack streams. - mem::drop(server.process(client_out.as_dgram_ref(), now())); + mem::drop(server.process(client_out.dgram(), now())); TestServer::new_with_conn(server).check_client_control_qpack_streams_no_resumption(); // Check that we can send a request and that the stream_id starts again from 0. @@ -4345,11 +4340,11 @@ mod tests { .enable_resumption(now(), &token) .expect("Set resumption token."); assert_eq!(client.state(), Http3State::ZeroRtt); - let out = client.process(None, now()); + let out = client.process_output(now()); assert_eq!(client.state(), Http3State::ZeroRtt); assert_eq!(*server.conn.state(), State::Init); - let out = server.conn.process(out.as_dgram_ref(), now()); + let out = server.conn.process(out.dgram(), now()); // Check that control and qpack streams and a SETTINGS frame are received. // Also qpack encoder stream will send "change capacity" instruction because it has @@ -4361,10 +4356,10 @@ mod tests { ); assert_eq!(*server.conn.state(), State::Handshaking); - let out = client.process(out.as_dgram_ref(), now()); + let out = client.process(out.dgram(), now()); assert_eq!(client.state(), Http3State::Connected); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + mem::drop(server.conn.process(out.dgram(), now())); assert!(server.conn.state().connected()); assert!(client.tls_info().unwrap().resumed()); @@ -4379,8 +4374,8 @@ mod tests { sent = server.conn.stream_send(control_stream, enc.as_ref()); assert_eq!(sent.unwrap(), enc.len()); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); assert_eq!(&client.state(), expected_client_state); assert!(server.conn.state().connected()); @@ -4739,8 +4734,8 @@ mod tests { server.conn.stream_close_send(request_stream_id).unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); let events: Vec = client.events().collect(); @@ -4847,7 +4842,7 @@ mod tests { Ok((3, true)) ); - client.process(None, now()); + client.process_output(now()); } #[test] @@ -4956,7 +4951,7 @@ mod tests { _ = server.conn.stream_send(request_stream_id, &[0, 0]).unwrap(); server.conn.stream_close_send(request_stream_id).unwrap(); let dgram = server.conn.process_output(now()).dgram(); - client.process_input(&dgram.unwrap(), now()); + client.process_input(dgram.unwrap(), now()); let data_readable_event = |e: &_| matches!(e, Http3ClientEvent::DataReadable { stream_id } if *stream_id == request_stream_id); assert_eq!(client.events().filter(data_readable_event).count(), 1); @@ -4979,16 +4974,16 @@ mod tests { server.create_control_stream(); // Send the server's control stream data. - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); server.create_qpack_streams(); - let qpack_pkt1 = server.conn.process(None, now()); + let qpack_pkt1 = server.conn.process_output(now()); // delay delivery of this packet. let request_stream_id = make_request(&mut client, true, &[]); - let out = client.process(None, now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.conn.process(out.dgram(), now())); setup_server_side_encoder(&mut client, &mut server); @@ -5007,8 +5002,8 @@ mod tests { }; // Send the encoder instructions, - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); // Send response let mut d = Encoder::default(); @@ -5022,14 +5017,14 @@ mod tests { .unwrap(); server.conn.stream_close_send(request_stream_id).unwrap(); - let out = server.conn.process(None, now()); - mem::drop(client.process(out.as_dgram_ref(), now())); + let out = server.conn.process_output(now()); + mem::drop(client.process(out.dgram(), now())); let header_ready_event = |e| matches!(e, Http3ClientEvent::HeaderReady { .. }); assert!(!client.events().any(header_ready_event)); // Let client receive the encoder instructions. - mem::drop(client.process(qpack_pkt1.as_dgram_ref(), now())); + mem::drop(client.process(qpack_pkt1.dgram(), now())); assert!(client.events().any(header_ready_event)); } @@ -5106,7 +5101,7 @@ mod tests { // Reading push data will stop the client from being idle. _ = send_push_data(&mut server.conn, 0, false); let out = server.conn.process_output(now()); - client.process_input(out.as_dgram_ref().unwrap(), now()); + client.process_input(out.dgram().unwrap(), now()); let mut buf = [0; 16]; let (read, fin) = client.push_read_data(now(), 0, &mut buf).unwrap(); @@ -5415,8 +5410,8 @@ mod tests { let request_stream_id_2 = make_request(&mut client, false, &[]); assert_eq!(request_stream_id_2, 4); - let out = client.process(None, now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.conn.process(out.dgram(), now())); send_push_promise_and_exchange_packets(&mut client, &mut server, request_stream_id_2, 5); @@ -5451,8 +5446,8 @@ mod tests { let request_stream_id_2 = make_request(&mut client, false, &[]); assert_eq!(request_stream_id_2, 4); - let out = client.process(None, now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.conn.process(out.dgram(), now())); send_push_promise_and_exchange_packets(&mut client, &mut server, request_stream_id_2, 5); @@ -5499,8 +5494,8 @@ mod tests { let request_stream_id_2 = make_request(&mut client, false, &[]); assert_eq!(request_stream_id_2, 4); - let out = client.process(None, now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.conn.process(out.dgram(), now())); send_push_promise_and_exchange_packets(&mut client, &mut server, request_stream_id_2, 5); @@ -5592,8 +5587,8 @@ mod tests { request_stream_id, ); - let out = client.process(None, now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.conn.process(out.dgram(), now())); // Check max_push_id frame has been received let control_stream_readable = @@ -5610,9 +5605,9 @@ mod tests { send_push_promise(&mut server.conn, request_stream_id, 8); send_push_data(&mut server.conn, 8, true); - let out = server.conn.process(None, now()); - let out = client.process(out.as_dgram_ref(), now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = server.conn.process_output(now()); + let out = client.process(out.dgram(), now()); + mem::drop(server.conn.process(out.dgram(), now())); assert_eq!(client.state(), Http3State::Connected); @@ -5779,8 +5774,8 @@ mod tests { .conn .stream_reset_send(push_stream_id, Error::HttpRequestCancelled.code()) .unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); // Assert that we do not have any push event. assert!(!check_push_events(&mut client)); @@ -5806,8 +5801,8 @@ mod tests { .conn .stream_reset_send(push_stream_id, Error::HttpRequestCancelled.code()) .unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); send_push_promise_and_exchange_packets(&mut client, &mut server, request_stream_id, 0); @@ -5853,8 +5848,8 @@ mod tests { send_push_data_and_exchange_packets(&mut client, &mut server, 0, false); assert!(client.cancel_push(0).is_ok()); - let out = client.process(None, now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.conn.process(out.dgram(), now())); // Assert that we do not have any push event. assert!(!check_push_events(&mut client)); @@ -5884,8 +5879,8 @@ mod tests { send_push_data_and_exchange_packets(&mut client, &mut server, 0, false); assert!(client.cancel_push(0).is_ok()); - let out = client.process(None, now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.conn.process(out.dgram(), now())); send_push_promise_and_exchange_packets(&mut client, &mut server, request_stream_id, 0); @@ -5926,8 +5921,8 @@ mod tests { .borrow_mut() .send_encoder_updates(&mut server.conn) .unwrap(); - let out = server.conn.process(None, now()); - mem::drop(client.process(out.as_dgram_ref(), now())); + let out = server.conn.process_output(now()); + mem::drop(client.process(out.dgram(), now())); } fn setup_server_side_encoder(client: &mut Http3Client, server: &mut TestServer) { @@ -5977,7 +5972,7 @@ mod tests { // Send the encoder instructions, but delay them so that the stream is blocked on decoding // headers. - let encoder_inst_pkt = server.conn.process(None, now()).dgram(); + let encoder_inst_pkt = server.conn.process_output(now()).dgram(); assert!(encoder_inst_pkt.is_some()); let mut d = Encoder::default(); @@ -6000,7 +5995,7 @@ mod tests { assert!(!check_push_events(&mut client)); // Let client receive the encoder instructions. - let _out = client.process(encoder_inst_pkt.as_ref(), now()); + let _out = client.process(encoder_inst_pkt, now()); // PushPromise is blocked wathing for encoder instructions. assert!(check_push_events(&mut client)); @@ -6040,7 +6035,7 @@ mod tests { assert!(check_data_readable(&mut client)); // Let client receive the encoder instructions. - let _out = client.process(encoder_inst_pkt.as_ref(), now()); + let _out = client.process(encoder_inst_pkt, now()); // PushPromise is blocked wathing for encoder instructions. assert!(check_push_events(&mut client)); @@ -6082,7 +6077,7 @@ mod tests { assert!(check_header_ready(&mut client)); // Let client receive the encoder instructions. - let _out = client.process(encoder_inst_pkt.as_ref(), now()); + let _out = client.process(encoder_inst_pkt, now()); // PushPromise is blocked wathing for encoder instructions. assert!(check_push_events(&mut client)); @@ -6102,8 +6097,8 @@ mod tests { .borrow_mut() .send_and_insert(&mut server.conn, b"content-length", b"1234") .unwrap(); - let encoder_inst_pkt1 = server.conn.process(None, now()).dgram(); - let _out = client.process(encoder_inst_pkt1.as_ref(), now()); + let encoder_inst_pkt1 = server.conn.process_output(now()).dgram(); + let _out = client.process(encoder_inst_pkt1, now()); // Send a PushPromise that is blocked until encoder_inst_pkt2 is process by the client. let encoder_inst_pkt2 = @@ -6138,7 +6133,7 @@ mod tests { assert!(!check_header_ready(&mut client)); // Let client receive the encoder instructions. - let _out = client.process(encoder_inst_pkt2.as_ref(), now()); + let _out = client.process(encoder_inst_pkt2, now()); // The response headers are blocked. assert!(check_header_ready_and_push_promise(&mut client)); @@ -6211,12 +6206,12 @@ mod tests { assert!(!check_header_ready(&mut client)); // Let client receive the encoder instructions. - let _out = client.process(encoder_inst_pkt1.as_ref(), now()); + let _out = client.process(encoder_inst_pkt1, now()); assert!(check_push_events(&mut client)); // Let client receive the encoder instructions. - let _out = client.process(encoder_inst_pkt2.as_ref(), now()); + let _out = client.process(encoder_inst_pkt2, now()); assert!(check_header_ready_and_push_promise(&mut client)); } @@ -6250,8 +6245,8 @@ mod tests { .read_data(now(), request_stream_id, &mut buf) .unwrap(); - let out = client.process(None, now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.conn.process(out.dgram(), now())); // Check that encoder got stream_canceled instruction. let mut inst = [0_u8; 100]; let (amount, fin) = server @@ -6284,7 +6279,7 @@ mod tests { }; // Delay encoder instruction so that the stream will be blocked. - let encoder_insts = server.conn.process(None, now()); + let encoder_insts = server.conn.process_output(now()); // Send response headers. let mut d = Encoder::default(); @@ -6315,7 +6310,7 @@ mod tests { ); // Now read headers. - mem::drop(client.process(encoder_insts.as_dgram_ref(), now())); + mem::drop(client.process(encoder_insts.dgram(), now())); } #[test] @@ -6325,8 +6320,8 @@ mod tests { // Cancel request. mem::drop(client.cancel_fetch(request_stream_id, Error::HttpRequestCancelled.code())); assert_eq!(server.encoder.borrow_mut().stats().stream_cancelled_recv, 0); - let out = client.process(None, now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.conn.process(out.dgram(), now())); mem::drop(server.encoder_receiver.receive(&mut server.conn)); assert_eq!(server.encoder.borrow_mut().stats().stream_cancelled_recv, 1); } @@ -6347,7 +6342,7 @@ mod tests { header_block: encoded_headers.to_vec(), }; - let out = server.conn.process(None, now()); + let out = server.conn.process_output(now()); // Send response let mut d = Encoder::default(); @@ -6373,9 +6368,9 @@ mod tests { .stream_reset_send(request_stream_id, Error::HttpRequestCancelled.code()) .unwrap(); assert_eq!(server.encoder.borrow_mut().stats().stream_cancelled_recv, 0); - let out = server.conn.process(None, now()); - let out = client.process(out.as_dgram_ref(), now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = server.conn.process_output(now()); + let out = client.process(out.dgram(), now()); + mem::drop(server.conn.process(out.dgram(), now())); mem::drop(server.encoder_receiver.receive(&mut server.conn)); assert_eq!(server.encoder.borrow_mut().stats().stream_cancelled_recv, 1); } @@ -6410,8 +6405,8 @@ mod tests { .unwrap(); assert_eq!(server.encoder.borrow_mut().stats().stream_cancelled_recv, 0); - let out = client.process(None, now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.conn.process(out.dgram(), now())); mem::drop(server.encoder_receiver.receive(&mut server.conn).unwrap()); assert_eq!(server.encoder.borrow_mut().stats().stream_cancelled_recv, 1); } @@ -6435,7 +6430,7 @@ mod tests { ); // Exchange encoder instructions - mem::drop(client.process(encoder_instruct.as_ref(), now())); + mem::drop(client.process(encoder_instruct, now())); let header_ready_event = |e| matches!(e, Http3ClientEvent::HeaderReady { .. }); assert!(client.events().any(header_ready_event)); @@ -6447,8 +6442,8 @@ mod tests { .unwrap(); assert_eq!(server.encoder.borrow_mut().stats().stream_cancelled_recv, 0); - let out = client.process(None, now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.conn.process(out.dgram(), now())); mem::drop(server.encoder_receiver.receive(&mut server.conn).unwrap()); assert_eq!(server.encoder.borrow_mut().stats().stream_cancelled_recv, 0); } @@ -6473,8 +6468,8 @@ mod tests { }; // Send the encoder instructions. - let out = server.conn.process(None, now()); - mem::drop(client.process(out.as_dgram_ref(), now())); + let out = server.conn.process_output(now()); + mem::drop(client.process(out.dgram(), now())); // Send PushPromise that will be blocked waiting for decoder instructions. mem::drop( @@ -6503,8 +6498,8 @@ mod tests { .cancel_fetch(request_stream_id, Error::HttpRequestCancelled.code()) .unwrap(); - let out = client.process(None, now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.conn.process(out.dgram(), now())); mem::drop(server.encoder_receiver.receive(&mut server.conn).unwrap()); assert_eq!(server.encoder.borrow_mut().stats().stream_cancelled_recv, 1); } @@ -6517,8 +6512,8 @@ mod tests { .cancel_fetch(request_stream_id, Error::HttpRequestCancelled.code()) .unwrap(); assert_eq!(server.encoder.borrow_mut().stats().stream_cancelled_recv, 0); - let out = client.process(None, now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.conn.process(out.dgram(), now())); mem::drop(server.encoder_receiver.receive(&mut server.conn).unwrap()); assert_eq!(server.encoder.borrow_mut().stats().stream_cancelled_recv, 0); } @@ -6544,7 +6539,7 @@ mod tests { }; // Delay encoder instruction so that the stream will be blocked. - let encoder_insts = server.conn.process(None, now()); + let encoder_insts = server.conn.process_output(now()); // Send response headers. let mut d = Encoder::default(); @@ -6571,7 +6566,7 @@ mod tests { assert!(!client.events().any(header_ready_event)); // Now make the encoder instructions available. - mem::drop(client.process(encoder_insts.as_dgram_ref(), now())); + mem::drop(client.process(encoder_insts.dgram(), now())); // Header blocks for both streams should be ready. let mut count_responses = 0; @@ -6614,8 +6609,8 @@ mod tests { enc.encode_varint(1_u64); let sent = server.conn.stream_send(control_stream, enc.as_ref()); assert_eq!(sent, Ok(4)); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); assert_closed(&client, &Error::HttpSettings); } } @@ -6715,8 +6710,8 @@ mod tests { } ); - let out = client.process(None, now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.conn.process(out.dgram(), now())); // Check that server has received a reset. let stop_sending_event = |e| { @@ -6848,8 +6843,8 @@ mod tests { assert!(client.events().any(push_reset_event)); - let out = client.process(None, now()); - mem::drop(server.conn.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.conn.process(out.dgram(), now())); // Check that server has received a reset. let stop_sending_event = |e| { @@ -6863,7 +6858,7 @@ mod tests { fn handshake_client_error(client: &mut Http3Client, server: &mut TestServer, error: &Error) { let out = handshake_only(client, server); - client.process(out.as_dgram_ref(), now()); + client.process(out.dgram(), now()); assert_closed(client, error); } @@ -7024,14 +7019,14 @@ mod tests { let is_done = |c: &Http3Client| matches!(c.state(), Http3State::Connected); while !is_done(&mut client) { maybe_authenticate(&mut client); - datagram = client.process(datagram.as_ref(), now()).dgram(); - datagram = server.process(datagram.as_ref(), now()).dgram(); + datagram = client.process(datagram, now()).dgram(); + datagram = server.process(datagram, now()).dgram(); } // exchange qpack settings, server will send a token as well. - datagram = client.process(datagram.as_ref(), now()).dgram(); - datagram = server.process(datagram.as_ref(), now()).dgram(); - mem::drop(client.process(datagram.as_ref(), now()).dgram()); + datagram = client.process(datagram, now()).dgram(); + datagram = server.process(datagram, now()).dgram(); + mem::drop(client.process(datagram, now()).dgram()); client .events() @@ -7085,15 +7080,15 @@ mod tests { // Exchange packets until header-ack is received. // These many packet exchange is needed, to get a header-ack. // TODO this may be optimize at Http3Server. - let out = client.process(None, now()); - let out = server.process(out.as_dgram_ref(), now()); - let out = client.process(out.as_dgram_ref(), now()); - let out = server.process(out.as_dgram_ref(), now()); - let out = client.process(out.as_dgram_ref(), now()); - let out = server.process(out.as_dgram_ref(), now()); - let out = client.process(out.as_dgram_ref(), now()); - let out = server.process(out.as_dgram_ref(), now()); - mem::drop(client.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + let out = server.process(out.dgram(), now()); + let out = client.process(out.dgram(), now()); + let out = server.process(out.dgram(), now()); + let out = client.process(out.dgram(), now()); + let out = server.process(out.dgram(), now()); + let out = client.process(out.dgram(), now()); + let out = server.process(out.dgram(), now()); + mem::drop(client.process(out.dgram(), now())); // The header ack for the first request has been received. assert_eq!(client.qpack_encoder_stats().header_acks_recv, 1); @@ -7148,8 +7143,8 @@ mod tests { .unwrap(); _ = server.conn.stream_send(push_stream_id, &[0]).unwrap(); server.conn.stream_close_send(push_stream_id).unwrap(); - let out = server.conn.process(None, now()); - client.process(out.as_dgram_ref(), now()); + let out = server.conn.process_output(now()); + client.process(out.dgram(), now()); assert_closed(&client, &Error::HttpGeneralProtocol); } @@ -7174,14 +7169,14 @@ mod tests { let md_before = server.conn.stats().frame_tx.max_data; // sending the http request and most most of the request data - let out = client.process(None, now()); - let out = server.conn.process(out.as_dgram_ref(), now()); + let out = client.process_output(now()); + let out = server.conn.process(out.dgram(), now()); // the server responses with an ack, but the max_data didn't change assert_eq!(md_before, server.conn.stats().frame_tx.max_data); - let out = client.process(out.as_dgram_ref(), now()); - let out = server.conn.process(out.as_dgram_ref(), now()); + let out = client.process(out.dgram(), now()); + let out = server.conn.process(out.dgram(), now()); // the server increased the max_data during the second read if that isn't the case // in the future and therefore this asserts fails, the request data on stream 0 could be @@ -7197,10 +7192,8 @@ mod tests { ); // the client now sends the priority update - let out = client.process(out.as_dgram_ref(), now()); - server - .conn - .process_input(out.as_dgram_ref().unwrap(), now()); + let out = client.process(out.dgram(), now()); + server.conn.process_input(out.dgram().unwrap(), now()); // check that the priority_update arrived at the client control stream let num_read = server.conn.stream_recv(StreamId::new(2), &mut buf).unwrap(); @@ -7230,7 +7223,7 @@ mod tests { // Send the encoder instructions, but delay them so that the stream is blocked on decoding // headers. - let encoder_inst_pkt = server.conn.process(None, now()); + let encoder_inst_pkt = server.conn.process_output(now()); // Send response let mut d = Encoder::default(); @@ -7247,7 +7240,7 @@ mod tests { ); // Let client receive the encoder instructions. - client.process_input(encoder_inst_pkt.as_dgram_ref().unwrap(), now()); + client.process_input(encoder_inst_pkt.dgram().unwrap(), now()); let reset_event = |e| matches!(e, Http3ClientEvent::Reset { stream_id, .. } if stream_id == request_stream_id); assert!(client.events().any(reset_event)); diff --git a/neqo-http3/src/features/extended_connect/tests/webtransport/mod.rs b/neqo-http3/src/features/extended_connect/tests/webtransport/mod.rs index 1aae3d97e4..4b23277cbc 100644 --- a/neqo-http3/src/features/extended_connect/tests/webtransport/mod.rs +++ b/neqo-http3/src/features/extended_connect/tests/webtransport/mod.rs @@ -63,8 +63,8 @@ pub fn default_http3_server(server_params: Http3Parameters) -> Http3Server { fn exchange_packets(client: &mut Http3Client, server: &mut Http3Server) { let mut out = None; loop { - out = client.process(out.as_ref(), now()).dgram(); - out = server.process(out.as_ref(), now()).dgram(); + out = client.process(out, now()).dgram(); + out = server.process(out, now()).dgram(); if out.is_none() { break; } @@ -74,31 +74,31 @@ fn exchange_packets(client: &mut Http3Client, server: &mut Http3Server) { // Perform only Quic transport handshake. fn connect_with(client: &mut Http3Client, server: &mut Http3Server) { assert_eq!(client.state(), Http3State::Initializing); - let out = client.process(None, now()); + let out = client.process_output(now()); assert_eq!(client.state(), Http3State::Initializing); - let out = server.process(out.as_dgram_ref(), now()); - let out = client.process(out.as_dgram_ref(), now()); - let out = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); + let out = client.process(out.dgram(), now()); + let out = server.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_none()); let authentication_needed = |e| matches!(e, Http3ClientEvent::AuthenticationNeeded); assert!(client.events().any(authentication_needed)); client.authenticated(AuthenticationStatus::Ok, now()); - let out = client.process(out.as_dgram_ref(), now()); + let out = client.process(out.dgram(), now()); let connected = |e| matches!(e, Http3ClientEvent::StateChange(Http3State::Connected)); assert!(client.events().any(connected)); assert_eq!(client.state(), Http3State::Connected); // Exchange H3 setttings - let out = server.process(out.as_dgram_ref(), now()); - let out = client.process(out.as_dgram_ref(), now()); - let out = server.process(out.as_dgram_ref(), now()); - let out = client.process(out.as_dgram_ref(), now()); - let out = server.process(out.as_dgram_ref(), now()); - std::mem::drop(client.process(out.as_dgram_ref(), now())); + let out = server.process(out.dgram(), now()); + let out = client.process(out.dgram(), now()); + let out = server.process(out.dgram(), now()); + let out = client.process(out.dgram(), now()); + let out = server.process(out.dgram(), now()); + std::mem::drop(client.process(out.dgram(), now())); } fn connect( @@ -200,10 +200,10 @@ impl WtTest { let mut now = now(); loop { now += RTT / 2; - out = self.client.process(out.as_ref(), now).dgram(); + out = self.client.process(out, now).dgram(); let client_none = out.is_none(); now += RTT / 2; - out = self.server.process(out.as_ref(), now).dgram(); + out = self.server.process(out, now).dgram(); if client_none && out.is_none() { break; } diff --git a/neqo-http3/src/features/extended_connect/tests/webtransport/negotiation.rs b/neqo-http3/src/features/extended_connect/tests/webtransport/negotiation.rs index eb316efee5..82ec1328a7 100644 --- a/neqo-http3/src/features/extended_connect/tests/webtransport/negotiation.rs +++ b/neqo-http3/src/features/extended_connect/tests/webtransport/negotiation.rs @@ -86,9 +86,9 @@ fn zero_rtt( assert_eq!(client.webtransport_enabled(), client_org && server_org); // exchange token - let out = server.process(None, now()); + let out = server.process_output(now()); // We do not have a token so we need to wait for a resumption token timer to trigger. - std::mem::drop(client.process(out.as_dgram_ref(), now() + Duration::from_millis(250))); + std::mem::drop(client.process(out.dgram(), now() + Duration::from_millis(250))); assert_eq!(client.state(), Http3State::Connected); let token = client .events() @@ -233,8 +233,8 @@ fn zero_rtt_wt_settings() { fn exchange_packets2(client: &mut Http3Client, server: &mut Connection) { let mut out = None; loop { - out = client.process(out.as_ref(), now()).dgram(); - out = server.process(out.as_ref(), now()).dgram(); + out = client.process(out, now()).dgram(); + out = server.process(out, now()).dgram(); if out.is_none() { break; } diff --git a/neqo-http3/src/features/extended_connect/tests/webtransport/sessions.rs b/neqo-http3/src/features/extended_connect/tests/webtransport/sessions.rs index d184f2d6a2..821d8ac5e3 100644 --- a/neqo-http3/src/features/extended_connect/tests/webtransport/sessions.rs +++ b/neqo-http3/src/features/extended_connect/tests/webtransport/sessions.rs @@ -425,18 +425,18 @@ fn wt_close_session_cannot_be_sent_at_once() { Err(Error::InvalidStreamId) ); - let out = wt.server.process(None, now()); - let out = wt.client.process(out.as_dgram_ref(), now()); + let out = wt.server.process_output(now()); + let out = wt.client.process(out.dgram(), now()); // Client has not received the full CloseSession frame and it can create more streams. let unidi_client = wt.create_wt_stream_client(wt_session.stream_id(), StreamType::UniDi); - let out = wt.server.process(out.as_dgram_ref(), now()); - let out = wt.client.process(out.as_dgram_ref(), now()); - let out = wt.server.process(out.as_dgram_ref(), now()); - let out = wt.client.process(out.as_dgram_ref(), now()); - let out = wt.server.process(out.as_dgram_ref(), now()); - let _out = wt.client.process(out.as_dgram_ref(), now()); + let out = wt.server.process(out.dgram(), now()); + let out = wt.client.process(out.dgram(), now()); + let out = wt.server.process(out.dgram(), now()); + let out = wt.client.process(out.dgram(), now()); + let out = wt.server.process(out.dgram(), now()); + let _out = wt.client.process(out.dgram(), now()); wt.check_events_after_closing_session_client( &[], diff --git a/neqo-http3/src/frames/tests/mod.rs b/neqo-http3/src/frames/tests/mod.rs index e0c13279ba..5c863242ff 100644 --- a/neqo-http3/src/frames/tests/mod.rs +++ b/neqo-http3/src/frames/tests/mod.rs @@ -22,13 +22,13 @@ pub fn enc_dec>(d: &Encoder, st: &str, remaining: usize) -> T let mut conn_c = default_client(); let mut conn_s = default_server(); - let out = conn_c.process(None, now()); - let out = conn_s.process(out.as_dgram_ref(), now()); - let out = conn_c.process(out.as_dgram_ref(), now()); - mem::drop(conn_s.process(out.as_dgram_ref(), now())); + let out = conn_c.process_output(now()); + let out = conn_s.process(out.dgram(), now()); + let out = conn_c.process(out.dgram(), now()); + mem::drop(conn_s.process(out.dgram(), now())); conn_c.authenticated(AuthenticationStatus::Ok, now()); - let out = conn_c.process(None, now()); - mem::drop(conn_s.process(out.as_dgram_ref(), now())); + let out = conn_c.process_output(now()); + mem::drop(conn_s.process(out.dgram(), now())); // create a stream let stream_id = conn_s.stream_create(StreamType::BiDi).unwrap(); @@ -38,8 +38,8 @@ pub fn enc_dec>(d: &Encoder, st: &str, remaining: usize) -> T // conver string into u8 vector let buf = Encoder::from_hex(st); conn_s.stream_send(stream_id, buf.as_ref()).unwrap(); - let out = conn_s.process(None, now()); - mem::drop(conn_c.process(out.as_dgram_ref(), now())); + let out = conn_s.process_output(now()); + mem::drop(conn_c.process(out.dgram(), now())); let (frame, fin) = fr .receive::(&mut StreamReaderConnectionWrapper::new( diff --git a/neqo-http3/src/frames/tests/reader.rs b/neqo-http3/src/frames/tests/reader.rs index dd4448f49f..46e236ce55 100644 --- a/neqo-http3/src/frames/tests/reader.rs +++ b/neqo-http3/src/frames/tests/reader.rs @@ -39,8 +39,8 @@ impl FrameReaderTest { fn process>(&mut self, v: &[u8]) -> Option { self.conn_s.stream_send(self.stream_id, v).unwrap(); - let out = self.conn_s.process(None, now()); - mem::drop(self.conn_c.process(out.as_dgram_ref(), now())); + let out = self.conn_s.process_output(now()); + mem::drop(self.conn_c.process(out.dgram(), now())); let (frame, fin) = self .fr .receive::(&mut StreamReaderConnectionWrapper::new( @@ -230,13 +230,13 @@ fn test_reading_frame + PartialEq + Debug>( fr.conn_s.stream_close_send(fr.stream_id).unwrap(); } - let out = fr.conn_s.process(None, now()); - mem::drop(fr.conn_c.process(out.as_dgram_ref(), now())); + let out = fr.conn_s.process_output(now()); + mem::drop(fr.conn_c.process(out.dgram(), now())); if matches!(test_to_send, FrameReadingTestSend::DataThenFin) { fr.conn_s.stream_close_send(fr.stream_id).unwrap(); - let out = fr.conn_s.process(None, now()); - mem::drop(fr.conn_c.process(out.as_dgram_ref(), now())); + let out = fr.conn_s.process_output(now()); + mem::drop(fr.conn_c.process(out.dgram(), now())); } let rv = fr.fr.receive::(&mut StreamReaderConnectionWrapper::new( @@ -478,12 +478,12 @@ fn frame_reading_when_stream_is_closed_before_sending_data() { let mut fr = FrameReaderTest::new(); fr.conn_s.stream_send(fr.stream_id, &[0x00]).unwrap(); - let out = fr.conn_s.process(None, now()); - mem::drop(fr.conn_c.process(out.as_dgram_ref(), now())); + let out = fr.conn_s.process_output(now()); + mem::drop(fr.conn_c.process(out.dgram(), now())); assert_eq!(Ok(()), fr.conn_c.stream_close_send(fr.stream_id)); - let out = fr.conn_c.process(None, now()); - mem::drop(fr.conn_s.process(out.as_dgram_ref(), now())); + let out = fr.conn_c.process_output(now()); + mem::drop(fr.conn_s.process(out.dgram(), now())); assert_eq!( Ok((None, true)), fr.fr @@ -501,12 +501,12 @@ fn wt_frame_reading_when_stream_is_closed_before_sending_data() { let mut fr = FrameReaderTest::new(); fr.conn_s.stream_send(fr.stream_id, &[0x00]).unwrap(); - let out = fr.conn_s.process(None, now()); - mem::drop(fr.conn_c.process(out.as_dgram_ref(), now())); + let out = fr.conn_s.process_output(now()); + mem::drop(fr.conn_c.process(out.dgram(), now())); assert_eq!(Ok(()), fr.conn_c.stream_close_send(fr.stream_id)); - let out = fr.conn_c.process(None, now()); - mem::drop(fr.conn_s.process(out.as_dgram_ref(), now())); + let out = fr.conn_c.process_output(now()); + mem::drop(fr.conn_s.process(out.dgram(), now())); assert_eq!( Ok((None, true)), fr.fr diff --git a/neqo-http3/src/server.rs b/neqo-http3/src/server.rs index bfc1fa2630..798fd7c70c 100644 --- a/neqo-http3/src/server.rs +++ b/neqo-http3/src/server.rs @@ -113,7 +113,12 @@ impl Http3Server { self.server.ech_config() } - pub fn process(&mut self, dgram: Option<&Datagram>, now: Instant) -> Output { + /// Short-hand for [`Http3Server::process`] with no input datagram. + pub fn process_output(&mut self, now: Instant) -> Output { + self.process(None::, now) + } + + pub fn process(&mut self, dgram: Option>>, now: Instant) -> Output { qtrace!([self], "Process."); let out = self.server.process(dgram, now); self.process_http3(now); @@ -123,7 +128,7 @@ impl Http3Server { qtrace!([self], "Send packet: {:?}", d); Output::Datagram(d) } - _ => self.server.process(Option::<&Datagram>::None, now), + _ => self.server.process(Option::::None, now), } } @@ -396,29 +401,29 @@ mod tests { const SERVER_SIDE_DECODER_STREAM_ID: StreamId = StreamId::new(11); fn connect_transport(server: &mut Http3Server, client: &mut Connection, resume: bool) { - let c1 = client.process(None, now()); - let s1 = server.process(c1.as_dgram_ref(), now()); - let c2 = client.process(s1.as_dgram_ref(), now()); + let c1 = client.process_output(now()); + let s1 = server.process(c1.dgram(), now()); + let c2 = client.process(s1.dgram(), now()); let needs_auth = client .events() .any(|e| e == ConnectionEvent::AuthenticationNeeded); let c2 = if needs_auth { assert!(!resume); // c2 should just be an ACK, so absorb that. - let s_ack = server.process(c2.as_dgram_ref(), now()); - assert!(s_ack.as_dgram_ref().is_none()); + let s_ack = server.process(c2.dgram(), now()); + assert!(s_ack.dgram().is_none()); client.authenticated(AuthenticationStatus::Ok, now()); - client.process(None, now()) + client.process_output(now()) } else { assert!(resume); c2 }; assert!(client.state().connected()); - let s2 = server.process(c2.as_dgram_ref(), now()); + let s2 = server.process(c2.dgram(), now()); assert_connected(server); - let c3 = client.process(s2.as_dgram_ref(), now()); - assert!(c3.as_dgram_ref().is_none()); + let c3 = client.process(s2.dgram(), now()); + assert!(c3.dgram().is_none()); } // Start a client/server and check setting frame. @@ -552,9 +557,9 @@ mod tests { let decoder_stream = neqo_trans_conn.stream_create(StreamType::UniDi).unwrap(); sent = neqo_trans_conn.stream_send(decoder_stream, &[0x3]); assert_eq!(sent, Ok(1)); - let out1 = neqo_trans_conn.process(None, now()); - let out2 = server.process(out1.as_dgram_ref(), now()); - mem::drop(neqo_trans_conn.process(out2.as_dgram_ref(), now())); + let out1 = neqo_trans_conn.process_output(now()); + let out2 = server.process(out1.dgram(), now()); + mem::drop(neqo_trans_conn.process(out2.dgram(), now())); // assert no error occured. assert_not_closed(server); @@ -584,8 +589,8 @@ mod tests { let (mut hconn, mut peer_conn) = connect(); let control = peer_conn.control_stream_id; peer_conn.stream_close_send(control).unwrap(); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); assert_closed(&hconn, &Error::HttpClosedCriticalStream); } @@ -599,8 +604,8 @@ mod tests { // Send a MAX_PUSH_ID frame instead. let sent = neqo_trans_conn.stream_send(control_stream, &[0x0, 0xd, 0x1, 0xf]); assert_eq!(sent, Ok(4)); - let out = neqo_trans_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = neqo_trans_conn.process_output(now()); + hconn.process(out.dgram(), now()); assert_closed(&hconn, &Error::HttpMissingSettings); } @@ -611,8 +616,8 @@ mod tests { let (mut hconn, mut peer_conn) = connect(); // send the second SETTINGS frame. peer_conn.control_send(&[0x4, 0x6, 0x1, 0x40, 0x64, 0x7, 0x40, 0x64]); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); assert_closed(&hconn, &Error::HttpFrameUnexpected); } @@ -626,8 +631,8 @@ mod tests { let mut e = Encoder::default(); frame.encode(&mut e); peer_conn.control_send(e.as_ref()); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); // check if the given connection got closed on invalid stream ids if valid { assert_not_closed(&hconn); @@ -669,8 +674,8 @@ mod tests { // receive a frame that is not allowed on the control stream. peer_conn.control_send(v); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); assert_closed(&hconn, &Error::HttpFrameUnexpected); } @@ -703,11 +708,11 @@ mod tests { _ = peer_conn .stream_send(new_stream_id, &[0x41, 0x19, 0x4, 0x4, 0x6, 0x0, 0x8, 0x0]) .unwrap(); - let out = peer_conn.process(None, now()); - let out = hconn.process(out.as_dgram_ref(), now()); - mem::drop(peer_conn.process(out.as_dgram_ref(), now())); - let out = hconn.process(None, now()); - mem::drop(peer_conn.process(out.as_dgram_ref(), now())); + let out = peer_conn.process_output(now()); + let out = hconn.process(out.dgram(), now()); + mem::drop(peer_conn.process(out.dgram(), now())); + let out = hconn.process_output(now()); + mem::drop(peer_conn.process(out.dgram(), now())); // check for stop-sending with Error::HttpStreamCreation. let mut stop_sending_event_found = false; @@ -734,9 +739,9 @@ mod tests { // create a push stream. let push_stream_id = peer_conn.stream_create(StreamType::UniDi).unwrap(); _ = peer_conn.stream_send(push_stream_id, &[0x1]).unwrap(); - let out = peer_conn.process(None, now()); - let out = hconn.process(out.as_dgram_ref(), now()); - mem::drop(peer_conn.conn.process(out.as_dgram_ref(), now())); + let out = peer_conn.process_output(now()); + let out = hconn.process(out.dgram(), now()); + mem::drop(peer_conn.conn.process(out.dgram(), now())); assert_closed(&hconn, &Error::HttpStreamCreation); } @@ -751,77 +756,77 @@ mod tests { // send the stream type let mut sent = peer_conn.stream_send(control_stream, &[0x0]); assert_eq!(sent, Ok(1)); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); // start sending SETTINGS frame sent = peer_conn.stream_send(control_stream, &[0x4]); assert_eq!(sent, Ok(1)); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); sent = peer_conn.stream_send(control_stream, &[0x4]); assert_eq!(sent, Ok(1)); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); sent = peer_conn.stream_send(control_stream, &[0x6]); assert_eq!(sent, Ok(1)); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); sent = peer_conn.stream_send(control_stream, &[0x0]); assert_eq!(sent, Ok(1)); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); sent = peer_conn.stream_send(control_stream, &[0x8]); assert_eq!(sent, Ok(1)); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); sent = peer_conn.stream_send(control_stream, &[0x0]); assert_eq!(sent, Ok(1)); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); assert_not_closed(&hconn); // Now test PushPromise sent = peer_conn.stream_send(control_stream, &[0x5]); assert_eq!(sent, Ok(1)); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); sent = peer_conn.stream_send(control_stream, &[0x5]); assert_eq!(sent, Ok(1)); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); sent = peer_conn.stream_send(control_stream, &[0x4]); assert_eq!(sent, Ok(1)); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); sent = peer_conn.stream_send(control_stream, &[0x61]); assert_eq!(sent, Ok(1)); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); sent = peer_conn.stream_send(control_stream, &[0x62]); assert_eq!(sent, Ok(1)); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); sent = peer_conn.stream_send(control_stream, &[0x63]); assert_eq!(sent, Ok(1)); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); sent = peer_conn.stream_send(control_stream, &[0x64]); assert_eq!(sent, Ok(1)); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); // PUSH_PROMISE on a control stream will cause an error assert_closed(&hconn, &Error::HttpFrameUnexpected); @@ -836,8 +841,8 @@ mod tests { peer_conn.stream_send(stream_id, res).unwrap(); peer_conn.stream_close_send(stream_id).unwrap(); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); assert_closed(&hconn, &Error::HttpFrame); } @@ -888,8 +893,8 @@ mod tests { peer_conn.stream_send(stream_id, REQUEST_WITH_BODY).unwrap(); peer_conn.stream_close_send(stream_id).unwrap(); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); // Check connection event. There should be 1 Header and 2 data events. let mut headers_frames = 0; @@ -935,8 +940,8 @@ mod tests { .stream_send(stream_id, &REQUEST_WITH_BODY[..20]) .unwrap(); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); // Check connection event. There should be 1 Header and no data events. let mut headers_frames = 0; @@ -972,7 +977,7 @@ mod tests { | Http3ServerEvent::WebTransport(_) => {} } } - let out = hconn.process(None, now()); + let out = hconn.process_output(now()); // Send data. peer_conn @@ -980,8 +985,8 @@ mod tests { .unwrap(); peer_conn.stream_close_send(stream_id).unwrap(); - let out = peer_conn.process(out.as_dgram_ref(), now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process(out.dgram(), now()); + hconn.process(out.dgram(), now()); while let Some(event) = hconn.next_event() { match event { @@ -1012,8 +1017,8 @@ mod tests { .stream_send(request_stream_id, &REQUEST_WITH_BODY[..20]) .unwrap(); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); // Check connection event. There should be 1 Header and no data events. // The server will reset the stream. @@ -1043,10 +1048,10 @@ mod tests { | Http3ServerEvent::WebTransport(_) => {} } } - let out = hconn.process(None, now()); + let out = hconn.process_output(now()); - let out = peer_conn.process(out.as_dgram_ref(), now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process(out.dgram(), now()); + hconn.process(out.dgram(), now()); // Check that STOP_SENDING and REET has been received. let mut reset = 0; @@ -1077,8 +1082,8 @@ mod tests { peer_conn .stream_reset_send(CLIENT_SIDE_CONTROL_STREAM_ID, Error::HttpNoError.code()) .unwrap(); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); assert_closed(&hconn, &Error::HttpClosedCriticalStream); } @@ -1090,8 +1095,8 @@ mod tests { peer_conn .stream_reset_send(CLIENT_SIDE_ENCODER_STREAM_ID, Error::HttpNoError.code()) .unwrap(); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); assert_closed(&hconn, &Error::HttpClosedCriticalStream); } @@ -1103,8 +1108,8 @@ mod tests { peer_conn .stream_reset_send(CLIENT_SIDE_DECODER_STREAM_ID, Error::HttpNoError.code()) .unwrap(); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); assert_closed(&hconn, &Error::HttpClosedCriticalStream); } @@ -1117,8 +1122,8 @@ mod tests { peer_conn .stream_stop_sending(SERVER_SIDE_CONTROL_STREAM_ID, Error::HttpNoError.code()) .unwrap(); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); assert_closed(&hconn, &Error::HttpClosedCriticalStream); } @@ -1130,8 +1135,8 @@ mod tests { peer_conn .stream_stop_sending(SERVER_SIDE_ENCODER_STREAM_ID, Error::HttpNoError.code()) .unwrap(); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); assert_closed(&hconn, &Error::HttpClosedCriticalStream); } @@ -1143,8 +1148,8 @@ mod tests { peer_conn .stream_stop_sending(SERVER_SIDE_DECODER_STREAM_ID, Error::HttpNoError.code()) .unwrap(); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); assert_closed(&hconn, &Error::HttpClosedCriticalStream); } @@ -1251,8 +1256,8 @@ mod tests { .stream_send(request_stream_id_2, REQUEST_WITH_BODY) .unwrap(); - let out = peer_conn.process(None, now()); - hconn.process(out.as_dgram_ref(), now()); + let out = peer_conn.process_output(now()); + hconn.process(out.dgram(), now()); let mut requests = HashMap::new(); while let Some(event) = hconn.next_event() { diff --git a/neqo-http3/src/stream_type_reader.rs b/neqo-http3/src/stream_type_reader.rs index 220a3dd22c..8ab8e404b3 100644 --- a/neqo-http3/src/stream_type_reader.rs +++ b/neqo-http3/src/stream_type_reader.rs @@ -268,8 +268,8 @@ mod tests { let (mut conn_c, mut conn_s) = connect(); // create a stream let stream_id = conn_s.stream_create(stream_type).unwrap(); - let out = conn_s.process(None, now()); - mem::drop(conn_c.process(out.as_dgram_ref(), now())); + let out = conn_s.process_output(now()); + mem::drop(conn_c.process(out.dgram(), now())); Self { conn_c, @@ -291,8 +291,8 @@ mod tests { self.conn_s .stream_send(self.stream_id, &enc[i..=i]) .unwrap(); - let out = self.conn_s.process(None, now()); - mem::drop(self.conn_c.process(out.as_dgram_ref(), now())); + let out = self.conn_s.process_output(now()); + mem::drop(self.conn_c.process(out.dgram(), now())); assert_eq!( self.decoder.receive(&mut self.conn_c).unwrap(), (ReceiveOutput::NoOutput, false) @@ -305,8 +305,8 @@ mod tests { if fin { self.conn_s.stream_close_send(self.stream_id).unwrap(); } - let out = self.conn_s.process(None, now()); - mem::drop(self.conn_c.process(out.dgram().as_ref(), now())); + let out = self.conn_s.process_output(now()); + mem::drop(self.conn_c.process(out.dgram(), now())); assert_eq!(&self.decoder.receive(&mut self.conn_c), outcome); assert_eq!(self.decoder.done(), done); } diff --git a/neqo-http3/tests/httpconn.rs b/neqo-http3/tests/httpconn.rs index 963844009f..5e192e01cc 100644 --- a/neqo-http3/tests/httpconn.rs +++ b/neqo-http3/tests/httpconn.rs @@ -94,20 +94,20 @@ fn process_client_events(conn: &mut Http3Client) { fn connect_peers(hconn_c: &mut Http3Client, hconn_s: &mut Http3Server) -> Option { assert_eq!(hconn_c.state(), Http3State::Initializing); - let out = hconn_c.process(None, now()); // Initial - let out = hconn_s.process(out.as_dgram_ref(), now()); // Initial + Handshake - let out = hconn_c.process(out.as_dgram_ref(), now()); // ACK - mem::drop(hconn_s.process(out.as_dgram_ref(), now())); // consume ACK + let out = hconn_c.process_output(now()); // Initial + let out = hconn_s.process(out.dgram(), now()); // Initial + Handshake + let out = hconn_c.process(out.dgram(), now()); // ACK + mem::drop(hconn_s.process(out.dgram(), now())); // consume ACK let authentication_needed = |e| matches!(e, Http3ClientEvent::AuthenticationNeeded); assert!(hconn_c.events().any(authentication_needed)); hconn_c.authenticated(AuthenticationStatus::Ok, now()); - let out = hconn_c.process(None, now()); // Handshake + let out = hconn_c.process_output(now()); // Handshake assert_eq!(hconn_c.state(), Http3State::Connected); - let out = hconn_s.process(out.as_dgram_ref(), now()); // Handshake - let out = hconn_c.process(out.as_dgram_ref(), now()); - let out = hconn_s.process(out.as_dgram_ref(), now()); + let out = hconn_s.process(out.dgram(), now()); // Handshake + let out = hconn_c.process(out.dgram(), now()); + let out = hconn_s.process(out.dgram(), now()); // assert!(hconn_s.settings_received); - let out = hconn_c.process(out.as_dgram_ref(), now()); + let out = hconn_c.process(out.dgram(), now()); // assert!(hconn_c.settings_received); out.dgram() @@ -121,28 +121,28 @@ fn connect_peers_with_network_propagation_delay( let net_delay = Duration::from_millis(net_delay); assert_eq!(hconn_c.state(), Http3State::Initializing); let mut now = now(); - let out = hconn_c.process(None, now); // Initial + let out = hconn_c.process_output(now); // Initial now += net_delay; - let out = hconn_s.process(out.as_dgram_ref(), now); // Initial + Handshake + let out = hconn_s.process(out.dgram(), now); // Initial + Handshake now += net_delay; - let out = hconn_c.process(out.as_dgram_ref(), now); // ACK + let out = hconn_c.process(out.dgram(), now); // ACK now += net_delay; - let out = hconn_s.process(out.as_dgram_ref(), now); // consume ACK + let out = hconn_s.process(out.dgram(), now); // consume ACK assert!(out.dgram().is_none()); let authentication_needed = |e| matches!(e, Http3ClientEvent::AuthenticationNeeded); assert!(hconn_c.events().any(authentication_needed)); now += net_delay; hconn_c.authenticated(AuthenticationStatus::Ok, now); - let out = hconn_c.process(None, now); // Handshake + let out = hconn_c.process_output(now); // Handshake assert_eq!(hconn_c.state(), Http3State::Connected); now += net_delay; - let out = hconn_s.process(out.as_dgram_ref(), now); // HANDSHAKE_DONE + let out = hconn_s.process(out.dgram(), now); // HANDSHAKE_DONE now += net_delay; - let out = hconn_c.process(out.as_dgram_ref(), now); // Consume HANDSHAKE_DONE, send control streams. + let out = hconn_c.process(out.dgram(), now); // Consume HANDSHAKE_DONE, send control streams. now += net_delay; - let out = hconn_s.process(out.as_dgram_ref(), now); // consume and send control streams. + let out = hconn_s.process(out.dgram(), now); // consume and send control streams. now += net_delay; - let out = hconn_c.process(out.as_dgram_ref(), now); // consume control streams. + let out = hconn_c.process(out.dgram(), now); // consume control streams. (out.dgram(), now) } @@ -157,8 +157,8 @@ fn connect() -> (Http3Client, Http3Server, Option) { fn exchange_packets(client: &mut Http3Client, server: &mut Http3Server, out_ex: Option) { let mut out = out_ex; loop { - out = client.process(out.as_ref(), now()).dgram(); - out = server.process(out.as_ref(), now()).dgram(); + out = client.process(out, now()).dgram(); + out = server.process(out, now()).dgram(); if out.is_none() { break; } @@ -186,17 +186,17 @@ fn fetch() { .unwrap(); assert_eq!(req, 0); hconn_c.stream_close_send(req).unwrap(); - let out = hconn_c.process(dgram.as_ref(), now()); + let out = hconn_c.process(dgram, now()); qtrace!("-----server"); - let out = hconn_s.process(out.as_dgram_ref(), now()); - mem::drop(hconn_c.process(out.as_dgram_ref(), now())); + let out = hconn_s.process(out.dgram(), now()); + mem::drop(hconn_c.process(out.dgram(), now())); process_server_events(&hconn_s); - let out = hconn_s.process(None, now()); + let out = hconn_s.process(None::, now()); qtrace!("-----client"); - mem::drop(hconn_c.process(out.as_dgram_ref(), now())); - let out = hconn_s.process(None, now()); - mem::drop(hconn_c.process(out.as_dgram_ref(), now())); + mem::drop(hconn_c.process(out.dgram(), now())); + let out = hconn_s.process(None::, now()); + mem::drop(hconn_c.process(out.dgram(), now())); process_client_events(&mut hconn_c); } @@ -215,10 +215,10 @@ fn response_103() { .unwrap(); assert_eq!(req, 0); hconn_c.stream_close_send(req).unwrap(); - let out = hconn_c.process(dgram.as_ref(), now()); + let out = hconn_c.process(dgram, now()); - let out = hconn_s.process(out.as_dgram_ref(), now()); - mem::drop(hconn_c.process(out.as_dgram_ref(), now())); + let out = hconn_s.process(out.dgram(), now()); + mem::drop(hconn_c.process(out.dgram(), now())); let request = receive_request(&hconn_s).unwrap(); let info_headers = [ Header::new(":status", "103"), @@ -226,9 +226,9 @@ fn response_103() { ]; // Send 103 request.send_headers(&info_headers).unwrap(); - let out = hconn_s.process(None, now()); + let out = hconn_s.process(None::, now()); - mem::drop(hconn_c.process(out.as_dgram_ref(), now())); + mem::drop(hconn_c.process(out.dgram(), now())); let info_headers_event = |e| { matches!(e, Http3ClientEvent::HeaderReady { headers, @@ -238,8 +238,8 @@ fn response_103() { assert!(hconn_c.events().any(info_headers_event)); set_response(&request); - let out = hconn_s.process(None, now()); - mem::drop(hconn_c.process(out.as_dgram_ref(), now())); + let out = hconn_s.process(None::, now()); + mem::drop(hconn_c.process(out.dgram(), now())); process_client_events(&mut hconn_c); } @@ -448,8 +448,8 @@ fn zerortt() { .unwrap(); hconn_c.stream_close_send(req).unwrap(); - let out = hconn_c.process(dgram.as_ref(), now()); - let out = hconn_s.process(out.as_dgram_ref(), now()); + let out = hconn_c.process(dgram, now()); + let out = hconn_s.process(out.dgram(), now()); let mut request_stream = None; let mut zerortt_state_change = false; @@ -513,7 +513,7 @@ fn fetch_noresponse_will_idletimeout() { .unwrap(); assert_eq!(req, 0); hconn_c.stream_close_send(req).unwrap(); - let _out = hconn_c.process(dgram.as_ref(), now); + let _out = hconn_c.process(dgram, now); qtrace!("-----server"); let mut done = false; diff --git a/neqo-http3/tests/priority.rs b/neqo-http3/tests/priority.rs index 77d19e6fcf..cafebe09b5 100644 --- a/neqo-http3/tests/priority.rs +++ b/neqo-http3/tests/priority.rs @@ -16,9 +16,9 @@ use test_fixture::*; fn exchange_packets(client: &mut Http3Client, server: &mut Http3Server) { let mut out = None; loop { - out = client.process(out.as_ref(), now()).dgram(); + out = client.process(out, now()).dgram(); let client_done = out.is_none(); - out = server.process(out.as_ref(), now()).dgram(); + out = server.process(out, now()).dgram(); if out.is_none() && client_done { break; } @@ -28,29 +28,29 @@ fn exchange_packets(client: &mut Http3Client, server: &mut Http3Server) { // Perform only Quic transport handshake. fn connect_with(client: &mut Http3Client, server: &mut Http3Server) { assert_eq!(client.state(), Http3State::Initializing); - let out = client.process(None, now()); + let out = client.process_output(now()); assert_eq!(client.state(), Http3State::Initializing); - let out = server.process(out.as_dgram_ref(), now()); - let out = client.process(out.as_dgram_ref(), now()); - let out = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); + let out = client.process(out.dgram(), now()); + let out = server.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_none()); let authentication_needed = |e| matches!(e, Http3ClientEvent::AuthenticationNeeded); assert!(client.events().any(authentication_needed)); client.authenticated(AuthenticationStatus::Ok, now()); - let out = client.process(out.as_dgram_ref(), now()); + let out = client.process(out.dgram(), now()); let connected = |e| matches!(e, Http3ClientEvent::StateChange(Http3State::Connected)); assert!(client.events().any(connected)); assert_eq!(client.state(), Http3State::Connected); // Exchange H3 setttings - let out = server.process(out.as_dgram_ref(), now()); - let out = client.process(out.as_dgram_ref(), now()); - let out = server.process(out.as_dgram_ref(), now()); - let out = client.process(out.as_dgram_ref(), now()); - _ = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); + let out = client.process(out.dgram(), now()); + let out = server.process(out.dgram(), now()); + let out = client.process(out.dgram(), now()); + _ = server.process(out.dgram(), now()); } fn connect() -> (Http3Client, Http3Server) { diff --git a/neqo-http3/tests/send_message.rs b/neqo-http3/tests/send_message.rs index 3bbcdd391c..19a47cde7c 100644 --- a/neqo-http3/tests/send_message.rs +++ b/neqo-http3/tests/send_message.rs @@ -29,8 +29,8 @@ fn response_header_103() -> &'static Vec
{ fn exchange_packets(client: &mut Http3Client, server: &mut Http3Server) { let mut out = None; loop { - out = client.process(out.as_ref(), now()).dgram(); - out = server.process(out.as_ref(), now()).dgram(); + out = client.process(out, now()).dgram(); + out = server.process(out, now()).dgram(); if out.is_none() { break; } diff --git a/neqo-http3/tests/webtransport.rs b/neqo-http3/tests/webtransport.rs index d178b23539..b2d2d571fb 100644 --- a/neqo-http3/tests/webtransport.rs +++ b/neqo-http3/tests/webtransport.rs @@ -41,19 +41,19 @@ fn connect() -> (Http3Client, Http3Server) { ) .expect("create a server"); assert_eq!(client.state(), Http3State::Initializing); - let out = client.process(None, now()); + let out = client.process_output(now()); assert_eq!(client.state(), Http3State::Initializing); - let out = server.process(out.as_dgram_ref(), now()); - let out = client.process(out.as_dgram_ref(), now()); - let out = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); + let out = client.process(out.dgram(), now()); + let out = server.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_none()); let authentication_needed = |e| matches!(e, Http3ClientEvent::AuthenticationNeeded); assert!(client.events().any(authentication_needed)); client.authenticated(AuthenticationStatus::Ok, now()); - let mut out = client.process(out.as_dgram_ref(), now()).dgram(); + let mut out = client.process(out.dgram(), now()).dgram(); let connected = |e| matches!(e, Http3ClientEvent::StateChange(Http3State::Connected)); assert!(client.events().any(connected)); @@ -61,9 +61,9 @@ fn connect() -> (Http3Client, Http3Server) { // Exchange H3 setttings loop { - out = server.process(out.as_ref(), now()).dgram(); + out = server.process(out, now()).dgram(); let dgram_present = out.is_some(); - out = client.process(out.as_ref(), now()).dgram(); + out = client.process(out, now()).dgram(); if out.is_none() && !dgram_present { break; } @@ -74,8 +74,8 @@ fn connect() -> (Http3Client, Http3Server) { fn exchange_packets(client: &mut Http3Client, server: &mut Http3Server) { let mut out = None; loop { - out = client.process(out.as_ref(), now()).dgram(); - out = server.process(out.as_ref(), now()).dgram(); + out = client.process(out, now()).dgram(); + out = server.process(out, now()).dgram(); if out.is_none() { break; } diff --git a/neqo-qpack/src/decoder.rs b/neqo-qpack/src/decoder.rs index 02ba69bf9d..ed1d0b8a18 100644 --- a/neqo-qpack/src/decoder.rs +++ b/neqo-qpack/src/decoder.rs @@ -333,8 +333,8 @@ mod tests { .peer_conn .stream_send(decoder.recv_stream_id, encoder_instruction) .unwrap(); - let out = decoder.peer_conn.process(None, now()); - mem::drop(decoder.conn.process(out.as_dgram_ref(), now())); + let out = decoder.peer_conn.process_output(now()); + mem::drop(decoder.conn.process(out.dgram(), now())); assert_eq!( decoder .decoder @@ -345,8 +345,8 @@ mod tests { fn send_instructions_and_check(decoder: &mut TestDecoder, decoder_instruction: &[u8]) { decoder.decoder.send(&mut decoder.conn).unwrap(); - let out = decoder.conn.process(None, now()); - mem::drop(decoder.peer_conn.process(out.as_dgram_ref(), now())); + let out = decoder.conn.process_output(now()); + mem::drop(decoder.peer_conn.process(out.dgram(), now())); let mut buf = [0_u8; 100]; let (amount, fin) = decoder .peer_conn diff --git a/neqo-qpack/src/encoder.rs b/neqo-qpack/src/encoder.rs index bf142c3e9f..8677f502da 100644 --- a/neqo-qpack/src/encoder.rs +++ b/neqo-qpack/src/encoder.rs @@ -572,9 +572,9 @@ mod tests { pub fn send_instructions(&mut self, encoder_instruction: &[u8]) { self.encoder.send_encoder_updates(&mut self.conn).unwrap(); - let out = self.conn.process(None, now()); - let out2 = self.peer_conn.process(out.as_dgram_ref(), now()); - mem::drop(self.conn.process(out2.as_dgram_ref(), now())); + let out = self.conn.process_output(now()); + let out2 = self.peer_conn.process(out.dgram(), now()); + mem::drop(self.conn.process(out2.dgram(), now())); let mut buf = [0_u8; 100]; let (amount, fin) = self .peer_conn @@ -635,8 +635,8 @@ mod tests { .peer_conn .stream_send(encoder.recv_stream_id, decoder_instruction) .unwrap(); - let out = encoder.peer_conn.process(None, now()); - mem::drop(encoder.conn.process(out.as_dgram_ref(), now())); + let out = encoder.peer_conn.process_output(now()); + mem::drop(encoder.conn.process(out.dgram(), now())); assert!(encoder .encoder .read_instructions(&mut encoder.conn, encoder.recv_stream_id) @@ -1563,8 +1563,8 @@ mod tests { encoder.send_instructions(ONE_INSTRUCTION_1); // exchange a flow control update. - let out = encoder.peer_conn.process(None, now()); - mem::drop(encoder.conn.process(out.as_dgram_ref(), now())); + let out = encoder.peer_conn.process_output(now()); + mem::drop(encoder.conn.process(out.dgram(), now())); // Try writing a new header block. Now, headers will be added to the dynamic table again, // because instructions can be sent. @@ -1610,8 +1610,8 @@ mod tests { .encoder .send_encoder_updates(&mut encoder.conn) .unwrap(); - let out = encoder.conn.process(None, now()); - mem::drop(encoder.peer_conn.process(out.as_dgram_ref(), now())); + let out = encoder.conn.process_output(now()); + mem::drop(encoder.peer_conn.process(out.dgram(), now())); // receive an insert count increment. recv_instruction(&mut encoder, &[0x01]); diff --git a/neqo-transport/src/connection/mod.rs b/neqo-transport/src/connection/mod.rs index 0184ddce7b..b6b6b15762 100644 --- a/neqo-transport/src/connection/mod.rs +++ b/neqo-transport/src/connection/mod.rs @@ -1022,15 +1022,16 @@ impl Connection { } /// Process new input datagrams on the connection. - pub fn process_input(&mut self, d: &Datagram, now: Instant) { + pub fn process_input(&mut self, d: Datagram>, now: Instant) { self.process_multiple_input(iter::once(d), now); } /// Process new input datagrams on the connection. - pub fn process_multiple_input<'a, I>(&mut self, dgrams: I, now: Instant) - where - I: IntoIterator, - { + pub fn process_multiple_input( + &mut self, + dgrams: impl IntoIterator>>, + now: Instant, + ) { let mut dgrams = dgrams.into_iter().peekable(); if dgrams.peek().is_none() { return; @@ -1161,7 +1162,7 @@ impl Connection { /// Process input and generate output. #[must_use = "Output of the process function must be handled"] - pub fn process(&mut self, dgram: Option<&Datagram>, now: Instant) -> Output { + pub fn process(&mut self, dgram: Option>>, now: Instant) -> Output { if let Some(d) = dgram { self.input(d, now, now); self.process_saved(now); @@ -1241,20 +1242,20 @@ impl Connection { } } - fn is_stateless_reset(&self, path: &PathRef, d: &Datagram) -> bool { + fn is_stateless_reset(&self, path: &PathRef, d: &Datagram>) -> bool { // If the datagram is too small, don't try. // If the connection is connected, then the reset token will be invalid. if d.len() < 16 || !self.state.connected() { return false; } - <&[u8; 16]>::try_from(&d[d.len() - 16..]) + <&[u8; 16]>::try_from(&d.as_ref()[d.len() - 16..]) .map_or(false, |token| path.borrow().is_stateless_reset(token)) } fn check_stateless_reset( &mut self, path: &PathRef, - d: &Datagram, + d: &Datagram>, first: bool, now: Instant, ) -> Res<()> { @@ -1280,24 +1281,27 @@ impl Connection { debug_assert!(self.crypto.states.rx_hp(self.version, cspace).is_some()); for saved in self.saved_datagrams.take_saved() { qtrace!([self], "input saved @{:?}: {:?}", saved.t, saved.d); - self.input(&saved.d, saved.t, now); + self.input(saved.d, saved.t, now); } } } /// In case a datagram arrives that we can only partially process, save any /// part that we don't have keys for. - fn save_datagram(&mut self, cspace: CryptoSpace, d: &Datagram, remaining: usize, now: Instant) { - let d = if remaining < d.len() { - Datagram::new( - d.source(), - d.destination(), - d.tos(), - &d[d.len() - remaining..], - ) - } else { - d.clone() - }; + #[allow(clippy::needless_pass_by_value)] // To consume an owned datagram below. + fn save_datagram( + &mut self, + cspace: CryptoSpace, + d: Datagram>, + remaining: usize, + now: Instant, + ) { + let d = Datagram::new( + d.source(), + d.destination(), + d.tos(), + d[d.len() - remaining..].to_vec(), + ); self.saved_datagrams.save(cspace, d, now); self.stats.borrow_mut().saved_datagrams += 1; } @@ -1498,7 +1502,7 @@ impl Connection { fn postprocess_packet( &mut self, path: &PathRef, - d: &Datagram, + d: &Datagram>, packet: &PublicPacket, migrate: bool, now: Instant, @@ -1530,7 +1534,7 @@ impl Connection { /// Take a datagram as input. This reports an error if the packet was bad. /// This takes two times: when the datagram was received, and the current time. - fn input(&mut self, d: &Datagram, received: Instant, now: Instant) { + fn input(&mut self, d: Datagram>, received: Instant, now: Instant) { // First determine the path. let path = self.paths.find_path_with_rebinding( d.destination(), @@ -1544,11 +1548,16 @@ impl Connection { self.capture_error(Some(path), now, 0, res).ok(); } - fn input_path(&mut self, path: &PathRef, d: &Datagram, now: Instant) -> Res<()> { - let mut slc = &d[..]; + fn input_path( + &mut self, + path: &PathRef, + d: Datagram>, + now: Instant, + ) -> Res<()> { + let mut slc = d.as_ref(); let mut dcid = None; - qtrace!([self], "{} input {}", path.borrow(), hex(&**d)); + qtrace!([self], "{} input {}", path.borrow(), hex(&d)); let pto = path.borrow().rtt().pto(self.confirmed()); // Handle each packet in the datagram. @@ -1606,7 +1615,7 @@ impl Connection { } else { match self.process_packet(path, &payload, now) { Ok(migrate) => { - self.postprocess_packet(path, d, &packet, migrate, now); + self.postprocess_packet(path, &d, &packet, migrate, now); } Err(e) => { self.ensure_error_path(path, &packet, now); @@ -1648,7 +1657,7 @@ impl Connection { // Decryption failure, or not having keys is not fatal. // If the state isn't available, or we can't decrypt the packet, drop // the rest of the datagram on the floor, but don't generate an error. - self.check_stateless_reset(path, d, dcid.is_none(), now)?; + self.check_stateless_reset(path, &d, dcid.is_none(), now)?; self.stats.borrow_mut().pkt_dropped("Decryption failure"); qlog::packet_dropped(&self.qlog, &packet); } @@ -1656,7 +1665,7 @@ impl Connection { slc = remainder; dcid = Some(ConnectionId::from(packet.dcid())); } - self.check_stateless_reset(path, d, dcid.is_none(), now)?; + self.check_stateless_reset(path, &d, dcid.is_none(), now)?; Ok(()) } @@ -1958,7 +1967,13 @@ impl Connection { Ok(()) } - fn handle_migration(&mut self, path: &PathRef, d: &Datagram, migrate: bool, now: Instant) { + fn handle_migration( + &mut self, + path: &PathRef, + d: &Datagram>, + migrate: bool, + now: Instant, + ) { if !migrate { return; } diff --git a/neqo-transport/src/connection/tests/ackrate.rs b/neqo-transport/src/connection/tests/ackrate.rs index f0a1d17cd9..f7a2e1869b 100644 --- a/neqo-transport/src/connection/tests/ackrate.rs +++ b/neqo-transport/src/connection/tests/ackrate.rs @@ -72,7 +72,7 @@ fn ack_rate_exit_slow_start() { // and to send ACK_FREQUENCY. now += DEFAULT_RTT / 2; assert_eq!(client.stats().frame_tx.ack_frequency, 0); - let af = client.process(Some(&ack), now).dgram(); + let af = client.process(Some(ack), now).dgram(); assert!(af.is_some()); assert_eq!(client.stats().frame_tx.ack_frequency, 1); } @@ -121,11 +121,11 @@ fn ack_rate_client_one_rtt() { // The first packet will elicit an immediate ACK however, so do this twice. let d = send_something(&mut client, now); now += RTT / 2; - let ack = server.process(Some(&d), now).dgram(); + let ack = server.process(Some(d), now).dgram(); assert!(ack.is_some()); let d = send_something(&mut client, now); now += RTT / 2; - let delay = server.process(Some(&d), now).callback(); + let delay = server.process(Some(d), now).callback(); assert_eq!(delay, RTT); assert_eq!(client.stats().frame_tx.ack_frequency, 1); @@ -144,11 +144,11 @@ fn ack_rate_server_half_rtt() { now += RTT / 2; // The client now will acknowledge immediately because it has been more than // an RTT since it last sent an acknowledgment. - let ack = client.process(Some(&d), now); + let ack = client.process(Some(d), now); assert!(ack.as_dgram_ref().is_some()); let d = send_something(&mut server, now); now += RTT / 2; - let delay = client.process(Some(&d), now).callback(); + let delay = client.process(Some(d), now).callback(); assert_eq!(delay, RTT / 2); assert_eq!(server.stats().frame_tx.ack_frequency, 1); @@ -172,7 +172,7 @@ fn migrate_ack_delay() { let client2 = send_something(&mut client, now); assertions::assert_v4_path(&client2, false); // Doesn't. Is dropped. now += DEFAULT_RTT / 2; - server.process_input(&client1, now); + server.process_input(client1, now); let stream = client.stream_create(StreamType::UniDi).unwrap(); let now = increase_cwnd(&mut client, &mut server, stream, now); @@ -188,7 +188,7 @@ fn migrate_ack_delay() { // After noticing this new loss, the client sends ACK_FREQUENCY. // It has sent a few before (as we dropped `client2`), so ignore those. let ad_before = client.stats().frame_tx.ack_frequency; - let af = client.process(Some(&ack), now).dgram(); + let af = client.process(Some(ack), now).dgram(); assert!(af.is_some()); assert_eq!(client.stats().frame_tx.ack_frequency, ad_before + 1); } diff --git a/neqo-transport/src/connection/tests/cc.rs b/neqo-transport/src/connection/tests/cc.rs index 2f66774881..09bcefb7a4 100644 --- a/neqo-transport/src/connection/tests/cc.rs +++ b/neqo-transport/src/connection/tests/cc.rs @@ -47,7 +47,7 @@ fn cc_slow_start_pmtud() { let stream_id = client.stream_create(StreamType::UniDi).unwrap(); let cwnd = cwnd_avail(&client); let (dgrams, _) = fill_cwnd(&mut client, stream_id, now); - let dgrams_len = dgrams.iter().map(|d| d.len()).sum::(); + let dgrams_len = dgrams.iter().map(Datagram::len).sum::(); assert_eq!(dgrams_len, cwnd); assert!(cwnd_avail(&client) < ACK_ONLY_SIZE_LIMIT); } @@ -86,7 +86,7 @@ fn cc_slow_start_to_cong_avoidance_recovery_period(congestion_signal: Congestion // Client: Process ack now += DEFAULT_RTT / 2; - client.process_input(&s_ack, now); + client.process_input(s_ack, now); assert_eq!( client.stats().frame_rx.largest_acknowledged, flight1_largest @@ -117,7 +117,7 @@ fn cc_slow_start_to_cong_avoidance_recovery_period(congestion_signal: Congestion // Client: Process ack now += DEFAULT_RTT / 2; - client.process_input(&s_ack, now); + client.process_input(s_ack, now); assert_eq!( client.stats().frame_rx.largest_acknowledged, flight2_largest @@ -160,7 +160,7 @@ fn cc_cong_avoidance_recovery_period_unchanged() { // Server: Receive and generate ack let s_ack = ack_bytes(&mut server, stream_id, c_tx_dgrams, now); - client.process_input(&s_ack, now); + client.process_input(s_ack, now); let cwnd1 = cwnd(&client); @@ -168,7 +168,7 @@ fn cc_cong_avoidance_recovery_period_unchanged() { let s_ack = ack_bytes(&mut server, stream_id, c_tx_dgrams2, now); // ACK more packets but they were sent before end of recovery period - client.process_input(&s_ack, now); + client.process_input(s_ack, now); // cwnd should not have changed since ACKed packets were sent before // recovery period expired @@ -198,12 +198,12 @@ fn single_packet_on_recovery() { // Acknowledge just one packet and cause one packet to be declared lost. // The length is the amount of credit the client should have. - let ack = server.process(Some(&delivered), now).dgram(); + let ack = server.process(Some(delivered), now).dgram(); assert!(ack.is_some()); // The client should see the loss and enter recovery. // As there are many outstanding packets, there should be no available cwnd. - client.process_input(&ack.unwrap(), now); + client.process_input(ack.unwrap(), now); assert_eq!(cwnd_avail(&client), 0); // The client should send one packet, ignoring the cwnd. @@ -235,7 +235,7 @@ fn cc_cong_avoidance_recovery_period_to_cong_avoidance() { // Client: Process ack now += DEFAULT_RTT / 2; - client.process_input(&s_ack, now); + client.process_input(s_ack, now); // Should be in CARP now. now += DEFAULT_RTT / 2; @@ -251,7 +251,7 @@ fn cc_cong_avoidance_recovery_period_to_cong_avoidance() { for i in 0..5 { qinfo!("iteration {}", i); - let c_tx_size: usize = c_tx_dgrams.iter().map(|d| d.len()).sum(); + let c_tx_size: usize = c_tx_dgrams.iter().map(Datagram::len).sum(); qinfo!( "client sending {} bytes into cwnd of {}", c_tx_size, @@ -269,7 +269,7 @@ fn cc_cong_avoidance_recovery_period_to_cong_avoidance() { let most = c_tx_dgrams.len() - usize::try_from(DEFAULT_ACK_PACKET_TOLERANCE).unwrap() - 1; let s_ack = ack_bytes(&mut server, stream_id, c_tx_dgrams.drain(..most), now); assert_eq!(cwnd(&client), expected_cwnd); - client.process_input(&s_ack, now); + client.process_input(s_ack, now); // make sure to fill cwnd again. let (mut new_pkts, next_now) = fill_cwnd(&mut client, stream_id, now); now = next_now; @@ -277,7 +277,7 @@ fn cc_cong_avoidance_recovery_period_to_cong_avoidance() { let s_ack = ack_bytes(&mut server, stream_id, c_tx_dgrams, now); assert_eq!(cwnd(&client), expected_cwnd); - client.process_input(&s_ack, now); + client.process_input(s_ack, now); // make sure to fill cwnd again. let (mut new_pkts, next_now) = fill_cwnd(&mut client, stream_id, now); now = next_now; @@ -329,7 +329,7 @@ fn cc_slow_start_to_persistent_congestion_some_acks() { let s_ack = ack_bytes(&mut server, stream, c_tx_dgrams, now); now += Duration::from_millis(100); - client.process_input(&s_ack, now); + client.process_input(s_ack, now); // send bytes that will be lost let (_, next_now) = fill_cwnd(&mut client, stream, now); @@ -375,7 +375,7 @@ fn cc_persistent_congestion_to_slow_start() { // No longer in CARP. (pkts acked from after start of CARP) // Should be in slow start now. - client.process_input(&s_ack, now); + client.process_input(s_ack, now); // ACKing 2 packets should let client send 4. let (c_tx_dgrams, _) = fill_cwnd(&mut client, stream, now); @@ -402,22 +402,22 @@ fn ack_are_not_cc() { let other_stream = server.stream_create(StreamType::BiDi).unwrap(); assert_eq!(other_stream, 1); server.stream_send(other_stream, b"dropped").unwrap(); - let dropped_packet = server.process(None, now).dgram(); + let dropped_packet = server.process_output(now).dgram(); assert!(dropped_packet.is_some()); // Now drop this one. // Now the server sends a packet that will force an ACK, // because the client will detect a gap. server.stream_send(other_stream, b"sent").unwrap(); - let ack_eliciting_packet = server.process(None, now).dgram(); + let ack_eliciting_packet = server.process_output(now).dgram(); assert!(ack_eliciting_packet.is_some()); // The client can ack the server packet even if cc windows is full. qdebug!([client], "Process ack-eliciting"); - let ack_pkt = client.process(ack_eliciting_packet.as_ref(), now).dgram(); + let ack_pkt = client.process(ack_eliciting_packet, now).dgram(); assert!(ack_pkt.is_some()); qdebug!([server], "Handle ACK"); let prev_ack_count = server.stats().frame_rx.ack; - server.process_input(&ack_pkt.unwrap(), now); + server.process_input(ack_pkt.unwrap(), now); assert_eq!(server.stats().frame_rx.ack, prev_ack_count + 1); } diff --git a/neqo-transport/src/connection/tests/close.rs b/neqo-transport/src/connection/tests/close.rs index 7c620de17e..a69db15220 100644 --- a/neqo-transport/src/connection/tests/close.rs +++ b/neqo-transport/src/connection/tests/close.rs @@ -41,7 +41,7 @@ fn connection_close() { client.close(now, 42, ""); let stats_before = client.stats().frame_tx; - let out = client.process(None, now); + let out = client.process_output(now); let stats_after = client.stats().frame_tx; assert_eq!( stats_after.connection_close, @@ -49,7 +49,7 @@ fn connection_close() { ); assert_eq!(stats_after.ack, stats_before.ack + 1); - server.process_input(&out.dgram().unwrap(), now); + server.process_input(out.dgram().unwrap(), now); assert_draining(&server, &Error::PeerApplicationError(42)); } @@ -65,7 +65,7 @@ fn connection_close_with_long_reason_string() { client.close(now, 42, long_reason); let stats_before = client.stats().frame_tx; - let out = client.process(None, now); + let out = client.process_output(now); let stats_after = client.stats().frame_tx; assert_eq!( stats_after.connection_close, @@ -73,7 +73,7 @@ fn connection_close_with_long_reason_string() { ); assert_eq!(stats_after.ack, stats_before.ack + 1); - server.process_input(&out.dgram().unwrap(), now); + server.process_input(out.dgram().unwrap(), now); assert_draining(&server, &Error::PeerApplicationError(42)); } @@ -84,17 +84,17 @@ fn early_application_close() { let mut server = default_server(); // One flight each. - let dgram = client.process(None, now()).dgram(); + let dgram = client.process_output(now()).dgram(); assert!(dgram.is_some()); - let dgram = server.process(dgram.as_ref(), now()).dgram(); + let dgram = server.process(dgram, now()).dgram(); assert!(dgram.is_some()); server.close(now(), 77, String::new()); assert!(server.state().closed()); - let dgram = server.process(None, now()).dgram(); + let dgram = server.process_output(now()).dgram(); assert!(dgram.is_some()); - client.process_input(&dgram.unwrap(), now()); + client.process_input(dgram.unwrap(), now()); assert_draining(&client, &Error::PeerError(ERROR_APPLICATION_CLOSE)); } @@ -109,15 +109,15 @@ fn bad_tls_version() { .unwrap(); let mut server = default_server(); - let dgram = client.process(None, now()).dgram(); + let dgram = client.process_output(now()).dgram(); assert!(dgram.is_some()); - let dgram = server.process(dgram.as_ref(), now()).dgram(); + let dgram = server.process(dgram, now()).dgram(); assert_eq!( *server.state(), State::Closed(CloseReason::Transport(Error::ProtocolViolation)) ); assert!(dgram.is_some()); - client.process_input(&dgram.unwrap(), now()); + client.process_input(dgram.unwrap(), now()); assert_draining(&client, &Error::PeerError(Error::ProtocolViolation.code())); } @@ -134,21 +134,21 @@ fn closing_timers_interation() { // We're going to induce time-based loss recovery so that timer is set. let _p1 = send_something(&mut client, now); let p2 = send_something(&mut client, now); - let ack = server.process(Some(&p2), now).dgram(); + let ack = server.process(Some(p2), now).dgram(); assert!(ack.is_some()); // This is an ACK. // After processing the ACK, we should be on the loss recovery timer. - let cb = client.process(ack.as_ref(), now).callback(); + let cb = client.process(ack, now).callback(); assert_ne!(cb, Duration::from_secs(0)); now += cb; // Rather than let the timer pop, close the connection. client.close(now, 0, ""); - let client_close = client.process(None, now).dgram(); + let client_close = client.process_output(now).dgram(); assert!(client_close.is_some()); // This should now report the end of the closing period, not a // zero-duration wait driven by the (now defunct) loss recovery timer. - let client_close_timer = client.process(None, now).callback(); + let client_close_timer = client.process_output(now).callback(); assert_ne!(client_close_timer, Duration::from_secs(0)); } @@ -164,20 +164,20 @@ fn closing_and_draining() { // Close the connection. client.close(now(), APP_ERROR, ""); - let client_close = client.process(None, now()).dgram(); + let client_close = client.process_output(now()).dgram(); assert!(client_close.is_some()); - let client_close_timer = client.process(None, now()).callback(); + let client_close_timer = client.process_output(now()).callback(); assert_ne!(client_close_timer, Duration::from_secs(0)); // The client will spit out the same packet in response to anything it receives. let p3 = send_something(&mut server, now()); - let client_close2 = client.process(Some(&p3), now()).dgram(); + let client_close2 = client.process(Some(p3), now()).dgram(); assert_eq!( client_close.as_ref().unwrap().len(), client_close2.as_ref().unwrap().len() ); // After this time, the client should transition to closed. - let end = client.process(None, now() + client_close_timer); + let end = client.process_output(now() + client_close_timer); assert_eq!(end, Output::None); assert_eq!( *client.state(), @@ -185,17 +185,17 @@ fn closing_and_draining() { ); // When the server receives the close, it too should generate CONNECTION_CLOSE. - let server_close = server.process(client_close.as_ref(), now()).dgram(); + let server_close = server.process(client_close, now()).dgram(); assert!(server.state().closed()); assert!(server_close.is_some()); // .. but it ignores any further close packets. - let server_close_timer = server.process(client_close2.as_ref(), now()).callback(); + let server_close_timer = server.process(client_close2, now()).callback(); assert_ne!(server_close_timer, Duration::from_secs(0)); // Even a legitimate packet without a close in it. - let server_close_timer2 = server.process(Some(&p1), now()).callback(); + let server_close_timer2 = server.process(Some(p1), now()).callback(); assert_eq!(server_close_timer, server_close_timer2); - let end = server.process(None, now() + server_close_timer); + let end = server.process_output(now() + server_close_timer); assert_eq!(end, Output::None); assert_eq!( *server.state(), @@ -218,6 +218,6 @@ fn stateless_reset_client() { .unwrap(); connect_force_idle(&mut client, &mut server); - client.process_input(&datagram(vec![77; 21]), now()); + client.process_input(datagram(vec![77; 21]), now()); assert_draining(&client, &Error::StatelessReset); } diff --git a/neqo-transport/src/connection/tests/datagram.rs b/neqo-transport/src/connection/tests/datagram.rs index 7fa38ec489..7fb03aba15 100644 --- a/neqo-transport/src/connection/tests/datagram.rs +++ b/neqo-transport/src/connection/tests/datagram.rs @@ -93,7 +93,7 @@ fn datagram_enabled_on_client() { let out = server.process_output(now()).dgram().unwrap(); assert_eq!(server.stats().frame_tx.datagram, dgram_sent + 1); - client.process_input(&out, now()); + client.process_input(out, now()); assert!(matches!( client.next_event().unwrap(), ConnectionEvent::Datagram(data) if data == DATA_SMALLER_THAN_MTU @@ -124,7 +124,7 @@ fn datagram_enabled_on_server() { let out = client.process_output(now()).dgram().unwrap(); assert_eq!(client.stats().frame_tx.datagram, dgram_sent + 1); - server.process_input(&out, now()); + server.process_input(out, now()); assert!(matches!( server.next_event().unwrap(), ConnectionEvent::Datagram(data) if data == DATA_SMALLER_THAN_MTU @@ -240,7 +240,7 @@ fn datagram_acked() { assert_eq!(client.stats().frame_tx.datagram, dgram_sent + 1); let dgram_received = server.stats().frame_rx.datagram; - server.process_input(&out.unwrap(), now()); + server.process_input(out.unwrap(), now()); assert_eq!(server.stats().frame_rx.datagram, dgram_received + 1); let now = now() + AT_LEAST_PTO; // Ack should be sent @@ -253,7 +253,7 @@ fn datagram_acked() { ConnectionEvent::Datagram(data) if data == DATA_SMALLER_THAN_MTU )); - client.process_input(&out.unwrap(), now); + client.process_input(out.unwrap(), now); assert!(matches!( client.next_event().unwrap(), ConnectionEvent::OutgoingDatagramOutcome { id, outcome } if id == 1 && outcome == OutgoingDatagramOutcome::Acked @@ -265,7 +265,7 @@ fn send_packet_and_get_server_event( server: &mut Connection, ) -> ConnectionEvent { let out = client.process_output(now()).dgram(); - server.process_input(&out.unwrap(), now()); + server.process_input(out.unwrap(), now()); let mut events: Vec<_> = server .events() .filter_map(|evt| match evt { @@ -404,7 +404,7 @@ fn dgram_no_allowed() { .test_write_frames(InsertDatagram { data: DATA_MTU }, now()) .dgram() .unwrap(); - client.process_input(&out, now()); + client.process_input(out, now()); assert_error(&client, &CloseReason::Transport(Error::ProtocolViolation)); } @@ -420,7 +420,7 @@ fn dgram_too_big() { .test_write_frames(InsertDatagram { data: DATA_MTU }, now()) .dgram() .unwrap(); - client.process_input(&out, now()); + client.process_input(out, now()); assert_error(&client, &CloseReason::Transport(Error::ProtocolViolation)); } @@ -455,7 +455,7 @@ fn outgoing_datagram_queue_full() { // Send DATA_SMALLER_THAN_MTU_2 datagram let out = client.process_output(now()).dgram(); assert_eq!(client.stats().frame_tx.datagram, dgram_sent + 1); - server.process_input(&out.unwrap(), now()); + server.process_input(out.unwrap(), now()); assert!(matches!( server.next_event().unwrap(), ConnectionEvent::Datagram(data) if data == DATA_SMALLER_THAN_MTU_2 @@ -465,7 +465,7 @@ fn outgoing_datagram_queue_full() { let dgram_sent2 = client.stats().frame_tx.datagram; let out = client.process_output(now()).dgram(); assert_eq!(client.stats().frame_tx.datagram, dgram_sent2 + 1); - server.process_input(&out.unwrap(), now()); + server.process_input(out.unwrap(), now()); assert!(matches!( server.next_event().unwrap(), ConnectionEvent::Datagram(data) if data == DATA_MTU @@ -479,7 +479,7 @@ fn send_datagram(sender: &mut Connection, receiver: &mut Connection, data: Vec SH, EE, CERT, CV, FIN"); let mut server = new_server(ConnectionParameters::default().pmtud(pmtud)); - let out = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_some()); assert_eq!(out.as_dgram_ref().unwrap().len(), server.plpmtu()); qdebug!("---- client: cert verification"); - let out = client.process(out.as_dgram_ref(), now()); + let out = client.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_some()); - let out = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_none()); assert!(maybe_authenticate(&mut client)); qdebug!("---- client: SH..FIN -> FIN"); - let out = client.process(out.as_dgram_ref(), now()); + let out = client.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_some()); assert_eq!(*client.state(), State::Connected); qdebug!("---- server: FIN -> ACKS"); - let out = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_some()); assert_eq!(*server.state(), State::Confirmed); qdebug!("---- client: ACKS -> 0"); - let out = client.process(out.as_dgram_ref(), now()); + let out = client.process(out.dgram(), now()); if pmtud { // PMTUD causes a PING probe to be sent here let pkt = out.dgram().unwrap(); @@ -103,19 +103,19 @@ fn handshake_pmtud() { fn handshake_failed_authentication() { qdebug!("---- client: generate CH"); let mut client = default_client(); - let out = client.process(None, now()); + let out = client.process_output(now()); assert!(out.as_dgram_ref().is_some()); qdebug!("---- server: CH -> SH, EE, CERT, CV, FIN"); let mut server = default_server(); - let out = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_some()); qdebug!("---- client: cert verification"); - let out = client.process(out.as_dgram_ref(), now()); + let out = client.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_some()); - let out = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_none()); let authentication_needed = |e| matches!(e, ConnectionEvent::AuthenticationNeeded); @@ -124,11 +124,11 @@ fn handshake_failed_authentication() { client.authenticated(AuthenticationStatus::CertRevoked, now()); qdebug!("---- client: -> Alert(certificate_revoked)"); - let out = client.process(None, now()); + let out = client.process_output(now()); assert!(out.as_dgram_ref().is_some()); qdebug!("---- server: Alert(certificate_revoked)"); - let out = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_some()); assert_error(&client, &CloseReason::Transport(Error::CryptoAlert(44))); assert_error(&server, &CloseReason::Transport(Error::PeerError(300))); @@ -160,29 +160,29 @@ fn no_alpn() { fn dup_server_flight1() { qdebug!("---- client: generate CH"); let mut client = default_client(); - let out = client.process(None, now()); + let out = client.process_output(now()); assert!(out.as_dgram_ref().is_some()); assert_eq!(out.as_dgram_ref().unwrap().len(), client.plpmtu()); qdebug!("Output={:0x?}", out.as_dgram_ref()); qdebug!("---- server: CH -> SH, EE, CERT, CV, FIN"); let mut server = default_server(); - let out_to_rep = server.process(out.as_dgram_ref(), now()); + let out_to_rep = server.process(out.dgram(), now()); assert!(out_to_rep.as_dgram_ref().is_some()); qdebug!("Output={:0x?}", out_to_rep.as_dgram_ref()); qdebug!("---- client: cert verification"); - let out = client.process(Some(out_to_rep.as_dgram_ref().unwrap()), now()); + let out = client.process(Some(out_to_rep.as_dgram_ref().cloned().unwrap()), now()); assert!(out.as_dgram_ref().is_some()); qdebug!("Output={:0x?}", out.as_dgram_ref()); - let out = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_none()); assert!(maybe_authenticate(&mut client)); qdebug!("---- client: SH..FIN -> FIN"); - let out = client.process(None, now()); + let out = client.process_output(now()); assert!(out.as_dgram_ref().is_some()); qdebug!("Output={:0x?}", out.as_dgram_ref()); @@ -191,7 +191,7 @@ fn dup_server_flight1() { assert_eq!(1, client.stats().dropped_rx); qdebug!("---- Dup, ignored"); - let out = client.process(out_to_rep.as_dgram_ref(), now()); + let out = client.process(out_to_rep.dgram(), now()); assert!(out.as_dgram_ref().is_none()); qdebug!("Output={:0x?}", out.as_dgram_ref()); @@ -216,17 +216,17 @@ fn crypto_frame_split() { ) .expect("create a server"); - let client1 = client.process(None, now()); + let client1 = client.process_output(now()); assert!(client1.as_dgram_ref().is_some()); // The entire server flight doesn't fit in a single packet because the // certificate is large, therefore the server will produce 2 packets. - let server1 = server.process(client1.as_dgram_ref(), now()); + let server1 = server.process(client1.dgram(), now()); assert!(server1.as_dgram_ref().is_some()); - let server2 = server.process(None, now()); + let server2 = server.process_output(now()); assert!(server2.as_dgram_ref().is_some()); - let client2 = client.process(server1.as_dgram_ref(), now()); + let client2 = client.process(server1.dgram(), now()); // This is an ack. assert!(client2.as_dgram_ref().is_some()); // The client might have the certificate now, so we can't guarantee that @@ -235,11 +235,11 @@ fn crypto_frame_split() { assert_eq!(*client.state(), State::Handshaking); // let server process the ack for the first packet. - let server3 = server.process(client2.as_dgram_ref(), now()); + let server3 = server.process(client2.dgram(), now()); assert!(server3.as_dgram_ref().is_none()); // Consume the second packet from the server. - let client3 = client.process(server2.as_dgram_ref(), now()); + let client3 = client.process(server2.dgram(), now()); // Check authentication. let auth2 = maybe_authenticate(&mut client); @@ -247,13 +247,13 @@ fn crypto_frame_split() { // Now client has all data to finish handshake. assert_eq!(*client.state(), State::Connected); - let client4 = client.process(server3.as_dgram_ref(), now()); + let client4 = client.process(server3.dgram(), now()); // One of these will contain data depending on whether Authentication was completed // after the first or second server packet. assert!(client3.as_dgram_ref().is_some() ^ client4.as_dgram_ref().is_some()); - mem::drop(server.process(client3.as_dgram_ref(), now())); - mem::drop(server.process(client4.as_dgram_ref(), now())); + mem::drop(server.process(client3.dgram(), now())); + mem::drop(server.process(client4.dgram(), now())); assert_eq!(*client.state(), State::Connected); assert_eq!(*server.state(), State::Confirmed); @@ -283,21 +283,21 @@ fn send_05rtt() { let mut client = default_client(); let mut server = default_server(); - let c1 = client.process(None, now()).dgram(); + let c1 = client.process_output(now()).dgram(); assert!(c1.is_some()); - let s1 = server.process(c1.as_ref(), now()).dgram().unwrap(); + let s1 = server.process(c1, now()).dgram().unwrap(); assert_eq!(s1.len(), server.plpmtu()); // The server should accept writes at this point. let s2 = send_something(&mut server, now()); // Complete the handshake at the client. - client.process_input(&s1, now()); + client.process_input(s1, now()); maybe_authenticate(&mut client); assert_eq!(*client.state(), State::Connected); // The client should receive the 0.5-RTT data now. - client.process_input(&s2, now()); + client.process_input(s2, now()); let mut buf = vec![0; DEFAULT_STREAM_DATA.len() + 1]; let stream_id = client .events() @@ -320,21 +320,21 @@ fn reorder_05rtt() { let mut client = default_client(); let mut server = default_server(); - let c1 = client.process(None, now()).dgram(); + let c1 = client.process_output(now()).dgram(); assert!(c1.is_some()); - let s1 = server.process(c1.as_ref(), now()).dgram().unwrap(); + let s1 = server.process(c1, now()).dgram().unwrap(); // The server should accept writes at this point. let s2 = send_something(&mut server, now()); // We can't use the standard facility to complete the handshake, so // drive it as aggressively as possible. - client.process_input(&s2, now()); + client.process_input(s2, now()); assert_eq!(client.stats().saved_datagrams, 1); // After processing the first packet, the client should go back and // process the 0.5-RTT packet data, which should make data available. - client.process_input(&s1, now()); + client.process_input(s1, now()); // We can't use `maybe_authenticate` here as that consumes events. client.authenticated(AuthenticationStatus::Ok, now()); assert_eq!(*client.state(), State::Connected); @@ -372,7 +372,7 @@ fn reorder_05rtt_with_0rtt() { server.send_ticket(now, &[]).unwrap(); let ticket = server.process_output(now).dgram().unwrap(); now += RTT / 2; - client.process_input(&ticket, now); + client.process_input(ticket, now); let token = get_tokens(&mut client).pop().unwrap(); let mut client = default_client(); @@ -389,35 +389,35 @@ fn reorder_05rtt_with_0rtt() { // Handle the first packet and send 0.5-RTT in response. Drop the response. now += RTT / 2; - mem::drop(server.process(Some(&c1), now).dgram().unwrap()); + mem::drop(server.process(Some(c1), now).dgram().unwrap()); // The gap in 0-RTT will result in this 0.5 RTT containing an ACK. - server.process_input(&c2, now); + server.process_input(c2, now); let s2 = send_something(&mut server, now); // Save the 0.5 RTT. now += RTT / 2; - client.process_input(&s2, now); + client.process_input(s2, now); assert_eq!(client.stats().saved_datagrams, 1); // Now PTO at the client and cause the server to re-send handshake packets. now += AT_LEAST_PTO; - let c3 = client.process(None, now).dgram(); + let c3 = client.process_output(now).dgram(); assert_coalesced_0rtt(c3.as_ref().unwrap()); now += RTT / 2; - let s3 = server.process(c3.as_ref(), now).dgram().unwrap(); + let s3 = server.process(c3, now).dgram().unwrap(); // The client should be able to process the 0.5 RTT now. // This should contain an ACK, so we are processing an ACK from the past. now += RTT / 2; - client.process_input(&s3, now); + client.process_input(s3, now); maybe_authenticate(&mut client); - let c4 = client.process(None, now).dgram(); + let c4 = client.process_output(now).dgram(); assert_eq!(*client.state(), State::Connected); assert_eq!(client.paths.rtt(), RTT); now += RTT / 2; - server.process_input(&c4.unwrap(), now); + server.process_input(c4.unwrap(), now); assert_eq!(*server.state(), State::Confirmed); // Don't check server RTT as it will be massively inflated by a // poor initial estimate received when the server dropped the @@ -435,10 +435,10 @@ fn coalesce_05rtt() { // The first exchange doesn't offer a chance for the server to send. // So drop the server flight and wait for the PTO. - let c1 = client.process(None, now).dgram(); + let c1 = client.process_output(now).dgram(); assert!(c1.is_some()); now += RTT / 2; - let s1 = server.process(c1.as_ref(), now).dgram(); + let s1 = server.process(c1, now).dgram(); assert!(s1.is_some()); // Drop the server flight. Then send some data. @@ -450,10 +450,10 @@ fn coalesce_05rtt() { // The server should then send its entire flight again, // including the application data, which it sends in a 1-RTT packet. now += AT_LEAST_PTO; - let c2 = client.process(None, now).dgram(); + let c2 = client.process_output(now).dgram(); assert!(c2.is_some()); now += RTT / 2; - let s2 = server.process(c2.as_ref(), now).dgram(); + let s2 = server.process(c2, now).dgram(); // Even though there is a 1-RTT packet at the end of the datagram, the // flight should be padded to full size. assert_eq!(s2.as_ref().unwrap().len(), server.plpmtu()); @@ -462,7 +462,7 @@ fn coalesce_05rtt() { // packet until authentication completes though. So it saves it. now += RTT / 2; assert_eq!(client.stats().dropped_rx, 0); - mem::drop(client.process(s2.as_ref(), now).dgram()); + mem::drop(client.process(s2, now).dgram()); // This packet will contain an ACK, but we can ignore it. assert_eq!(client.stats().dropped_rx, 0); assert_eq!(client.stats().packets_rx, 3); @@ -470,7 +470,7 @@ fn coalesce_05rtt() { // After (successful) authentication, the packet is processed. maybe_authenticate(&mut client); - let c3 = client.process(None, now).dgram(); + let c3 = client.process_output(now).dgram(); assert!(c3.is_some()); assert_eq!(client.stats().dropped_rx, 0); // No Initial padding. assert_eq!(client.stats().packets_rx, 4); @@ -479,11 +479,11 @@ fn coalesce_05rtt() { // Allow the handshake to complete. now += RTT / 2; - let s3 = server.process(c3.as_ref(), now).dgram(); + let s3 = server.process(c3, now).dgram(); assert!(s3.is_some()); assert_eq!(*server.state(), State::Confirmed); now += RTT / 2; - mem::drop(client.process(s3.as_ref(), now).dgram()); + mem::drop(client.process(s3, now).dgram()); assert_eq!(*client.state(), State::Confirmed); assert_eq!(client.stats().dropped_rx, 0); // No dropped packets. @@ -496,11 +496,11 @@ fn reorder_handshake() { let mut server = default_server(); let mut now = now(); - let c1 = client.process(None, now).dgram(); + let c1 = client.process_output(now).dgram(); assert!(c1.is_some()); now += RTT / 2; - let s1 = server.process(c1.as_ref(), now).dgram(); + let s1 = server.process(c1, now).dgram(); assert!(s1.is_some()); // Drop the Initial packet from this. @@ -510,7 +510,7 @@ fn reorder_handshake() { // Pass just the handshake packet in and the client can't handle it yet. // It can only send another Initial packet. now += RTT / 2; - let dgram = client.process(s_hs.as_ref(), now).dgram(); + let dgram = client.process(s_hs, now).dgram(); assertions::assert_initial(dgram.as_ref().unwrap(), false); assert_eq!(client.stats().saved_datagrams, 1); assert_eq!(client.stats().packets_rx, 1); @@ -519,9 +519,9 @@ fn reorder_handshake() { // Though we currently allow the server to arm its PTO timer, use // a second client Initial packet to cause it to send again. now += AT_LEAST_PTO; - let c2 = client.process(None, now).dgram(); + let c2 = client.process_output(now).dgram(); now += RTT / 2; - let s2 = server.process(c2.as_ref(), now).dgram(); + let s2 = server.process(c2, now).dgram(); assert!(s2.is_some()); let (s_init, s_hs) = split_datagram(&s2.unwrap()); @@ -529,28 +529,28 @@ fn reorder_handshake() { // Processing the Handshake packet first should save it. now += RTT / 2; - client.process_input(&s_hs.unwrap(), now); + client.process_input(s_hs.unwrap(), now); assert_eq!(client.stats().saved_datagrams, 2); assert_eq!(client.stats().packets_rx, 2); - client.process_input(&s_init, now); + client.process_input(s_init, now); // Each saved packet should now be "received" again. assert_eq!(client.stats().packets_rx, 7); maybe_authenticate(&mut client); - let c3 = client.process(None, now).dgram(); + let c3 = client.process_output(now).dgram(); assert!(c3.is_some()); // Note that though packets were saved and processed very late, // they don't cause the RTT to change. now += RTT / 2; - let s3 = server.process(c3.as_ref(), now).dgram(); + let s3 = server.process(c3, now).dgram(); assert_eq!(*server.state(), State::Confirmed); // Don't check server RTT estimate as it will be inflated due to // it making a guess based on retransmissions when it dropped // the Initial packet number space. now += RTT / 2; - client.process_input(&s3.unwrap(), now); + client.process_input(s3.unwrap(), now); assert_eq!(*client.state(), State::Confirmed); assert_eq!(client.paths.rtt(), RTT); } @@ -563,24 +563,24 @@ fn reorder_1rtt() { let mut server = default_server(); let mut now = now(); - let c1 = client.process(None, now).dgram(); + let c1 = client.process_output(now).dgram(); assert!(c1.is_some()); now += RTT / 2; - let s1 = server.process(c1.as_ref(), now).dgram(); + let s1 = server.process(c1, now).dgram(); assert!(s1.is_some()); now += RTT / 2; - client.process_input(&s1.unwrap(), now); + client.process_input(s1.unwrap(), now); maybe_authenticate(&mut client); - let c2 = client.process(None, now).dgram(); + let c2 = client.process_output(now).dgram(); assert!(c2.is_some()); // Now get a bunch of packets from the client. // Give them to the server before giving it `c2`. for _ in 0..PACKETS { let d = send_something(&mut client, now); - server.process_input(&d, now + RTT / 2); + server.process_input(d, now + RTT / 2); } // The server has now received those packets, and saved them. // The two extra received are Initial + the junk we use for padding. @@ -589,7 +589,7 @@ fn reorder_1rtt() { assert_eq!(server.stats().dropped_rx, 1); now += RTT / 2; - let s2 = server.process(c2.as_ref(), now).dgram(); + let s2 = server.process(c2, now).dgram(); // The server has now received those packets, and saved them. // The two additional are a Handshake and a 1-RTT (w/ NEW_CONNECTION_ID). assert_eq!(server.stats().packets_rx, PACKETS * 2 + 4); @@ -599,7 +599,7 @@ fn reorder_1rtt() { assert_eq!(server.paths.rtt(), RTT); now += RTT / 2; - client.process_input(&s2.unwrap(), now); + client.process_input(s2.unwrap(), now); assert_eq!(client.paths.rtt(), RTT); // All the stream data that was sent should now be available. @@ -627,7 +627,7 @@ fn reorder_1rtt() { fn corrupted_initial() { let mut client = default_client(); let mut server = default_server(); - let d = client.process(None, now()).dgram().unwrap(); + let d = client.process_output(now()).dgram().unwrap(); let mut corrupted = Vec::from(&d[..]); // Find the last non-zero value and corrupt that. let (idx, _) = corrupted @@ -638,7 +638,7 @@ fn corrupted_initial() { .unwrap(); corrupted[idx] ^= 0x76; let dgram = Datagram::new(d.source(), d.destination(), d.tos(), corrupted); - server.process_input(&dgram, now()); + server.process_input(dgram, now()); // The server should have received two packets, // the first should be dropped, the second saved. assert_eq!(server.stats().packets_rx, 2); @@ -655,14 +655,14 @@ fn verify_pkt_honors_mtu() { let now = now(); - let res = client.process(None, now); + let res = client.process_output(now); let idle_timeout = ConnectionParameters::default().get_idle_timeout(); assert_eq!(res, Output::Callback(idle_timeout)); // Try to send a large stream and verify first packet is correctly sized let stream_id = client.stream_create(StreamType::UniDi).unwrap(); assert_eq!(client.stream_send(stream_id, &[0xbb; 2000]).unwrap(), 2000); - let pkt0 = client.process(None, now); + let pkt0 = client.process_output(now); assert!(matches!(pkt0, Output::Datagram(_))); assert_eq!(pkt0.as_dgram_ref().unwrap().len(), client.plpmtu()); } @@ -673,10 +673,10 @@ fn extra_initial_hs() { let mut server = default_server(); let mut now = now(); - let c_init = client.process(None, now).dgram(); + let c_init = client.process_output(now).dgram(); assert!(c_init.is_some()); now += DEFAULT_RTT / 2; - let s_init = server.process(c_init.as_ref(), now).dgram(); + let s_init = server.process(c_init, now).dgram(); assert!(s_init.is_some()); now += DEFAULT_RTT / 2; @@ -688,28 +688,28 @@ fn extra_initial_hs() { // Do that EXTRA_INITIALS times and each time the client will emit // another Initial packet. for _ in 0..=super::super::EXTRA_INITIALS { - let c_init = client.process(undecryptable.as_ref(), now).dgram(); + let c_init = client.process(undecryptable.clone(), now).dgram(); assertions::assert_initial(c_init.as_ref().unwrap(), false); now += DEFAULT_RTT / 10; } // After EXTRA_INITIALS, the client stops sending Initial packets. - let nothing = client.process(undecryptable.as_ref(), now).dgram(); + let nothing = client.process(undecryptable, now).dgram(); assert!(nothing.is_none()); // Until PTO, where another Initial can be used to complete the handshake. now += AT_LEAST_PTO; - let c_init = client.process(None, now).dgram(); + let c_init = client.process_output(now).dgram(); assertions::assert_initial(c_init.as_ref().unwrap(), false); now += DEFAULT_RTT / 2; - let s_init = server.process(c_init.as_ref(), now).dgram(); + let s_init = server.process(c_init, now).dgram(); now += DEFAULT_RTT / 2; - client.process_input(&s_init.unwrap(), now); + client.process_input(s_init.unwrap(), now); maybe_authenticate(&mut client); let c_fin = client.process_output(now).dgram(); assert_eq!(*client.state(), State::Connected); now += DEFAULT_RTT / 2; - server.process_input(&c_fin.unwrap(), now); + server.process_input(c_fin.unwrap(), now); assert_eq!(*server.state(), State::Confirmed); } @@ -719,10 +719,10 @@ fn extra_initial_invalid_cid() { let mut server = default_server(); let mut now = now(); - let c_init = client.process(None, now).dgram(); + let c_init = client.process_output(now).dgram(); assert!(c_init.is_some()); now += DEFAULT_RTT / 2; - let s_init = server.process(c_init.as_ref(), now).dgram(); + let s_init = server.process(c_init, now).dgram(); assert!(s_init.is_some()); now += DEFAULT_RTT / 2; @@ -734,7 +734,7 @@ fn extra_initial_invalid_cid() { assert_ne!(copy[5], 0); // The DCID should be non-zero length. copy[6] ^= 0xc4; let dgram_copy = Datagram::new(hs.destination(), hs.source(), hs.tos(), copy); - let nothing = client.process(Some(&dgram_copy), now).dgram(); + let nothing = client.process(Some(dgram_copy), now).dgram(); assert!(nothing.is_none()); } @@ -783,7 +783,7 @@ fn anti_amplification() { let c_init = client.process_output(now).dgram(); now += DEFAULT_RTT / 2; - let s_init1 = server.process(c_init.as_ref(), now).dgram().unwrap(); + let s_init1 = server.process(c_init, now).dgram().unwrap(); assert_eq!(s_init1.len(), server.plpmtu()); let s_init2 = server.process_output(now).dgram().unwrap(); assert_eq!(s_init2.len(), server.plpmtu()); @@ -795,11 +795,11 @@ fn anti_amplification() { assert_eq!(cb, server.conn_params.get_idle_timeout()); now += DEFAULT_RTT / 2; - client.process_input(&s_init1, now); - client.process_input(&s_init2, now); + client.process_input(s_init1, now); + client.process_input(s_init2, now); let ack_count = client.stats().frame_tx.ack; let frame_count = client.stats().frame_tx.all(); - let ack = client.process(Some(&s_init3), now).dgram().unwrap(); + let ack = client.process(Some(s_init3), now).dgram().unwrap(); assert!(!maybe_authenticate(&mut client)); // No need yet. // The client sends a padded datagram, with just ACK for Handshake. @@ -808,16 +808,16 @@ fn anti_amplification() { assert_ne!(ack.len(), client.plpmtu()); // Not padded (it includes Handshake). now += DEFAULT_RTT / 2; - let remainder = server.process(Some(&ack), now).dgram(); + let remainder = server.process(Some(ack), now).dgram(); now += DEFAULT_RTT / 2; - client.process_input(&remainder.unwrap(), now); + client.process_input(remainder.unwrap(), now); assert!(maybe_authenticate(&mut client)); // OK, we have all of it. let fin = client.process_output(now).dgram(); assert_eq!(*client.state(), State::Connected); now += DEFAULT_RTT / 2; - server.process_input(&fin.unwrap(), now); + server.process_input(fin.unwrap(), now); assert_eq!(*server.state(), State::Confirmed); } @@ -833,17 +833,17 @@ fn garbage_initial() { corrupted.push(initial[initial.len() - 1] ^ 0xb7); corrupted.extend_from_slice(rest.as_ref().map_or(&[], |r| &r[..])); let garbage = datagram(corrupted); - assert_eq!(Output::None, server.process(Some(&garbage), now())); + assert_eq!(Output::None, server.process(Some(garbage), now())); } #[test] fn drop_initial_packet_from_wrong_address() { let mut client = default_client(); - let out = client.process(None, now()); + let out = client.process_output(now()); assert!(out.as_dgram_ref().is_some()); let mut server = default_server(); - let out = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_some()); let p = out.dgram().unwrap(); @@ -854,24 +854,24 @@ fn drop_initial_packet_from_wrong_address() { &p[..], ); - let out = client.process(Some(&dgram), now()); + let out = client.process(Some(dgram), now()); assert!(out.as_dgram_ref().is_none()); } #[test] fn drop_handshake_packet_from_wrong_address() { let mut client = default_client(); - let out = client.process(None, now()); + let out = client.process_output(now()); assert!(out.as_dgram_ref().is_some()); let mut server = default_server(); - let out = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_some()); let (s_in, s_hs) = split_datagram(&out.dgram().unwrap()); // Pass the initial packet. - mem::drop(client.process(Some(&s_in), now()).dgram()); + mem::drop(client.process(Some(s_in), now()).dgram()); let p = s_hs.unwrap(); let dgram = Datagram::new( @@ -881,7 +881,7 @@ fn drop_handshake_packet_from_wrong_address() { &p[..], ); - let out = client.process(Some(&dgram), now()); + let out = client.process(Some(dgram), now()); assert!(out.as_dgram_ref().is_none()); } @@ -930,8 +930,8 @@ fn ech_retry() { .unwrap(); let dgram = client.process_output(now()).dgram(); - let dgram = server.process(dgram.as_ref(), now()).dgram(); - client.process_input(&dgram.unwrap(), now()); + let dgram = server.process(dgram, now()).dgram(); + client.process_input(dgram.unwrap(), now()); let auth_event = ConnectionEvent::EchFallbackAuthenticationNeeded { public_name: String::from(ECH_PUBLIC_NAME), }; @@ -941,7 +941,7 @@ fn ech_retry() { // Tell the server about the error. let dgram = client.process_output(now()).dgram(); - server.process_input(&dgram.unwrap(), now()); + server.process_input(dgram.unwrap(), now()); assert_eq!( server.state().error(), Some(&CloseReason::Transport(Error::PeerError(0x100 + 121))) @@ -985,8 +985,8 @@ fn ech_retry_fallback_rejected() { .unwrap(); let dgram = client.process_output(now()).dgram(); - let dgram = server.process(dgram.as_ref(), now()).dgram(); - client.process_input(&dgram.unwrap(), now()); + let dgram = server.process(dgram, now()).dgram(); + client.process_input(dgram.unwrap(), now()); let auth_event = ConnectionEvent::EchFallbackAuthenticationNeeded { public_name: String::from(ECH_PUBLIC_NAME), }; @@ -1000,7 +1000,7 @@ fn ech_retry_fallback_rejected() { // Pass the error on. let dgram = client.process_output(now()).dgram(); - server.process_input(&dgram.unwrap(), now()); + server.process_input(dgram.unwrap(), now()); assert_eq!( server.state().error(), Some(&CloseReason::Transport(Error::PeerError(298))) @@ -1018,13 +1018,13 @@ fn bad_min_ack_delay() { let mut client = default_client(); let dgram = client.process_output(now()).dgram(); - let dgram = server.process(dgram.as_ref(), now()).dgram(); - client.process_input(&dgram.unwrap(), now()); + let dgram = server.process(dgram, now()).dgram(); + client.process_input(dgram.unwrap(), now()); client.authenticated(AuthenticationStatus::Ok, now()); assert_eq!(client.state().error(), Some(&EXPECTED_ERROR)); let dgram = client.process_output(now()).dgram(); - server.process_input(&dgram.unwrap(), now()); + server.process_input(dgram.unwrap(), now()); assert_eq!( server.state().error(), Some(&CloseReason::Transport(Error::PeerError( @@ -1044,7 +1044,7 @@ fn only_server_initial() { let client_dgram = client.process_output(now).dgram(); // Now fetch two flights of messages from the server. - let server_dgram1 = server.process(client_dgram.as_ref(), now).dgram(); + let server_dgram1 = server.process(client_dgram, now).dgram(); let server_dgram2 = server.process_output(now + AT_LEAST_PTO).dgram(); // Only pass on the Initial from the first. We should get a Handshake in return. @@ -1054,7 +1054,7 @@ fn only_server_initial() { // The client will not acknowledge the Initial as it discards keys. // It sends a Handshake probe instead, containing just a PING frame. assert_eq!(client.stats().frame_tx.ping, 0); - let probe = client.process(Some(&initial), now).dgram(); + let probe = client.process(Some(initial), now).dgram(); assertions::assert_handshake(&probe.unwrap()); assert_eq!(client.stats().dropped_rx, 0); assert_eq!(client.stats().frame_tx.ping, 1); @@ -1066,17 +1066,17 @@ fn only_server_initial() { now += AT_LEAST_PTO; assert_eq!(client.stats().frame_tx.ping, 1); let discarded = client.stats().dropped_rx; - let probe = client.process(Some(&initial), now).dgram(); + let probe = client.process(Some(initial), now).dgram(); assertions::assert_handshake(&probe.unwrap()); assert_eq!(client.stats().frame_tx.ping, 2); assert_eq!(client.stats().dropped_rx, discarded + 1); // Pass the Handshake packet and complete the handshake. - client.process_input(&handshake.unwrap(), now); + client.process_input(handshake.unwrap(), now); maybe_authenticate(&mut client); let dgram = client.process_output(now).dgram(); - let dgram = server.process(dgram.as_ref(), now).dgram(); - client.process_input(&dgram.unwrap(), now); + let dgram = server.process(dgram, now).dgram(); + client.process_input(dgram.unwrap(), now); assert_eq!(*client.state(), State::Confirmed); assert_eq!(*server.state(), State::Confirmed); @@ -1102,25 +1102,25 @@ fn no_extra_probes_after_confirmed() { // Finally, run the handshake. now += AT_LEAST_PTO * 2; let dgram = client.process_output(now).dgram(); - let dgram = server.process(dgram.as_ref(), now).dgram(); + let dgram = server.process(dgram, now).dgram(); // The server should have dropped the Initial keys now, so passing in the Initial // should elicit a retransmit rather than having it completely ignored. - let spare_handshake = server.process(Some(&replay_initial), now).dgram(); + let spare_handshake = server.process(Some(replay_initial), now).dgram(); assert!(spare_handshake.is_some()); - client.process_input(&dgram.unwrap(), now); + client.process_input(dgram.unwrap(), now); maybe_authenticate(&mut client); let dgram = client.process_output(now).dgram(); - let dgram = server.process(dgram.as_ref(), now).dgram(); - client.process_input(&dgram.unwrap(), now); + let dgram = server.process(dgram, now).dgram(); + client.process_input(dgram.unwrap(), now); assert_eq!(*client.state(), State::Confirmed); assert_eq!(*server.state(), State::Confirmed); - let probe = server.process(spare_initial.as_ref(), now).dgram(); + let probe = server.process(spare_initial, now).dgram(); assert!(probe.is_none()); - let probe = client.process(spare_handshake.as_ref(), now).dgram(); + let probe = client.process(spare_handshake, now).dgram(); assert!(probe.is_none()); } @@ -1133,12 +1133,12 @@ fn implicit_rtt_server() { let dgram = client.process_output(now).dgram(); now += RTT / 2; - let dgram = server.process(dgram.as_ref(), now).dgram(); + let dgram = server.process(dgram, now).dgram(); now += RTT / 2; - let dgram = client.process(dgram.as_ref(), now).dgram(); + let dgram = client.process(dgram, now).dgram(); assertions::assert_handshake(dgram.as_ref().unwrap()); now += RTT / 2; - server.process_input(&dgram.unwrap(), now); + server.process_input(dgram.unwrap(), now); // The server doesn't receive any acknowledgments, but it can infer // an RTT estimate from having discarded the Initial packet number space. @@ -1157,14 +1157,14 @@ fn emit_authentication_needed_once() { ) .expect("create a server"); - let client1 = client.process(None, now()); + let client1 = client.process_output(now()); assert!(client1.as_dgram_ref().is_some()); // The entire server flight doesn't fit in a single packet because the // certificate is large, therefore the server will produce 2 packets. - let server1 = server.process(client1.as_dgram_ref(), now()); + let server1 = server.process(client1.dgram(), now()); assert!(server1.as_dgram_ref().is_some()); - let server2 = server.process(None, now()); + let server2 = server.process_output(now()); assert!(server2.as_dgram_ref().is_some()); let authentication_needed_count = |client: &mut Connection| { @@ -1184,7 +1184,7 @@ fn emit_authentication_needed_once() { // packet, but be large enough that the CertificateVerify message does not // also fit in the same packet. Our default test setup achieves this, but // changes to the setup might invalidate this test. - _ = client.process(server1.as_dgram_ref(), now()); + _ = client.process(server1.dgram(), now()); assert_eq!(1, authentication_needed_count(&mut client)); assert!(client.peer_certificate().is_some()); @@ -1192,7 +1192,7 @@ fn emit_authentication_needed_once() { // `Connection::authenticated`. On receiving the second packet from the // server, the client must not emit a another // `ConnectionEvent::AuthenticationNeeded`. - _ = client.process(server2.as_dgram_ref(), now()); + _ = client.process(server2.dgram(), now()); assert_eq!(0, authentication_needed_count(&mut client)); } @@ -1204,7 +1204,7 @@ fn client_initial_retransmits_identical() { // Force the client to retransmit its Initial packet a number of times and make sure the // retranmissions are identical to the original. Also, verify the PTO durations. for i in 1..=5 { - let ci = client.process(None, now).dgram().unwrap(); + let ci = client.process_output(now).dgram().unwrap(); assert_eq!(ci.len(), client.plpmtu()); assert_eq!( client.stats().frame_tx, @@ -1213,7 +1213,7 @@ fn client_initial_retransmits_identical() { ..Default::default() } ); - let pto = client.process(None, now).callback(); + let pto = client.process_output(now).callback(); assert_eq!(pto, DEFAULT_RTT * 3 * (1 << (i - 1))); now += pto; } @@ -1223,14 +1223,14 @@ fn client_initial_retransmits_identical() { fn server_initial_retransmits_identical() { let mut now = now(); let mut client = default_client(); - let mut ci = client.process(None, now).dgram(); + let mut ci = client.process_output(now).dgram(); // Force the server to retransmit its Initial packet a number of times and make sure the // retranmissions are identical to the original. Also, verify the PTO durations. let mut server = default_server(); let mut total_ptos: Duration = Duration::from_secs(0); for i in 1..=3 { - let si = server.process(ci.take().as_ref(), now).dgram().unwrap(); + let si = server.process(ci.take(), now).dgram().unwrap(); assert_eq!(si.len(), server.plpmtu()); assert_eq!( server.stats().frame_tx, @@ -1241,7 +1241,7 @@ fn server_initial_retransmits_identical() { } ); - let pto = server.process(None, now).callback(); + let pto = server.process_output(now).callback(); if i < 3 { assert_eq!(pto, DEFAULT_RTT * 3 * (1 << (i - 1))); } else { diff --git a/neqo-transport/src/connection/tests/idle.rs b/neqo-transport/src/connection/tests/idle.rs index dfb59235c8..deb4312dca 100644 --- a/neqo-transport/src/connection/tests/idle.rs +++ b/neqo-transport/src/connection/tests/idle.rs @@ -40,17 +40,14 @@ fn test_idle_timeout(client: &mut Connection, server: &mut Connection, timeout: let now = now(); - let res = client.process(None, now); + let res = client.process_output(now); assert_eq!(res, Output::Callback(timeout)); // Still connected after timeout-1 seconds. Idle timer not reset - mem::drop(client.process( - None, - now + timeout.checked_sub(Duration::from_secs(1)).unwrap(), - )); + mem::drop(client.process_output(now + timeout.checked_sub(Duration::from_secs(1)).unwrap())); assert!(matches!(client.state(), State::Confirmed)); - mem::drop(client.process(None, now + timeout)); + mem::drop(client.process_output(now + timeout)); // Not connected after timeout. assert!(matches!(client.state(), State::Closed(_))); @@ -112,19 +109,19 @@ fn asymmetric_idle_timeout() { connect(&mut client, &mut server); let c1 = send_something(&mut client, now()); let c2 = send_something(&mut client, now()); - server.process_input(&c2, now()); - server.process_input(&c1, now()); + server.process_input(c2, now()); + server.process_input(c1, now()); let s1 = send_something(&mut server, now()); let s2 = send_something(&mut server, now()); - client.process_input(&s2, now()); - let ack = client.process(Some(&s1), now()).dgram(); + client.process_input(s2, now()); + let ack = client.process(Some(s1), now()).dgram(); assert!(ack.is_some()); // Now both should have received ACK frames so should be idle. + assert_eq!(server.process(ack, now()), Output::Callback(LOWER_TIMEOUT)); assert_eq!( - server.process(ack.as_ref(), now()), + client.process_output(now()), Output::Callback(LOWER_TIMEOUT) ); - assert_eq!(client.process(None, now()), Output::Callback(LOWER_TIMEOUT)); } #[test] @@ -152,17 +149,17 @@ fn tiny_idle_timeout() { let c1 = send_something(&mut client, now); let c2 = send_something(&mut client, now); now += RTT / 2; - server.process_input(&c2, now); - server.process_input(&c1, now); + server.process_input(c2, now); + server.process_input(c1, now); let s1 = send_something(&mut server, now); let s2 = send_something(&mut server, now); now += RTT / 2; - client.process_input(&s2, now); - let ack = client.process(Some(&s1), now).dgram(); + client.process_input(s2, now); + let ack = client.process(Some(s1), now).dgram(); assert!(ack.is_some()); // The client should be idle now, but with a different timer. - if let Output::Callback(t) = client.process(None, now) { + if let Output::Callback(t) = client.process_output(now) { assert!(t > LOWER_TIMEOUT); } else { panic!("Client not idle"); @@ -170,7 +167,7 @@ fn tiny_idle_timeout() { // The server should go idle after the ACK, but again with a larger timeout. now += RTT / 2; - if let Output::Callback(t) = client.process(ack.as_ref(), now) { + if let Output::Callback(t) = client.process(ack, now) { assert!(t > LOWER_TIMEOUT); } else { panic!("Client not idle"); @@ -186,7 +183,7 @@ fn idle_send_packet1() { let mut now = now(); connect_force_idle(&mut client, &mut server); - let timeout = client.process(None, now).callback(); + let timeout = client.process_output(now).callback(); assert_eq!(timeout, default_timeout()); now += Duration::from_secs(10); @@ -196,13 +193,13 @@ fn idle_send_packet1() { // Still connected after 39 seconds because idle timer reset by the // outgoing packet. now += default_timeout() - DELTA; - let dgram = client.process(None, now).dgram(); + let dgram = client.process_output(now).dgram(); assert!(dgram.is_some()); // PTO assert!(client.state().connected()); // Not connected after 40 seconds. now += DELTA; - let out = client.process(None, now); + let out = client.process_output(now); assert!(matches!(out, Output::None)); assert!(client.state().closed()); } @@ -218,7 +215,7 @@ fn idle_send_packet2() { let mut now = now(); - let timeout = client.process(None, now).callback(); + let timeout = client.process_output(now).callback(); assert_eq!(timeout, default_timeout()); // First transmission at t=GAP. @@ -231,14 +228,14 @@ fn idle_send_packet2() { // Still connected just before GAP + default_timeout(). now += default_timeout() - DELTA; - let dgram = client.process(None, now).dgram(); + let dgram = client.process_output(now).dgram(); assert!(dgram.is_some()); // PTO assert!(matches!(client.state(), State::Confirmed)); // Not connected after 40 seconds because timer not reset by second // outgoing packet now += DELTA; - let out = client.process(None, now); + let out = client.process_output(now); assert!(matches!(out, Output::None)); assert!(matches!(client.state(), State::Closed(_))); } @@ -253,7 +250,7 @@ fn idle_recv_packet() { let mut now = now(); - let res = client.process(None, now); + let res = client.process_output(now); assert_eq!(res, Output::Callback(default_timeout())); let stream = client.stream_create(StreamType::BiDi).unwrap(); @@ -264,21 +261,21 @@ fn idle_recv_packet() { // Note that it is important that this not result in the RTT increasing above 0. // Otherwise, the eventual timeout will be extended (and we're not testing that). now += Duration::from_secs(10); - let out = client.process(None, now); - server.process_input(&out.dgram().unwrap(), now); + let out = client.process_output(now); + server.process_input(out.dgram().unwrap(), now); assert_eq!(server.stream_send(stream, b"world").unwrap(), 5); let out = server.process_output(now); assert_ne!(out.as_dgram_ref(), None); - mem::drop(client.process(out.as_dgram_ref(), now)); + mem::drop(client.process(out.dgram(), now)); assert!(matches!(client.state(), State::Confirmed)); // Add a little less than the idle timeout and we're still connected. now += default_timeout() - FUDGE; - mem::drop(client.process(None, now)); + mem::drop(client.process_output(now)); assert!(matches!(client.state(), State::Confirmed)); now += FUDGE; - mem::drop(client.process(None, now)); + mem::drop(client.process_output(now)); assert!(matches!(client.state(), State::Closed(_))); } @@ -296,9 +293,9 @@ fn idle_caching() { // Perform the first round trip, but drop the Initial from the server. // The client then caches the Handshake packet. let dgram = client.process_output(start).dgram(); - let dgram = server.process(dgram.as_ref(), start).dgram(); + let dgram = server.process(dgram, start).dgram(); let (_, handshake) = split_datagram(&dgram.unwrap()); - client.process_input(&handshake.unwrap(), start); + client.process_input(handshake.unwrap(), start); // Perform an exchange and keep the connection alive. let middle = start + AT_LEAST_PTO; @@ -309,7 +306,7 @@ fn idle_caching() { mem::drop(server.process_output(middle).dgram()); // Now let the server process the RTX'ed client Initial. This causes the server // to send CRYPTO frames again, so manually extract and discard those. - server.process_input(&dgram.unwrap(), middle); + server.process_input(dgram.unwrap(), middle); let mut tokens = Vec::new(); server.crypto.streams.write_frame( PacketNumberSpace::Initial, @@ -333,7 +330,7 @@ fn idle_caching() { let (initial, _) = split_datagram(&dgram.unwrap()); let crypto_before_c = client.stats().frame_rx.crypto; let ack_before = client.stats().frame_rx.ack; - client.process_input(&initial, middle); + client.process_input(initial, middle); assert_eq!(client.stats().frame_rx.crypto, crypto_before_c); assert_eq!(client.stats().frame_rx.ack, ack_before + 1); @@ -342,11 +339,11 @@ fn idle_caching() { let dgram = server.process_output(end).dgram(); let (initial, _) = split_datagram(&dgram.unwrap()); neqo_common::qwarn!("client ingests initial, finally"); - mem::drop(client.process(Some(&initial), end)); + mem::drop(client.process(Some(initial), end)); maybe_authenticate(&mut client); let dgram = client.process_output(end).dgram(); - let dgram = server.process(dgram.as_ref(), end).dgram(); - client.process_input(&dgram.unwrap(), end); + let dgram = server.process(dgram, end).dgram(); + client.process_input(dgram.unwrap(), end); assert_eq!(*client.state(), State::Confirmed); assert_eq!(*server.state(), State::Confirmed); } @@ -375,7 +372,7 @@ fn create_stream_idle_rtt( _ = initiator.stream_send(stream, DEFAULT_STREAM_DATA).unwrap(); let req = initiator.process_output(now).dgram(); now += rtt / 2; - responder.process_input(&req.unwrap(), now); + responder.process_input(req.unwrap(), now); // Reordering two packets from the responder forces the initiator to be idle. _ = responder.stream_send(stream, DEFAULT_STREAM_DATA).unwrap(); @@ -384,15 +381,15 @@ fn create_stream_idle_rtt( let resp2 = responder.process_output(now).dgram(); now += rtt / 2; - initiator.process_input(&resp2.unwrap(), now); - initiator.process_input(&resp1.unwrap(), now); + initiator.process_input(resp2.unwrap(), now); + initiator.process_input(resp1.unwrap(), now); let ack = initiator.process_output(now).dgram(); assert!(ack.is_some()); check_idle(initiator, now); // Receiving the ACK should return the responder to idle too. now += rtt / 2; - responder.process_input(&ack.unwrap(), now); + responder.process_input(ack.unwrap(), now); check_idle(responder, now); (now, stream) @@ -428,9 +425,9 @@ fn keep_alive_initiator() { assert_eq!(server.stats().frame_tx.ping, pings_before + 1); // Exchange ack for the PING. - let out = client.process(ping.as_ref(), now).dgram(); - let out = server.process(out.as_ref(), now).dgram(); - assert!(client.process(out.as_ref(), now).dgram().is_none()); + let out = client.process(ping, now).dgram(); + let out = server.process(out, now).dgram(); + assert!(client.process(out, now).dgram().is_none()); // Check that there will be next keep-alive ping after keep_alive_timeout(). assert_idle(&mut server, now, keep_alive_timeout()); @@ -469,12 +466,12 @@ fn keep_alive_lost() { assert_eq!(server.stats().frame_tx.ping, pings_before2 + 1); // Exchange ack for the PING. - let out = client.process(ping.as_ref(), now).dgram(); + let out = client.process(ping, now).dgram(); now += Duration::from_millis(20); - let out = server.process(out.as_ref(), now).dgram(); + let out = server.process(out, now).dgram(); - assert!(client.process(out.as_ref(), now).dgram().is_none()); + assert!(client.process(out, now).dgram().is_none()); // TODO: if we run server.process with current value of now, the server will // return some small timeout for the recovry although it does not have @@ -527,10 +524,10 @@ fn keep_alive_unmark() { fn transfer_force_idle(sender: &mut Connection, receiver: &mut Connection) { let dgram = sender.process_output(now()).dgram(); let chaff = send_something(sender, now()); - receiver.process_input(&chaff, now()); - receiver.process_input(&dgram.unwrap(), now()); + receiver.process_input(chaff, now()); + receiver.process_input(dgram.unwrap(), now()); let ack = receiver.process_output(now()).dgram(); - sender.process_input(&ack.unwrap(), now()); + sender.process_input(ack.unwrap(), now()); } /// Receiving the end of the stream stops keep-alives for that stream. @@ -598,7 +595,7 @@ fn keep_alive_stop_sending() { // The server will have sent RESET_STREAM, which the client will // want to acknowledge, so force that out. let junk = send_something(&mut server, now()); - let ack = client.process(Some(&junk), now()).dgram(); + let ack = client.process(Some(junk), now()).dgram(); assert!(ack.is_some()); // Now the client should be idle. @@ -661,7 +658,7 @@ fn keep_alive_uni() { _ = client.stream_send(stream, DEFAULT_STREAM_DATA).unwrap(); let dgram = client.process_output(now()).dgram(); - server.process_input(&dgram.unwrap(), now()); + server.process_input(dgram.unwrap(), now()); server.stream_keep_alive(stream, true).unwrap(); } diff --git a/neqo-transport/src/connection/tests/keys.rs b/neqo-transport/src/connection/tests/keys.rs index ca35b8b774..59bbc2f24c 100644 --- a/neqo-transport/src/connection/tests/keys.rs +++ b/neqo-transport/src/connection/tests/keys.rs @@ -33,7 +33,7 @@ fn check_discarded( mem::drop(peer.process_output(now())); let before = peer.stats(); - let out = peer.process(Some(pkt), now()); + let out = peer.process(Some(pkt.clone()), now()); assert_eq!(out.as_dgram_ref().is_some(), response); let after = peer.stats(); assert_eq!(dropped, after.dropped_rx - before.dropped_rx); @@ -57,17 +57,17 @@ fn overwrite_invocations(n: PacketNumber) { fn discarded_initial_keys() { qdebug!("---- client: generate CH"); let mut client = default_client(); - let init_pkt_c = client.process(None, now()).dgram(); + let init_pkt_c = client.process_output(now()).dgram(); assert!(init_pkt_c.is_some()); assert_eq!(init_pkt_c.as_ref().unwrap().len(), client.plpmtu()); qdebug!("---- server: CH -> SH, EE, CERT, CV, FIN"); let mut server = default_server(); - let init_pkt_s = server.process(init_pkt_c.as_ref(), now()).dgram(); + let init_pkt_s = server.process(init_pkt_c.clone(), now()).dgram(); assert!(init_pkt_s.is_some()); qdebug!("---- client: cert verification"); - let out = client.process(init_pkt_s.as_ref(), now()).dgram(); + let out = client.process(init_pkt_s.clone(), now()).dgram(); assert!(out.is_some()); // The client has received a handshake packet. It will remove the Initial keys. @@ -86,12 +86,12 @@ fn discarded_initial_keys() { check_discarded(&mut server, &init_pkt_c.clone().unwrap(), false, 1, 1); qdebug!("---- client: SH..FIN -> FIN"); - let out = client.process(None, now()).dgram(); + let out = client.process_output(now()).dgram(); assert!(out.is_some()); // The server will process the first Handshake packet. // After this the Initial keys will be dropped. - let out = server.process(out.as_ref(), now()).dgram(); + let out = server.process(out, now()).dgram(); assert!(out.is_some()); // Check that the Initial keys are dropped at the server @@ -116,7 +116,7 @@ fn key_update_client() { // Initiating an update should only increase the write epoch. let idle_timeout = ConnectionParameters::default().get_idle_timeout(); - assert_eq!(Output::Callback(idle_timeout), client.process(None, now)); + assert_eq!(Output::Callback(idle_timeout), client.process_output(now)); assert_eq!(client.get_epochs(), (Some(4), Some(3))); // Send something to propagate the update. @@ -125,7 +125,7 @@ fn key_update_client() { // The server should now be waiting to discharge read keys. assert_eq!(server.get_epochs(), (Some(4), Some(3))); - let res = server.process(None, now); + let res = server.process_output(now); if let Output::Callback(t) = res { assert!(t < idle_timeout); } else { @@ -142,10 +142,10 @@ fn key_update_client() { // But at this point the client hasn't received a key update from the server. // It will be stuck with old keys. now += AT_LEAST_PTO; - let dgram = client.process(None, now).dgram(); + let dgram = client.process_output(now).dgram(); assert!(dgram.is_some()); // Drop this packet. assert_eq!(client.get_epochs(), (Some(4), Some(3))); - mem::drop(server.process(None, now)); + mem::drop(server.process_output(now)); assert_eq!(server.get_epochs(), (Some(4), Some(4))); // Even though the server has updated, it hasn't received an ACK yet. @@ -155,7 +155,7 @@ fn key_update_client() { // The previous PTO packet (see above) was dropped, so we should get an ACK here. let dgram = send_and_receive(&mut client, &mut server, now); assert!(dgram.is_some()); - let res = client.process(dgram.as_ref(), now); + let res = client.process(dgram, now); // This is the first packet that the client has received from the server // with new keys, so its read timer just started. if let Output::Callback(t) = res { @@ -170,7 +170,7 @@ fn key_update_client() { assert_update_blocked(&mut server); now += AT_LEAST_PTO; - mem::drop(client.process(None, now)); + mem::drop(client.process_output(now)); assert_eq!(client.get_epochs(), (Some(4), Some(4))); } @@ -194,11 +194,11 @@ fn key_update_consecutive() { assert_eq!(client.get_epochs(), (Some(4), Some(3))); // Have the server process the ACK. - if let Output::Callback(_) = server.process(dgram.as_ref(), now) { + if let Output::Callback(_) = server.process(dgram, now) { assert_eq!(server.get_epochs(), (Some(4), Some(3))); // Now move the server temporarily into the future so that it // rotates the keys. The client stays in the present. - mem::drop(server.process(None, now + AT_LEAST_PTO)); + mem::drop(server.process_output(now + AT_LEAST_PTO)); assert_eq!(server.get_epochs(), (Some(4), Some(4))); } else { panic!("server should have a timer set"); @@ -224,33 +224,33 @@ fn key_update_before_confirmed() { assert_update_blocked(&mut server); // Client Initial - let dgram = client.process(None, now()).dgram(); + let dgram = client.process_output(now()).dgram(); assert!(dgram.is_some()); assert_update_blocked(&mut client); // Server Initial + Handshake - let dgram = server.process(dgram.as_ref(), now()).dgram(); + let dgram = server.process(dgram, now()).dgram(); assert!(dgram.is_some()); assert_update_blocked(&mut server); // Client Handshake - client.process_input(&dgram.unwrap(), now()); + client.process_input(dgram.unwrap(), now()); assert_update_blocked(&mut client); assert!(maybe_authenticate(&mut client)); assert_update_blocked(&mut client); - let dgram = client.process(None, now()).dgram(); + let dgram = client.process_output(now()).dgram(); assert!(dgram.is_some()); assert_update_blocked(&mut client); // Server HANDSHAKE_DONE - let dgram = server.process(dgram.as_ref(), now()).dgram(); + let dgram = server.process(dgram, now()).dgram(); assert!(dgram.is_some()); assert!(server.initiate_key_update().is_ok()); // Client receives HANDSHAKE_DONE - let dgram = client.process(dgram.as_ref(), now()).dgram(); + let dgram = client.process(dgram, now()).dgram(); assert!(dgram.is_none()); assert!(client.initiate_key_update().is_ok()); } @@ -281,13 +281,13 @@ fn exhaust_read_keys() { let dgram = send_something(&mut client, now()); overwrite_invocations(0); - let dgram = server.process(Some(&dgram), now()).dgram(); + let dgram = server.process(Some(dgram), now()).dgram(); assert!(matches!( server.state(), State::Closed(CloseReason::Transport(Error::KeysExhausted)) )); - client.process_input(&dgram.unwrap(), now()); + client.process_input(dgram.unwrap(), now()); assert!(matches!( client.state(), State::Draining { diff --git a/neqo-transport/src/connection/tests/migration.rs b/neqo-transport/src/connection/tests/migration.rs index 541ab7dfeb..0a7d5e50b7 100644 --- a/neqo-transport/src/connection/tests/migration.rs +++ b/neqo-transport/src/connection/tests/migration.rs @@ -75,7 +75,7 @@ fn rebinding_port() { let dgram = send_something(&mut client, now()); let dgram = change_source_port(&dgram); - server.process_input(&dgram, now()); + server.process_input(dgram, now()); // Have the server send something so that it generates a packet. let stream_id = server.stream_create(StreamType::UniDi).unwrap(); server.stream_close_send(stream_id).unwrap(); @@ -97,7 +97,7 @@ fn path_forwarding_attack() { let dgram = send_something(&mut client, now); let dgram = change_path(&dgram, DEFAULT_ADDR_V4); - server.process_input(&dgram, now); + server.process_input(dgram, now); // The server now probes the new (primary) path. let new_probe = server.process_output(now).dgram().unwrap(); @@ -117,14 +117,14 @@ fn path_forwarding_attack() { // The client should respond to the challenge on the new path. // The server couldn't pad, so the client is also amplification limited. - let new_resp = client.process(Some(&new_probe), now).dgram().unwrap(); + let new_resp = client.process(Some(new_probe), now).dgram().unwrap(); assert_eq!(client.stats().frame_rx.path_challenge, 1); assert_eq!(client.stats().frame_tx.path_challenge, 1); assert_eq!(client.stats().frame_tx.path_response, 1); assert_v4_path(&new_resp, false); // The client also responds to probes on the old path. - let old_resp = client.process(Some(&old_probe), now).dgram().unwrap(); + let old_resp = client.process(Some(old_probe), now).dgram().unwrap(); assert_eq!(client.stats().frame_rx.path_challenge, 2); assert_eq!(client.stats().frame_tx.path_challenge, 1); assert_eq!(client.stats().frame_tx.path_response, 2); @@ -137,12 +137,12 @@ fn path_forwarding_attack() { // Receiving the PATH_RESPONSE from the client opens the amplification // limit enough for the server to respond. // This is padded because it includes PATH_CHALLENGE. - let server_data1 = server.process(Some(&new_resp), now).dgram().unwrap(); + let server_data1 = server.process(Some(new_resp), now).dgram().unwrap(); assert_v4_path(&server_data1, true); assert_eq!(server.stats().frame_tx.path_challenge, 3); // The client responds to this probe on the new path. - client.process_input(&server_data1, now); + client.process_input(server_data1, now); let stream_before = client.stats().frame_tx.stream; let padded_resp = send_something(&mut client, now); assert_eq!(stream_before, client.stats().frame_tx.stream); @@ -157,7 +157,7 @@ fn path_forwarding_attack() { assert_v4_path(&server_data2, false); // Until new data is received from the client on the old path. - server.process_input(&client_data2, now); + server.process_input(client_data2, now); // The server sends a probe on the new path. let server_data3 = send_something(&mut server, now); assert_v4_path(&server_data3, true); @@ -185,7 +185,7 @@ fn migrate_immediate() { let server_delayed = send_something(&mut server, now); // The server accepts the first packet and migrates (but probes). - let server1 = server.process(Some(&client1), now).dgram().unwrap(); + let server1 = server.process(Some(client1), now).dgram().unwrap(); assert_v4_path(&server1, true); let server2 = server.process_output(now).dgram().unwrap(); assert_v6_path(&server2, true); @@ -193,13 +193,13 @@ fn migrate_immediate() { // The second packet has no real effect, it just elicits an ACK. let all_before = server.stats().frame_tx.all(); let ack_before = server.stats().frame_tx.ack; - let server3 = server.process(Some(&client2), now).dgram(); + let server3 = server.process(Some(client2), now).dgram(); assert!(server3.is_some()); assert_eq!(server.stats().frame_tx.all(), all_before + 1); assert_eq!(server.stats().frame_tx.ack, ack_before + 1); // Receiving a packet sent by the server before migration doesn't change path. - client.process_input(&server_delayed, now); + client.process_input(server_delayed, now); // The client has sent two unpaced packets and this new path has no RTT estimate // so this might be paced. let (client3, _t) = send_something_paced(&mut client, now, true); @@ -287,13 +287,13 @@ fn migrate_same() { assert_v6_path(&probe, true); // Contains PATH_CHALLENGE. assert_eq!(client.stats().frame_tx.path_challenge, 1); - let resp = server.process(Some(&probe), now).dgram().unwrap(); + let resp = server.process(Some(probe), now).dgram().unwrap(); assert_v6_path(&resp, true); assert_eq!(server.stats().frame_tx.path_response, 1); assert_eq!(server.stats().frame_tx.path_challenge, 0); // Everything continues happily. - client.process_input(&resp, now); + client.process_input(resp, now); let contd = send_something(&mut client, now); assert_v6_path(&contd, false); } @@ -371,7 +371,7 @@ fn migration(mut client: Connection) { assert_eq!(client.stats().frame_tx.path_challenge, 1); let probe_cid = ConnectionId::from(get_cid(&probe)); - let resp = server.process(Some(&probe), now).dgram().unwrap(); + let resp = server.process(Some(probe), now).dgram().unwrap(); assert_v4_path(&resp, true); assert_eq!(server.stats().frame_tx.path_response, 1); assert_eq!(server.stats().frame_tx.path_challenge, 1); @@ -380,12 +380,12 @@ fn migration(mut client: Connection) { let client_data = send_something(&mut client, now); assert_ne!(get_cid(&client_data), probe_cid); assert_v6_path(&client_data, false); - server.process_input(&client_data, now); + server.process_input(client_data, now); let server_data = send_something(&mut server, now); assert_v6_path(&server_data, false); // Once the client receives the probe response, it migrates to the new path. - client.process_input(&resp, now); + client.process_input(resp, now); assert_eq!(client.stats().frame_rx.path_challenge, 1); let migrate_client = send_something(&mut client, now); assert_v4_path(&migrate_client, true); // Responds to server probe. @@ -394,7 +394,7 @@ fn migration(mut client: Connection) { // However, it will probe the old path again, even though it has just // received a response to its last probe, because it needs to verify // that the migration is genuine. - server.process_input(&migrate_client, now); + server.process_input(migrate_client, now); let stream_before = server.stats().frame_tx.stream; let probe_old_server = send_something(&mut server, now); // This is just the double-check probe; no STREAM frames. @@ -409,8 +409,8 @@ fn migration(mut client: Connection) { assert_eq!(server.stats().frame_tx.stream, stream_before + 1); // The client receives these checks and responds to the probe, but uses the new path. - client.process_input(&migrate_server, now); - client.process_input(&probe_old_server, now); + client.process_input(migrate_server, now); + client.process_input(probe_old_server, now); let old_probe_resp = send_something(&mut client, now); assert_v6_path(&old_probe_resp, true); let client_confirmation = client.process_output(now).dgram().unwrap(); @@ -450,11 +450,11 @@ fn migration_client_empty_cid() { /// Returns the packet containing `HANDSHAKE_DONE` from the server. fn fast_handshake(client: &mut Connection, server: &mut Connection) -> Option { let dgram = client.process_output(now()).dgram(); - let dgram = server.process(dgram.as_ref(), now()).dgram(); - client.process_input(&dgram.unwrap(), now()); + let dgram = server.process(dgram, now()).dgram(); + client.process_input(dgram.unwrap(), now()); assert!(maybe_authenticate(client)); let dgram = client.process_output(now()).dgram(); - server.process(dgram.as_ref(), now()).dgram() + server.process(dgram, now()).dgram() } fn preferred_address(hs_client: SocketAddr, hs_server: SocketAddr, preferred: SocketAddr) { @@ -512,7 +512,7 @@ fn preferred_address(hs_client: SocketAddr, hs_server: SocketAddr, preferred: So // The client is about to process HANDSHAKE_DONE. // It should start probing toward the server's preferred address. - let probe = client.process(dgram.as_ref(), now()).dgram().unwrap(); + let probe = client.process(dgram, now()).dgram().unwrap(); assert_toward_spa(&probe, true); assert_eq!(client.stats().frame_tx.path_challenge, 1); assert_ne!(client.process_output(now()).callback(), Duration::new(0, 0)); @@ -522,26 +522,26 @@ fn preferred_address(hs_client: SocketAddr, hs_server: SocketAddr, preferred: So assert_orig_path(&data, false); // The server responds to the probe. - let resp = server.process(Some(&probe), now()).dgram().unwrap(); + let resp = server.process(Some(probe), now()).dgram().unwrap(); assert_from_spa(&resp, true); assert_eq!(server.stats().frame_tx.path_challenge, 1); assert_eq!(server.stats().frame_tx.path_response, 1); // Data continues on the main path for the server. - server.process_input(&data, now()); + server.process_input(data, now()); let data = send_something(&mut server, now()); assert_orig_path(&data, false); // Client gets the probe response back and it migrates. - client.process_input(&resp, now()); - client.process_input(&data, now()); + client.process_input(resp, now()); + client.process_input(data, now()); let data = send_something(&mut client, now()); assert_toward_spa(&data, true); assert_eq!(client.stats().frame_tx.stream, 2); assert_eq!(client.stats().frame_tx.path_response, 1); // The server sees the migration and probes the old path. - let probe = server.process(Some(&data), now()).dgram().unwrap(); + let probe = server.process(Some(data), now()).dgram().unwrap(); assert_orig_path(&probe, true); assert_eq!(server.stats().frame_tx.path_challenge, 2); @@ -583,7 +583,7 @@ fn expect_no_migration(client: &mut Connection, server: &mut Connection) { let dgram = fast_handshake(client, server); // The client won't probe now, though it could; it remains idle. - let out = client.process(dgram.as_ref(), now()); + let out = client.process(dgram, now()); assert_ne!(out.callback(), Duration::new(0, 0)); // Data continues on the main path for the client. @@ -708,14 +708,14 @@ fn migration_invalid_state() { assert!(client .migrate(Some(DEFAULT_ADDR), Some(DEFAULT_ADDR), false, now()) .is_err()); - let close = client.process(None, now()).dgram(); + let close = client.process_output(now()).dgram(); - let dgram = server.process(close.as_ref(), now()).dgram(); + let dgram = server.process(close, now()).dgram(); assert!(server .migrate(Some(DEFAULT_ADDR), Some(DEFAULT_ADDR), false, now()) .is_err()); - client.process_input(&dgram.unwrap(), now()); + client.process_input(dgram.unwrap(), now()); assert!(client .migrate(Some(DEFAULT_ADDR), Some(DEFAULT_ADDR), false, now()) .is_err()); @@ -814,7 +814,7 @@ fn retire_all() { let new_cid_before = client.stats().frame_rx.new_connection_id; let retire_cid_before = client.stats().frame_tx.retire_connection_id; - client.process_input(&ncid, now()); + client.process_input(ncid, now()); let retire = send_something(&mut client, now()); assert_eq!( client.stats().frame_rx.new_connection_id, @@ -861,17 +861,17 @@ fn retire_prior_to_migration_failure() { // retire all of the available connection IDs. let retire_all = send_with_extra(&mut server, RetireAll { cid_gen }, now()); - let resp = server.process(Some(&probe), now()).dgram().unwrap(); + let resp = server.process(Some(probe), now()).dgram().unwrap(); assert_v4_path(&resp, true); assert_eq!(server.stats().frame_tx.path_response, 1); assert_eq!(server.stats().frame_tx.path_challenge, 1); // Have the client receive the NEW_CONNECTION_ID with Retire Prior To. - client.process_input(&retire_all, now()); + client.process_input(retire_all, now()); // This packet contains the probe response, which should be fine, but it // also includes PATH_CHALLENGE for the new path, and the client can't // respond without a connection ID. We treat this as a connection error. - client.process_input(&resp, now()); + client.process_input(resp, now()); assert!(matches!( client.state(), State::Closing { @@ -914,15 +914,15 @@ fn retire_prior_to_migration_success() { // retire all of the available connection IDs. let retire_all = send_with_extra(&mut server, RetireAll { cid_gen }, now()); - let resp = server.process(Some(&probe), now()).dgram().unwrap(); + let resp = server.process(Some(probe), now()).dgram().unwrap(); assert_v4_path(&resp, true); assert_eq!(server.stats().frame_tx.path_response, 1); assert_eq!(server.stats().frame_tx.path_challenge, 1); // Have the client receive the NEW_CONNECTION_ID with Retire Prior To second. // As this occurs in a very specific order, migration succeeds. - client.process_input(&resp, now()); - client.process_input(&retire_all, now()); + client.process_input(resp, now()); + client.process_input(retire_all, now()); // Migration succeeds and the new path gets the last connection ID. let dgram = send_something(&mut client, now()); @@ -952,12 +952,12 @@ fn error_on_new_path_with_no_connection_id() { Rc::new(RefCell::new(CountingConnectionIdGenerator::default())); let retire_all = send_with_extra(&mut server, RetireAll { cid_gen }, now()); - client.process_input(&retire_all, now()); + client.process_input(retire_all, now()); let garbage = send_with_extra(&mut server, GarbageWriter {}, now()); let dgram = change_path(&garbage, DEFAULT_ADDR_V4); - client.process_input(&dgram, now()); + client.process_input(dgram, now()); // See issue #1697. We had a crash when the client had a temporary path and // process_output is called. @@ -972,7 +972,7 @@ fn error_on_new_path_with_no_connection_id() { )); // Wait until the connection is closed. let mut now = now(); - now += client.process(None, now).callback(); + now += client.process_output(now).callback(); _ = client.process_output(now); // No closing frames should be sent, and the connection should be closed. assert_eq!(client.stats().frame_tx.connection_close, closing_frames); diff --git a/neqo-transport/src/connection/tests/mod.rs b/neqo-transport/src/connection/tests/mod.rs index c2cf4db391..ee87505373 100644 --- a/neqo-transport/src/connection/tests/mod.rs +++ b/neqo-transport/src/connection/tests/mod.rs @@ -208,7 +208,7 @@ fn handshake_with_modifier( if should_ping { a.test_frame_writer = Some(Box::new(PingWriter {})); } - let output = a.process(input.as_ref(), now).dgram(); + let output = a.process(input, now).dgram(); if should_ping { a.test_frame_writer = None; did_ping[a.role()] = true; @@ -219,7 +219,7 @@ fn handshake_with_modifier( mem::swap(&mut a, &mut b); } if let Some(d) = input { - a.process_input(&d, now); + a.process_input(d, now); } now } @@ -299,7 +299,7 @@ fn exchange_ticket( server.send_ticket(now, &[]).expect("can send ticket"); let ticket = server.process_output(now).dgram(); assert!(ticket.is_some()); - client.process_input(&ticket.unwrap(), now); + client.process_input(ticket.unwrap(), now); assert_eq!(*client.state(), State::Confirmed); get_tokens(client).pop().expect("should have token") } @@ -397,7 +397,7 @@ fn fill_cwnd(c: &mut Connection, stream: StreamId, mut now: Instant) -> (Vec() + total_dgrams.iter().map(Datagram::len).sum::() ); (total_dgrams, now) } @@ -415,7 +415,7 @@ fn increase_cwnd( let pkt = sender.process_output(now); match pkt { Output::Datagram(dgram) => { - receiver.process_input(&dgram, now + DEFAULT_RTT / 2); + receiver.process_input(dgram, now + DEFAULT_RTT / 2); } Output::Callback(t) => { if t < DEFAULT_RTT { @@ -432,7 +432,7 @@ fn increase_cwnd( now += DEFAULT_RTT / 2; let ack = receiver.process_output(now).dgram(); now += DEFAULT_RTT / 2; - sender.process_input(&ack.unwrap(), now); + sender.process_input(ack.unwrap(), now); now } @@ -453,7 +453,7 @@ where let in_dgrams = in_dgrams.into_iter(); qdebug!([dest], "ack_bytes {} datagrams", in_dgrams.len()); for dgram in in_dgrams { - dest.process_input(&dgram, now); + dest.process_input(dgram, now); } loop { @@ -524,7 +524,7 @@ fn induce_persistent_congestion( // An ACK for the third PTO causes persistent congestion. let s_ack = ack_bytes(server, stream, c_tx_dgrams, now); - client.process_input(&s_ack, now); + client.process_input(s_ack, now); assert_eq!(cwnd(client), cwnd_min(client)); now } @@ -635,7 +635,7 @@ fn send_with_modifier_and_receive( modifier: fn(Datagram) -> Option, ) -> Option { let dgram = send_something_with_modifier(sender, now, modifier); - receiver.process(Some(&dgram), now).dgram() + receiver.process(Some(dgram), now).dgram() } /// Send something on a stream from `sender` to `receiver`. diff --git a/neqo-transport/src/connection/tests/null.rs b/neqo-transport/src/connection/tests/null.rs index e4d60445c6..162ec5ca05 100644 --- a/neqo-transport/src/connection/tests/null.rs +++ b/neqo-transport/src/connection/tests/null.rs @@ -26,7 +26,7 @@ fn no_encryption() { let client_pkt = client.process_output(now()).dgram().unwrap(); assert!(client_pkt[..client_pkt.len() - AEAD_NULL_TAG.len()].ends_with(DATA_CLIENT)); - server.process_input(&client_pkt, now()); + server.process_input(client_pkt, now()); let mut buf = vec![0; 100]; let (len, _) = server.stream_recv(stream_id, &mut buf).unwrap(); assert_eq!(len, DATA_CLIENT.len()); @@ -35,7 +35,7 @@ fn no_encryption() { let server_pkt = server.process_output(now()).dgram().unwrap(); assert!(server_pkt[..server_pkt.len() - AEAD_NULL_TAG.len()].ends_with(DATA_SERVER)); - client.process_input(&server_pkt, now()); + client.process_input(server_pkt, now()); let (len, _) = client.stream_recv(stream_id, &mut buf).unwrap(); assert_eq!(len, DATA_SERVER.len()); assert_eq!(&buf[..len], DATA_SERVER); diff --git a/neqo-transport/src/connection/tests/priority.rs b/neqo-transport/src/connection/tests/priority.rs index 26ba55260d..3a19a18830 100644 --- a/neqo-transport/src/connection/tests/priority.rs +++ b/neqo-transport/src/connection/tests/priority.rs @@ -41,7 +41,7 @@ fn receive_stream() { assert_eq!(MESSAGE.len(), client.stream_send(id, MESSAGE).unwrap()); let dgram = client.process_output(now()).dgram(); - server.process_input(&dgram.unwrap(), now()); + server.process_input(dgram.unwrap(), now()); assert_eq!( server .stream_priority( @@ -83,7 +83,7 @@ fn relative() { .unwrap(); let dgram = client.process_output(now()).dgram(); - server.process_input(&dgram.unwrap(), now()); + server.process_input(dgram.unwrap(), now()); // The "id_normal" stream will get a `NewStream` event, but no data. for e in server.events() { @@ -114,7 +114,7 @@ fn reprioritize() { .unwrap(); let dgram = client.process_output(now()).dgram(); - server.process_input(&dgram.unwrap(), now()); + server.process_input(dgram.unwrap(), now()); // The "id_normal" stream will get a `NewStream` event, but no data. for e in server.events() { @@ -133,7 +133,7 @@ fn reprioritize() { ) .unwrap(); let dgram = client.process_output(now()).dgram(); - server.process_input(&dgram.unwrap(), now()); + server.process_input(dgram.unwrap(), now()); for e in server.events() { if let ConnectionEvent::RecvStreamReadable { stream_id } = e { @@ -164,7 +164,7 @@ fn repairing_loss() { let _lost = client.process_output(now).dgram(); for _ in 0..5 { match client.process_output(now) { - Output::Datagram(d) => server.process_input(&d, now), + Output::Datagram(d) => server.process_input(d, now), Output::Callback(delay) => now += delay, Output::None => unreachable!(), } @@ -177,9 +177,9 @@ fn repairing_loss() { let id_normal = client.stream_create(StreamType::UniDi).unwrap(); fill_stream(&mut client, id_normal); - let dgram = client.process(ack.as_ref(), now).dgram(); + let dgram = client.process(ack, now).dgram(); assert_eq!(client.stats().lost, 1); // Client should have noticed the loss. - server.process_input(&dgram.unwrap(), now); + server.process_input(dgram.unwrap(), now); // Only the low priority stream has data as the retransmission of the data from // the lost packet is now more important than new data from the high priority stream. @@ -195,7 +195,7 @@ fn repairing_loss() { // the retransmitted data into a second packet, it will also contain data from the // normal priority stream. let dgram = client.process_output(now).dgram(); - server.process_input(&dgram.unwrap(), now); + server.process_input(dgram.unwrap(), now); assert!(server.events().any( |e| matches!(e, ConnectionEvent::RecvStreamReadable { stream_id } if stream_id == id_normal), )); @@ -210,8 +210,8 @@ fn critical() { // Rather than connect, send stream data in 0.5-RTT. // That allows this to test that critical streams pre-empt most frame types. let dgram = client.process_output(now).dgram(); - let dgram = server.process(dgram.as_ref(), now).dgram(); - client.process_input(&dgram.unwrap(), now); + let dgram = server.process(dgram, now).dgram(); + client.process_input(dgram.unwrap(), now); maybe_authenticate(&mut client); let id = server.stream_create(StreamType::UniDi).unwrap(); @@ -238,8 +238,8 @@ fn critical() { assert_eq!(stats_after.handshake_done, 0); // Complete the handshake. - let dgram = client.process(dgram.as_ref(), now).dgram(); - server.process_input(&dgram.unwrap(), now); + let dgram = client.process(dgram, now).dgram(); + server.process_input(dgram.unwrap(), now); // Critical beats everything but HANDSHAKE_DONE. let stats_before = server.stats().frame_tx; @@ -261,8 +261,8 @@ fn important() { // Rather than connect, send stream data in 0.5-RTT. // That allows this to test that important streams pre-empt most frame types. let dgram = client.process_output(now).dgram(); - let dgram = server.process(dgram.as_ref(), now).dgram(); - client.process_input(&dgram.unwrap(), now); + let dgram = server.process(dgram, now).dgram(); + client.process_input(dgram.unwrap(), now); maybe_authenticate(&mut client); let id = server.stream_create(StreamType::UniDi).unwrap(); @@ -290,8 +290,8 @@ fn important() { assert_eq!(stats_after.stream, stats_before.stream + 1); // Complete the handshake. - let dgram = client.process(dgram.as_ref(), now).dgram(); - server.process_input(&dgram.unwrap(), now); + let dgram = client.process(dgram, now).dgram(); + server.process_input(dgram.unwrap(), now); // Important beats everything but flow control. let stats_before = server.stats().frame_tx; @@ -314,8 +314,8 @@ fn high_normal() { // Rather than connect, send stream data in 0.5-RTT. // That allows this to test that important streams pre-empt most frame types. let dgram = client.process_output(now).dgram(); - let dgram = server.process(dgram.as_ref(), now).dgram(); - client.process_input(&dgram.unwrap(), now); + let dgram = server.process(dgram, now).dgram(); + client.process_input(dgram.unwrap(), now); maybe_authenticate(&mut client); let id = server.stream_create(StreamType::UniDi).unwrap(); @@ -343,8 +343,8 @@ fn high_normal() { assert_eq!(stats_after.stream, stats_before.stream + 1); // Complete the handshake. - let dgram = client.process(dgram.as_ref(), now).dgram(); - server.process_input(&dgram.unwrap(), now); + let dgram = client.process(dgram, now).dgram(); + server.process_input(dgram.unwrap(), now); // High or Normal doesn't beat NEW_CONNECTION_ID, // but they beat CRYPTO/NEW_TOKEN. diff --git a/neqo-transport/src/connection/tests/recovery.rs b/neqo-transport/src/connection/tests/recovery.rs index 37845c671f..f3c319bdec 100644 --- a/neqo-transport/src/connection/tests/recovery.rs +++ b/neqo-transport/src/connection/tests/recovery.rs @@ -45,7 +45,7 @@ fn pto_works_basic() { let mut now = now(); - let res = client.process(None, now); + let res = client.process_output(now); let idle_timeout = ConnectionParameters::default().get_idle_timeout(); assert_eq!(res, Output::Callback(idle_timeout)); @@ -59,19 +59,19 @@ fn pto_works_basic() { // Send a packet after some time. now += Duration::from_secs(10); - let out = client.process(None, now); + let out = client.process_output(now); assert!(out.dgram().is_some()); // Nothing to do, should return callback - let out = client.process(None, now); + let out = client.process_output(now); assert!(matches!(out, Output::Callback(_))); // One second later, it should want to send PTO packet now += AT_LEAST_PTO; - let out = client.process(None, now); + let out = client.process_output(now); let stream_before = server.stats().frame_rx.stream; - server.process_input(&out.dgram().unwrap(), now); + server.process_input(out.dgram().unwrap(), now); assert_eq!(server.stats().frame_rx.stream, stream_before + 2); } @@ -96,7 +96,7 @@ fn pto_works_full_cwnd() { // Both datagrams contain one or more STREAM frames. for d in dgrams { let stream_before = server.stats().frame_rx.stream; - server.process_input(&d, now); + server.process_input(d, now); assert!(server.stats().frame_rx.stream > stream_before); } } @@ -115,49 +115,49 @@ fn pto_works_ping() { let pkt3 = send_something(&mut client, now); // Nothing to do, should return callback - let cb = client.process(None, now).callback(); + let cb = client.process_output(now).callback(); // The PTO timer is calculated with: // RTT + max(rttvar * 4, GRANULARITY) + max_ack_delay // With zero RTT and rttvar, max_ack_delay is minimum too (GRANULARITY) assert_eq!(cb, GRANULARITY * 2); // Process these by server, skipping pkt0 - let srv0 = server.process(Some(&pkt1), now).dgram(); + let srv0 = server.process(Some(pkt1), now).dgram(); assert!(srv0.is_some()); // ooo, ack client pkt1 now += Duration::from_millis(20); // process pkt2 (immediate ack because last ack was more than an RTT ago; RTT=0) - let srv1 = server.process(Some(&pkt2), now).dgram(); + let srv1 = server.process(Some(pkt2), now).dgram(); assert!(srv1.is_some()); // this is now dropped now += Duration::from_millis(20); // process pkt3 (acked for same reason) - let srv2 = server.process(Some(&pkt3), now).dgram(); + let srv2 = server.process(Some(pkt3), now).dgram(); // ack client pkt 2 & 3 assert!(srv2.is_some()); // client processes ack - let pkt4 = client.process(srv2.as_ref(), now).dgram(); + let pkt4 = client.process(srv2, now).dgram(); // client resends data from pkt0 assert!(pkt4.is_some()); // server sees ooo pkt0 and generates immediate ack - let srv3 = server.process(Some(&pkt0), now).dgram(); + let srv3 = server.process(Some(pkt0), now).dgram(); assert!(srv3.is_some()); // Accept the acknowledgment. - let pkt5 = client.process(srv3.as_ref(), now).dgram(); + let pkt5 = client.process(srv3, now).dgram(); assert!(pkt5.is_none()); now += Duration::from_millis(70); // PTO expires. No unacked data. Only send PING. let client_pings = client.stats().frame_tx.ping; - let pkt6 = client.process(None, now).dgram(); + let pkt6 = client.process_output(now).dgram(); assert_eq!(client.stats().frame_tx.ping, client_pings + 1); let server_pings = server.stats().frame_rx.ping; - server.process_input(&pkt6.unwrap(), now); + server.process_input(pkt6.unwrap(), now); assert_eq!(server.stats().frame_rx.ping, server_pings + 1); } @@ -168,40 +168,40 @@ fn pto_initial() { qdebug!("---- client: generate CH"); let mut client = default_client(); - let pkt1 = client.process(None, now).dgram(); + let pkt1 = client.process_output(now).dgram(); assert!(pkt1.is_some()); assert_eq!(pkt1.clone().unwrap().len(), client.plpmtu()); - let delay = client.process(None, now).callback(); + let delay = client.process_output(now).callback(); assert_eq!(delay, INITIAL_PTO); // Resend initial after PTO. now += delay; - let pkt2 = client.process(None, now).dgram(); + let pkt2 = client.process_output(now).dgram(); assert!(pkt2.is_some()); assert_eq!(pkt2.unwrap().len(), client.plpmtu()); - let delay = client.process(None, now).callback(); + let delay = client.process_output(now).callback(); // PTO has doubled. assert_eq!(delay, INITIAL_PTO * 2); // Server process the first initial pkt. let mut server = default_server(); - let out = server.process(pkt1.as_ref(), now).dgram(); + let out = server.process(pkt1, now).dgram(); assert!(out.is_some()); // Client receives ack for the first initial packet as well a Handshake packet. // After the handshake packet the initial keys and the crypto stream for the initial // packet number space will be discarded. // Here only an ack for the Handshake packet will be sent. - let out = client.process(out.as_ref(), now).dgram(); + let out = client.process(out, now).dgram(); assert!(out.is_some()); // We do not have PTO for the resent initial packet any more, but // the Handshake PTO timer should be armed. As the RTT is apparently // the same as the initial PTO value, and there is only one sample, // the PTO will be 3x the INITIAL PTO. - let delay = client.process(None, now).callback(); + let delay = client.process_output(now).callback(); assert_eq!(delay, INITIAL_PTO * 3); } @@ -215,37 +215,37 @@ fn pto_handshake_complete() { let mut client = default_client(); let mut server = default_server(); - let pkt = client.process(None, now).dgram(); + let pkt = client.process_output(now).dgram(); assert_initial(pkt.as_ref().unwrap(), false); - let cb = client.process(None, now).callback(); + let cb = client.process_output(now).callback(); assert_eq!(cb, Duration::from_millis(300)); now += HALF_RTT; - let pkt = server.process(pkt.as_ref(), now).dgram(); + let pkt = server.process(pkt, now).dgram(); assert_initial(pkt.as_ref().unwrap(), false); now += HALF_RTT; - let pkt = client.process(pkt.as_ref(), now).dgram(); + let pkt = client.process(pkt, now).dgram(); assert_handshake(pkt.as_ref().unwrap()); - let cb = client.process(None, now).callback(); + let cb = client.process_output(now).callback(); // The client now has a single RTT estimate (20ms), so // the handshake PTO is set based on that. assert_eq!(cb, HALF_RTT * 6); now += HALF_RTT; - let pkt = server.process(pkt.as_ref(), now).dgram(); + let pkt = server.process(pkt, now).dgram(); assert!(pkt.is_none()); now += HALF_RTT; client.authenticated(AuthenticationStatus::Ok, now); qdebug!("---- client: SH..FIN -> FIN"); - let pkt1 = client.process(None, now).dgram(); + let pkt1 = client.process_output(now).dgram(); assert_handshake(pkt1.as_ref().unwrap()); assert_eq!(*client.state(), State::Connected); - let cb = client.process(None, now).callback(); + let cb = client.process_output(now).callback(); assert_eq!(cb, HALF_RTT * 6); let mut pto_counts = [0; MAX_PTO_COUNTS]; @@ -255,7 +255,7 @@ fn pto_handshake_complete() { // Wait long enough that the 1-RTT PTO also fires. qdebug!("---- client: PTO"); now += HALF_RTT * 6; - let pkt2 = client.process(None, now).dgram(); + let pkt2 = client.process_output(now).dgram(); assert_handshake(pkt2.as_ref().unwrap()); pto_counts[0] = 1; @@ -267,14 +267,14 @@ fn pto_handshake_complete() { let stream_id = client.stream_create(StreamType::UniDi).unwrap(); client.stream_close_send(stream_id).unwrap(); now += HALF_RTT * 6; - let pkt3 = client.process(None, now).dgram(); + let pkt3 = client.process_output(now).dgram(); assert_handshake(pkt3.as_ref().unwrap()); let (pkt3_hs, pkt3_1rtt) = split_datagram(&pkt3.unwrap()); assert_handshake(&pkt3_hs); assert!(pkt3_1rtt.is_some()); // PTO has been doubled. - let cb = client.process(None, now).callback(); + let cb = client.process_output(now).callback(); assert_eq!(cb, HALF_RTT * 12); // We still have only a single PTO @@ -288,8 +288,8 @@ fn pto_handshake_complete() { // This should remove the 1-RTT PTO from messing this test up. let server_acks = server.stats().frame_tx.ack; let server_done = server.stats().frame_tx.handshake_done; - server.process_input(&pkt3_1rtt.unwrap(), now); - let ack = server.process(pkt1.as_ref(), now).dgram(); + server.process_input(pkt3_1rtt.unwrap(), now); + let ack = server.process(pkt1, now).dgram(); assert!(ack.is_some()); assert_eq!(server.stats().frame_tx.ack, server_acks + 2); assert_eq!(server.stats().frame_tx.handshake_done, server_done + 1); @@ -302,14 +302,14 @@ fn pto_handshake_complete() { assert!(pkt2_1rtt.is_some()); let dropped_before1 = server.stats().dropped_rx; let server_frames = server.stats().frame_rx.all(); - server.process_input(&pkt2_hs, now); + server.process_input(pkt2_hs, now); assert_eq!(1, server.stats().dropped_rx - dropped_before1); assert_eq!(server.stats().frame_rx.all(), server_frames); - server.process_input(&pkt2_1rtt.unwrap(), now); + server.process_input(pkt2_1rtt.unwrap(), now); let server_frames2 = server.stats().frame_rx.all(); let dropped_before2 = server.stats().dropped_rx; - server.process_input(&pkt3_hs, now); + server.process_input(pkt3_hs, now); assert_eq!(1, server.stats().dropped_rx - dropped_before2); assert_eq!(server.stats().frame_rx.all(), server_frames2); @@ -317,14 +317,14 @@ fn pto_handshake_complete() { // Let the client receive the ACK. // It should now be wait to acknowledge the HANDSHAKE_DONE. - let cb = client.process(ack.as_ref(), now).callback(); + let cb = client.process(ack, now).callback(); // The default ack delay is the RTT divided by the default ACK ratio of 4. let expected_ack_delay = HALF_RTT * 2 / 4; assert_eq!(cb, expected_ack_delay); // Let the ACK delay timer expire. now += cb; - let out = client.process(None, now).dgram(); + let out = client.process_output(now).dgram(); assert!(out.is_some()); } @@ -334,19 +334,19 @@ fn pto_handshake_frames() { let mut now = now(); qdebug!("---- client: generate CH"); let mut client = default_client(); - let pkt = client.process(None, now); + let pkt = client.process_output(now); now += Duration::from_millis(10); qdebug!("---- server: CH -> SH, EE, CERT, CV, FIN"); let mut server = default_server(); - let pkt = server.process(pkt.as_dgram_ref(), now); + let pkt = server.process(pkt.dgram(), now); now += Duration::from_millis(10); qdebug!("---- client: cert verification"); - let pkt = client.process(pkt.as_dgram_ref(), now); + let pkt = client.process(pkt.dgram(), now); now += Duration::from_millis(10); - mem::drop(server.process(pkt.as_dgram_ref(), now)); + mem::drop(server.process(pkt.dgram(), now)); now += Duration::from_millis(10); client.authenticated(AuthenticationStatus::Ok, now); @@ -355,21 +355,21 @@ fn pto_handshake_frames() { assert_eq!(stream, 2); assert_eq!(client.stream_send(stream, b"zero").unwrap(), 4); qdebug!("---- client: SH..FIN -> FIN and 1RTT packet"); - let pkt1 = client.process(None, now).dgram(); + let pkt1 = client.process_output(now).dgram(); assert!(pkt1.is_some()); // Get PTO timer. - let out = client.process(None, now); + let out = client.process_output(now); assert_eq!(out, Output::Callback(Duration::from_millis(60))); // Wait for PTO to expire and resend a handshake packet. now += Duration::from_millis(60); - let pkt2 = client.process(None, now).dgram(); + let pkt2 = client.process_output(now).dgram(); assert!(pkt2.is_some()); now += Duration::from_millis(10); let crypto_before = server.stats().frame_rx.crypto; - server.process_input(&pkt2.unwrap(), now); + server.process_input(pkt2.unwrap(), now); assert_eq!(server.stats().frame_rx.crypto, crypto_before + 1); } @@ -388,21 +388,21 @@ fn handshake_ack_pto() { let big = TransportParameter::Bytes(vec![0; Pmtud::default_plpmtu(DEFAULT_ADDR.ip())]); server.set_local_tparam(0xce16, big).unwrap(); - let c1 = client.process(None, now).dgram(); + let c1 = client.process_output(now).dgram(); now += RTT / 2; - let s1 = server.process(c1.as_ref(), now).dgram(); + let s1 = server.process(c1, now).dgram(); assert!(s1.is_some()); - let s2 = server.process(None, now).dgram(); + let s2 = server.process_output(now).dgram(); assert!(s1.is_some()); // Now let the client have the Initial, but drop the first coalesced Handshake packet. now += RTT / 2; let (initial, _) = split_datagram(&s1.unwrap()); - client.process_input(&initial, now); - let c2 = client.process(s2.as_ref(), now).dgram(); + client.process_input(initial, now); + let c2 = client.process(s2, now).dgram(); assert!(c2.is_some()); // This is an ACK. Drop it. - let delay = client.process(None, now).callback(); + let delay = client.process_output(now).callback(); assert_eq!(delay, RTT * 3); let mut pto_counts = [0; MAX_PTO_COUNTS]; @@ -410,26 +410,26 @@ fn handshake_ack_pto() { // Wait for the PTO and ensure that the client generates a packet. now += delay; - let c3 = client.process(None, now).dgram(); + let c3 = client.process_output(now).dgram(); assert!(c3.is_some()); now += RTT / 2; let ping_before = server.stats().frame_rx.ping; - server.process_input(&c3.unwrap(), now); + server.process_input(c3.unwrap(), now); assert_eq!(server.stats().frame_rx.ping, ping_before + 1); pto_counts[0] = 1; assert_eq!(client.stats.borrow().pto_counts, pto_counts); // Now complete the handshake as cheaply as possible. - let dgram = server.process(None, now).dgram(); - client.process_input(&dgram.unwrap(), now); + let dgram = server.process_output(now).dgram(); + client.process_input(dgram.unwrap(), now); maybe_authenticate(&mut client); - let dgram = client.process(None, now).dgram(); + let dgram = client.process_output(now).dgram(); assert_eq!(*client.state(), State::Connected); - let dgram = server.process(dgram.as_ref(), now).dgram(); + let dgram = server.process(dgram, now).dgram(); assert_eq!(*server.state(), State::Confirmed); - client.process_input(&dgram.unwrap(), now); + client.process_input(dgram.unwrap(), now); assert_eq!(*client.state(), State::Confirmed); assert_eq!(client.stats.borrow().pto_counts, pto_counts); @@ -450,12 +450,12 @@ fn loss_recovery_crash() { assert!(ack.is_some()); // Have the server process the ACK. - let cb = server.process(ack.as_ref(), now).callback(); + let cb = server.process(ack, now).callback(); assert!(cb > Duration::from_secs(0)); // Now we leap into the future. The server should regard the first // packet as lost based on time alone. - let dgram = server.process(None, now + AT_LEAST_PTO).dgram(); + let dgram = server.process_output(now + AT_LEAST_PTO).dgram(); assert!(dgram.is_some()); // This crashes. @@ -480,10 +480,10 @@ fn ack_after_pto() { now += AT_LEAST_PTO; // We can use MAX_PTO_PACKET_COUNT, because we know the handshake is over. for _ in 0..MAX_PTO_PACKET_COUNT { - let dgram = client.process(None, now).dgram(); + let dgram = client.process_output(now).dgram(); assert!(dgram.is_some()); } - assert!(client.process(None, now).dgram().is_none()); + assert!(client.process_output(now).dgram().is_none()); // The server now needs to send something that will cause the // client to want to acknowledge it. A little out of order @@ -495,13 +495,13 @@ fn ack_after_pto() { // The client is now after a PTO, but if it receives something // that demands acknowledgment, it will send just the ACK. - let ack = client.process(Some(&dgram), now).dgram(); + let ack = client.process(Some(dgram), now).dgram(); assert!(ack.is_some()); // Make sure that the packet only contained an ACK frame. let all_frames_before = server.stats().frame_rx.all(); let ack_before = server.stats().frame_rx.ack; - server.process_input(&ack.unwrap(), now); + server.process_input(ack.unwrap(), now); assert_eq!(server.stats().frame_rx.all(), all_frames_before + 1); assert_eq!(server.stats().frame_rx.ack, ack_before + 1); } @@ -522,7 +522,7 @@ fn lost_but_kept_and_lr_timer() { // At t=RTT/2 the server receives the packet and ACKs it. now += RTT / 2; - let ack = server.process(Some(&p2), now).dgram(); + let ack = server.process(Some(p2), now).dgram(); assert!(ack.is_some()); // The client also sends another two packets (p3, p4), again losing the first. let _p3 = send_something(&mut client, now); @@ -531,24 +531,24 @@ fn lost_but_kept_and_lr_timer() { // At t=RTT the client receives the ACK and goes into timed loss recovery. // The client doesn't call p1 lost at this stage, but it will soon. now += RTT / 2; - let res = client.process(ack.as_ref(), now); + let res = client.process(ack, now); // The client should be on a loss recovery timer as p1 is missing. let lr_timer = res.callback(); // Loss recovery timer should be RTT/8, but only check for 0 or >=RTT/2. assert_ne!(lr_timer, Duration::from_secs(0)); assert!(lr_timer < (RTT / 2)); // The server also receives and acknowledges p4, again sending an ACK. - let ack = server.process(Some(&p4), now).dgram(); + let ack = server.process(Some(p4), now).dgram(); assert!(ack.is_some()); // At t=RTT*3/2 the client should declare p1 to be lost. now += RTT / 2; // So the client will send the data from p1 again. - let res = client.process(None, now); + let res = client.process_output(now); assert!(res.dgram().is_some()); // When the client processes the ACK, it should engage the // loss recovery timer for p3, not p1 (even though it still tracks p1). - let res = client.process(ack.as_ref(), now); + let res = client.process(ack, now); let lr_timer2 = res.callback(); assert_eq!(lr_timer, lr_timer2); } @@ -569,9 +569,9 @@ fn loss_time_past_largest_acked() { let mut now = now(); // Start the handshake. - let c_in = client.process(None, now).dgram(); + let c_in = client.process_output(now).dgram(); now += RTT / 2; - let s_hs1 = server.process(c_in.as_ref(), now).dgram(); + let s_hs1 = server.process(c_in, now).dgram(); // Get some spare server handshake packets for the client to ACK. // This involves a time machine, so be a little cautious. @@ -579,15 +579,15 @@ fn loss_time_past_largest_acked() { // with a much lower RTT estimate, so the PTO at this point should // be much smaller than an RTT and so the server shouldn't see // time go backwards. - let s_pto = server.process(None, now).callback(); + let s_pto = server.process_output(now).callback(); assert_ne!(s_pto, Duration::from_secs(0)); assert!(s_pto < RTT); - let s_hs2 = server.process(None, now + s_pto).dgram(); + let s_hs2 = server.process_output(now + s_pto).dgram(); assert!(s_hs2.is_some()); - let s_pto = server.process(None, now).callback(); + let s_pto = server.process_output(now).callback(); assert_ne!(s_pto, Duration::from_secs(0)); assert!(s_pto < RTT); - let s_hs3 = server.process(None, now + s_pto).dgram(); + let s_hs3 = server.process_output(now + s_pto).dgram(); assert!(s_hs3.is_some()); // We are blocked by the amplification limit now. @@ -601,26 +601,26 @@ fn loss_time_past_largest_acked() { // to generate an ack-eliciting packet. For that, we use the Finished message. // Reordering delivery ensures that the later packet is also acknowledged. now += RTT / 2; - let c_hs1 = client.process(s_hs1.as_ref(), now).dgram(); + let c_hs1 = client.process(s_hs1, now).dgram(); assert!(c_hs1.is_some()); // This comes first, so it's useless. maybe_authenticate(&mut client); - let c_hs2 = client.process(None, now).dgram(); + let c_hs2 = client.process_output(now).dgram(); assert!(c_hs2.is_some()); // This one will elicit an ACK. // The we need the outstanding packet to be sent after the // application data packet, so space these out a tiny bit. let _p1 = send_something(&mut client, now + INCR); - let c_hs3 = client.process(s_hs2.as_ref(), now + (INCR * 2)).dgram(); + let c_hs3 = client.process(s_hs2, now + (INCR * 2)).dgram(); assert!(c_hs3.is_some()); // This will be left outstanding. - let c_hs4 = client.process(s_hs3.as_ref(), now + (INCR * 3)).dgram(); + let c_hs4 = client.process(s_hs3, now + (INCR * 3)).dgram(); assert!(c_hs4.is_some()); // This will be acknowledged. // Process c_hs2 and c_hs4, but skip c_hs3. // Then get an ACK for the client. now += RTT / 2; // Deliver c_hs4 first, but don't generate a packet. - server.process_input(&c_hs4.unwrap(), now); - let s_ack = server.process(c_hs2.as_ref(), now).dgram(); + server.process_input(c_hs4.unwrap(), now); + let s_ack = server.process(c_hs2, now).dgram(); assert!(s_ack.is_some()); // This includes an ACK, but it also includes HANDSHAKE_DONE, // which we need to remove because that will cause the Handshake loss @@ -629,12 +629,12 @@ fn loss_time_past_largest_acked() { // Now the client should start its loss recovery timer based on the ACK. now += RTT / 2; - let _c_ack = client.process(Some(&s_hs_ack), now).dgram(); + let _c_ack = client.process(Some(s_hs_ack), now).dgram(); // This ACK triggers an immediate ACK, due to an ACK loss during handshake. - let c_ack = client.process(None, now).dgram(); + let c_ack = client.process_output(now).dgram(); assert!(c_ack.is_none()); // The client should now have the loss recovery timer active. - let lr_time = client.process(None, now).callback(); + let lr_time = client.process_output(now).callback(); assert_ne!(lr_time, Duration::from_secs(0)); assert!(lr_time < (RTT / 2)); } @@ -648,12 +648,12 @@ fn trickle(sender: &mut Connection, receiver: &mut Connection, mut count: usize, while count > 0 { qdebug!("trickle: remaining={}", count); assert_eq!(sender.stream_send(id, &[9]).unwrap(), 1); - let dgram = sender.process(maybe_ack.as_ref(), now).dgram(); + let dgram = sender.process(maybe_ack, now).dgram(); - maybe_ack = receiver.process(dgram.as_ref(), now).dgram(); + maybe_ack = receiver.process(dgram, now).dgram(); count -= usize::from(maybe_ack.is_some()); } - sender.process_input(&maybe_ack.unwrap(), now); + sender.process_input(maybe_ack.unwrap(), now); } /// Ensure that a PING frame is sent with ACK sometimes. @@ -744,7 +744,7 @@ fn fast_pto() { let mut server = default_server(); let mut now = connect_rtt_idle(&mut client, &mut server, DEFAULT_RTT); - let res = client.process(None, now); + let res = client.process_output(now); let idle_timeout = ConnectionParameters::default().get_idle_timeout() - (DEFAULT_RTT / 2); assert_eq!(res, Output::Callback(idle_timeout)); @@ -766,10 +766,10 @@ fn fast_pto() { // Once the PTO timer expires, a PTO packet should be sent should want to send PTO packet. now += cb; - let dgram = client.process(None, now).dgram(); + let dgram = client.process_output(now).dgram(); let stream_before = server.stats().frame_rx.stream; - server.process_input(&dgram.unwrap(), now); + server.process_input(dgram.unwrap(), now); assert_eq!(server.stats().frame_rx.stream, stream_before + 1); } @@ -781,7 +781,7 @@ fn fast_pto_persistent_congestion() { let mut server = default_server(); let mut now = connect_rtt_idle(&mut client, &mut server, DEFAULT_RTT); - let res = client.process(None, now); + let res = client.process_output(now); let idle_timeout = ConnectionParameters::default().get_idle_timeout() - (DEFAULT_RTT / 2); assert_eq!(res, Output::Callback(idle_timeout)); @@ -809,9 +809,9 @@ fn fast_pto_persistent_congestion() { // Now acknowledge the tail packet and enter persistent congestion. now += DEFAULT_RTT / 2; - let ack = server.process(Some(&dgram), now).dgram(); + let ack = server.process(Some(dgram), now).dgram(); now += DEFAULT_RTT / 2; - client.process_input(&ack.unwrap(), now); + client.process_input(ack.unwrap(), now); assert_eq!(cwnd(&client), cwnd_min(&client)); } @@ -841,7 +841,7 @@ fn ack_for_unsent() { .unwrap(); // Now deliver the packet with the spoofed ACK frame - client.process_input(&spoofed, now()); + client.process_input(spoofed, now()); assert!(matches!( client.state(), State::Closing { diff --git a/neqo-transport/src/connection/tests/resumption.rs b/neqo-transport/src/connection/tests/resumption.rs index 01e977e506..50b469b7f8 100644 --- a/neqo-transport/src/connection/tests/resumption.rs +++ b/neqo-transport/src/connection/tests/resumption.rs @@ -66,7 +66,7 @@ fn remember_smoothed_rtt() { let ticket = server.process_output(now).dgram(); assert!(ticket.is_some()); now += RTT1 / 2; - client.process_input(&ticket.unwrap(), now); + client.process_input(ticket.unwrap(), now); let token = get_tokens(&mut client).pop().unwrap(); let mut client = default_client(); @@ -102,7 +102,7 @@ fn ticket_rtt(rtt: Duration) -> Duration { let client_dcid = client_dcid.to_owned(); now += rtt / 2; - let server_packet = server.process(client_initial.as_dgram_ref(), now).dgram(); + let server_packet = server.process(client_initial.dgram(), now).dgram(); let (server_initial, server_hs) = split_datagram(server_packet.as_ref().unwrap()); let (protected_header, _, _, payload) = decode_initial_header(&server_initial, Role::Server).unwrap(); @@ -143,15 +143,15 @@ fn ticket_rtt(rtt: Duration) -> Duration { // Now a connection can be made successfully. now += rtt / 2; - client.process_input(&si, now); - client.process_input(&server_hs.unwrap(), now); + client.process_input(si, now); + client.process_input(server_hs.unwrap(), now); client.authenticated(AuthenticationStatus::Ok, now); let finished = client.process_output(now); assert_eq!(*client.state(), State::Connected); now += rtt / 2; - _ = server.process(finished.as_dgram_ref(), now); + _ = server.process(finished.dgram(), now); assert_eq!(*server.state(), State::Confirmed); // Don't deliver the server's handshake finished, it has ACKs. @@ -164,7 +164,7 @@ fn ticket_rtt(rtt: Duration) -> Duration { let ticket = server.process_output(now).dgram(); assert!(ticket.is_some()); now += rtt / 2; - client.process_input(&ticket.unwrap(), now); + client.process_input(ticket.unwrap(), now); let token = get_tokens(&mut client).pop().unwrap(); // And connect again. @@ -213,7 +213,7 @@ fn address_validation_token_resume() { let mut server = resumed_server(&client); // Grab an Initial packet from the client. - let dgram = client.process(None, now).dgram(); + let dgram = client.process_output(now).dgram(); assertions::assert_initial(dgram.as_ref().unwrap(), true); // Now try to complete the handshake after giving time for a client PTO. @@ -242,26 +242,26 @@ fn two_tickets_on_timer() { let pkt = send_something(&mut server, now()); // process() will return an ack first - assert!(client.process(Some(&pkt), now()).dgram().is_some()); + assert!(client.process(Some(pkt), now()).dgram().is_some()); // We do not have a ResumptionToken event yet, because NEW_TOKEN was not sent. assert_eq!(get_tokens(&mut client).len(), 0); // We need to wait for release_resumption_token_timer to expire. The timer will be // set to 3 * PTO let mut now = now() + 3 * client.pto(); - mem::drop(client.process(None, now)); + mem::drop(client.process_output(now)); let mut recv_tokens = get_tokens(&mut client); assert_eq!(recv_tokens.len(), 1); let token1 = recv_tokens.pop().unwrap(); // Wai for anottheer 3 * PTO to get the nex okeen. now += 3 * client.pto(); - mem::drop(client.process(None, now)); + mem::drop(client.process_output(now)); let mut recv_tokens = get_tokens(&mut client); assert_eq!(recv_tokens.len(), 1); let token2 = recv_tokens.pop().unwrap(); // Wait for 3 * PTO, but now there are no more tokens. now += 3 * client.pto(); - mem::drop(client.process(None, now)); + mem::drop(client.process_output(now)); assert_eq!(get_tokens(&mut client).len(), 0); assert_ne!(token1.as_ref(), token2.as_ref()); @@ -283,7 +283,7 @@ fn two_tickets_with_new_token() { server.send_ticket(now(), &[]).expect("send ticket2"); let pkt = send_something(&mut server, now()); - client.process_input(&pkt, now()); + client.process_input(pkt, now()); let mut all_tokens = get_tokens(&mut client); assert_eq!(all_tokens.len(), 2); let token1 = all_tokens.pop().unwrap(); @@ -303,8 +303,8 @@ fn take_token() { connect(&mut client, &mut server); server.send_ticket(now(), &[]).unwrap(); - let dgram = server.process(None, now()).dgram(); - client.process_input(&dgram.unwrap(), now()); + let dgram = server.process_output(now()).dgram(); + client.process_input(dgram.unwrap(), now()); // There should be no ResumptionToken event here. let tokens = get_tokens(&mut client); diff --git a/neqo-transport/src/connection/tests/stream.rs b/neqo-transport/src/connection/tests/stream.rs index f7472d917f..aa2b1003c9 100644 --- a/neqo-transport/src/connection/tests/stream.rs +++ b/neqo-transport/src/connection/tests/stream.rs @@ -32,14 +32,14 @@ use crate::{ fn stream_create() { let mut client = default_client(); - let out = client.process(None, now()); + let out = client.process_output(now()); let mut server = default_server(); - let out = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); - let out = client.process(out.as_dgram_ref(), now()); - mem::drop(server.process(out.as_dgram_ref(), now())); + let out = client.process(out.dgram(), now()); + mem::drop(server.process(out.dgram(), now())); assert!(maybe_authenticate(&mut client)); - let out = client.process(None, now()); + let out = client.process_output(now()); // client now in State::Connected assert_eq!(client.stream_create(StreamType::UniDi).unwrap(), 2); @@ -47,7 +47,7 @@ fn stream_create() { assert_eq!(client.stream_create(StreamType::BiDi).unwrap(), 0); assert_eq!(client.stream_create(StreamType::BiDi).unwrap(), 4); - mem::drop(server.process(out.as_dgram_ref(), now())); + mem::drop(server.process(out.dgram(), now())); // server now in State::Connected assert_eq!(server.stream_create(StreamType::UniDi).unwrap(), 3); assert_eq!(server.stream_create(StreamType::UniDi).unwrap(), 7); @@ -86,7 +86,7 @@ fn transfer() { qdebug!("---- server receives"); for d in datagrams { - let out = server.process(Some(&d), now()); + let out = server.process(Some(d), now()); // With an RTT of zero, the server will acknowledge every packet immediately. assert!(out.as_dgram_ref().is_some()); qdebug!("Output={:0x?}", out.as_dgram_ref()); @@ -151,7 +151,7 @@ fn sendorder_test(order_of_sendorder: &[Option]) { qdebug!("---- server receives"); for d in datagrams { - let out = server.process(Some(&d), now()); + let out = server.process(Some(d), now()); qdebug!("Output={:0x?}", out.as_dgram_ref()); } assert_eq!(*server.state(), State::Confirmed); @@ -317,12 +317,12 @@ fn report_fin_when_stream_closed_wo_data() { // create a stream let stream_id = client.stream_create(StreamType::BiDi).unwrap(); client.stream_send(stream_id, &[0x00]).unwrap(); - let out = client.process(None, now()); - mem::drop(server.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.process(out.dgram(), now())); server.stream_close_send(stream_id).unwrap(); - let out = server.process(None, now()); - mem::drop(client.process(out.as_dgram_ref(), now())); + let out = server.process_output(now()); + mem::drop(client.process(out.dgram(), now())); let stream_readable = |e| matches!(e, ConnectionEvent::RecvStreamReadable { .. }); assert!(client.events().any(stream_readable)); } @@ -330,9 +330,9 @@ fn report_fin_when_stream_closed_wo_data() { fn exchange_data(client: &mut Connection, server: &mut Connection) { let mut input = None; loop { - let out = client.process(input.as_ref(), now()).dgram(); + let out = client.process(input, now()).dgram(); let c_done = out.is_none(); - let out = server.process(out.as_ref(), now()).dgram(); + let out = server.process(out, now()).dgram(); if out.is_none() && c_done { break; } @@ -373,8 +373,8 @@ fn sending_max_data() { assert_eq!(received, SMALL_MAX_DATA); assert!(!fin); - let out = server.process(None, now()).dgram(); - client.process_input(&out.unwrap(), now()); + let out = server.process_output(now()).dgram(); + client.process_input(out.unwrap(), now()); assert_eq!( client @@ -511,8 +511,8 @@ fn do_not_accept_data_after_stop_sending() { // create a stream let stream_id = client.stream_create(StreamType::BiDi).unwrap(); client.stream_send(stream_id, &[0x00]).unwrap(); - let out = client.process(None, now()); - mem::drop(server.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.process(out.dgram(), now())); let stream_readable = |e| matches!(e, ConnectionEvent::RecvStreamReadable { .. }); assert!(server.events().any(stream_readable)); @@ -520,7 +520,7 @@ fn do_not_accept_data_after_stop_sending() { // Send one more packet from client. The packet should arrive after the server // has already requested stop_sending. client.stream_send(stream_id, &[0x00]).unwrap(); - let out_second_data_frame = client.process(None, now()); + let out_second_data_frame = client.process_output(now()); // Call stop sending. assert_eq!( Ok(()), @@ -529,10 +529,10 @@ fn do_not_accept_data_after_stop_sending() { // Receive the second data frame. The frame should be ignored and // DataReadable events shouldn't be posted. - let out = server.process(out_second_data_frame.as_dgram_ref(), now()); + let out = server.process(out_second_data_frame.dgram(), now()); assert!(!server.events().any(stream_readable)); - mem::drop(client.process(out.as_dgram_ref(), now())); + mem::drop(client.process(out.dgram(), now())); assert_eq!( Err(Error::FinalSizeError), client.stream_send(stream_id, &[0x00]) @@ -549,8 +549,8 @@ fn simultaneous_stop_sending_and_reset() { // create a stream let stream_id = client.stream_create(StreamType::BiDi).unwrap(); client.stream_send(stream_id, &[0x00]).unwrap(); - let out = client.process(None, now()); - let ack = server.process(out.as_dgram_ref(), now()).dgram(); + let out = client.process_output(now()); + let ack = server.process(out.dgram(), now()).dgram(); let stream_readable = |e| matches!(e, ConnectionEvent::RecvStreamReadable { stream_id: id } if id == stream_id); @@ -559,23 +559,23 @@ fn simultaneous_stop_sending_and_reset() { // The client resets the stream. The packet with reset should arrive after the server // has already requested stop_sending. client.stream_reset_send(stream_id, 0).unwrap(); - let out_reset_frame = client.process(ack.as_ref(), now()).dgram(); + let out_reset_frame = client.process(ack, now()).dgram(); // Send something out of order to force the server to generate an // acknowledgment at the next opportunity. let force_ack = send_something(&mut client, now()); - server.process_input(&force_ack, now()); + server.process_input(force_ack, now()); // Call stop sending. server.stream_stop_sending(stream_id, 0).unwrap(); // Receive the second data frame. The frame should be ignored and // DataReadable events shouldn't be posted. - let ack = server.process(out_reset_frame.as_ref(), now()).dgram(); + let ack = server.process(out_reset_frame, now()).dgram(); assert!(ack.is_some()); assert!(!server.events().any(stream_readable)); // The client gets the STOP_SENDING frame. - client.process_input(&ack.unwrap(), now()); + client.process_input(ack.unwrap(), now()); assert_eq!( Err(Error::InvalidStreamId), client.stream_send(stream_id, &[0x00]) @@ -588,35 +588,35 @@ fn client_fin_reorder() { let mut server = default_server(); // Send ClientHello. - let client_hs = client.process(None, now()); + let client_hs = client.process_output(now()); assert!(client_hs.as_dgram_ref().is_some()); - let server_hs = server.process(client_hs.as_dgram_ref(), now()); + let server_hs = server.process(client_hs.dgram(), now()); assert!(server_hs.as_dgram_ref().is_some()); // ServerHello, etc... - let client_ack = client.process(server_hs.as_dgram_ref(), now()); + let client_ack = client.process(server_hs.dgram(), now()); assert!(client_ack.as_dgram_ref().is_some()); - let server_out = server.process(client_ack.as_dgram_ref(), now()); + let server_out = server.process(client_ack.dgram(), now()); assert!(server_out.as_dgram_ref().is_none()); assert!(maybe_authenticate(&mut client)); assert_eq!(*client.state(), State::Connected); - let client_fin = client.process(None, now()); + let client_fin = client.process_output(now()); assert!(client_fin.as_dgram_ref().is_some()); let client_stream_id = client.stream_create(StreamType::UniDi).unwrap(); client.stream_send(client_stream_id, &[1, 2, 3]).unwrap(); - let client_stream_data = client.process(None, now()); + let client_stream_data = client.process_output(now()); assert!(client_stream_data.as_dgram_ref().is_some()); // Now stream data gets before client_fin - let server_out = server.process(client_stream_data.as_dgram_ref(), now()); + let server_out = server.process(client_stream_data.dgram(), now()); assert!(server_out.as_dgram_ref().is_none()); // the packet will be discarded assert_eq!(*server.state(), State::Handshaking); - let server_out = server.process(client_fin.as_dgram_ref(), now()); + let server_out = server.process(client_fin.dgram(), now()); assert!(server_out.as_dgram_ref().is_some()); } @@ -629,10 +629,10 @@ fn after_fin_is_read_conn_events_for_stream_should_be_removed() { let id = server.stream_create(StreamType::BiDi).unwrap(); server.stream_send(id, &[6; 10]).unwrap(); server.stream_close_send(id).unwrap(); - let out = server.process(None, now()).dgram(); + let out = server.process_output(now()).dgram(); assert!(out.is_some()); - mem::drop(client.process(out.as_ref(), now())); + mem::drop(client.process(out, now())); // read from the stream before checking connection events. let mut buf = vec![0; 4000]; @@ -654,10 +654,10 @@ fn after_stream_stop_sending_is_called_conn_events_for_stream_should_be_removed( let id = server.stream_create(StreamType::BiDi).unwrap(); server.stream_send(id, &[6; 10]).unwrap(); server.stream_close_send(id).unwrap(); - let out = server.process(None, now()).dgram(); + let out = server.process_output(now()).dgram(); assert!(out.is_some()); - mem::drop(client.process(out.as_ref(), now())); + mem::drop(client.process(out, now())); // send stop seending. client @@ -682,11 +682,11 @@ fn stream_data_blocked_generates_max_stream_data() { // Send some data and consume some flow control. let stream_id = server.stream_create(StreamType::UniDi).unwrap(); _ = server.stream_send(stream_id, DEFAULT_STREAM_DATA).unwrap(); - let dgram = server.process(None, now).dgram(); + let dgram = server.process_output(now).dgram(); assert!(dgram.is_some()); // Consume the data. - client.process_input(&dgram.unwrap(), now); + client.process_input(dgram.unwrap(), now); let mut buf = [0; 10]; let (count, end) = client.stream_recv(stream_id, &mut buf[..]).unwrap(); assert_eq!(count, DEFAULT_STREAM_DATA.len()); @@ -703,14 +703,14 @@ fn stream_data_blocked_generates_max_stream_data() { assert!(dgram.is_some()); let sdb_before = client.stats().frame_rx.stream_data_blocked; - let dgram = client.process(dgram.as_ref(), now).dgram(); + let dgram = client.process(dgram, now).dgram(); assert_eq!(client.stats().frame_rx.stream_data_blocked, sdb_before + 1); assert!(dgram.is_some()); // Client should have sent a MAX_STREAM_DATA frame with just a small increase // on the default window size. let msd_before = server.stats().frame_rx.max_stream_data; - server.process_input(&dgram.unwrap(), now); + server.process_input(dgram.unwrap(), now); assert_eq!(server.stats().frame_rx.max_stream_data, msd_before + 1); // Test that the entirety of the receive buffer is available now. @@ -742,22 +742,22 @@ fn max_streams_after_bidi_closed() { // Write on the one stream and send that out. _ = client.stream_send(stream_id, REQUEST).unwrap(); client.stream_close_send(stream_id).unwrap(); - let dgram = client.process(None, now()).dgram(); + let dgram = client.process_output(now()).dgram(); // Now handle the stream and send an incomplete response. - server.process_input(&dgram.unwrap(), now()); + server.process_input(dgram.unwrap(), now()); server.stream_send(stream_id, RESPONSE).unwrap(); let dgram = server.process_output(now()).dgram(); // The server shouldn't have released more stream credit. - client.process_input(&dgram.unwrap(), now()); + client.process_input(dgram.unwrap(), now()); let e = client.stream_create(StreamType::BiDi).unwrap_err(); assert!(matches!(e, Error::StreamLimitError)); // Closing the stream isn't enough. server.stream_close_send(stream_id).unwrap(); let dgram = server.process_output(now()).dgram(); - client.process_input(&dgram.unwrap(), now()); + client.process_input(dgram.unwrap(), now()); assert!(client.stream_create(StreamType::BiDi).is_err()); // The server needs to see an acknowledgment from the client for its @@ -771,12 +771,12 @@ fn max_streams_after_bidi_closed() { // We need an ACK from the client now, but that isn't guaranteed, // so give the client one more packet just in case. let dgram = send_something(&mut server, now()); - client.process_input(&dgram, now()); + client.process_input(dgram, now()); // Now get the client to send the ACK and have the server handle that. let dgram = send_something(&mut client, now()); - let dgram = server.process(Some(&dgram), now()).dgram(); - client.process_input(&dgram.unwrap(), now()); + let dgram = server.process(Some(dgram), now()).dgram(); + client.process_input(dgram.unwrap(), now()); assert!(client.stream_create(StreamType::BiDi).is_ok()); assert!(client.stream_create(StreamType::BiDi).is_err()); } @@ -790,8 +790,8 @@ fn no_dupdata_readable_events() { // create a stream let stream_id = client.stream_create(StreamType::BiDi).unwrap(); client.stream_send(stream_id, &[0x00]).unwrap(); - let out = client.process(None, now()); - mem::drop(server.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.process(out.dgram(), now())); // We have a data_readable event. let stream_readable = |e| matches!(e, ConnectionEvent::RecvStreamReadable { .. }); @@ -800,16 +800,16 @@ fn no_dupdata_readable_events() { // Send one more data frame from client. The previous stream data has not been read yet, // therefore there should not be a new DataReadable event. client.stream_send(stream_id, &[0x00]).unwrap(); - let out_second_data_frame = client.process(None, now()); - mem::drop(server.process(out_second_data_frame.as_dgram_ref(), now())); + let out_second_data_frame = client.process_output(now()); + mem::drop(server.process(out_second_data_frame.dgram(), now())); assert!(!server.events().any(stream_readable)); // One more frame with a fin will not produce a new DataReadable event, because the // previous stream data has not been read yet. client.stream_send(stream_id, &[0x00]).unwrap(); client.stream_close_send(stream_id).unwrap(); - let out_third_data_frame = client.process(None, now()); - mem::drop(server.process(out_third_data_frame.as_dgram_ref(), now())); + let out_third_data_frame = client.process_output(now()); + mem::drop(server.process(out_third_data_frame.dgram(), now())); assert!(!server.events().any(stream_readable)); } @@ -822,8 +822,8 @@ fn no_dupdata_readable_events_empty_last_frame() { // create a stream let stream_id = client.stream_create(StreamType::BiDi).unwrap(); client.stream_send(stream_id, &[0x00]).unwrap(); - let out = client.process(None, now()); - mem::drop(server.process(out.as_dgram_ref(), now())); + let out = client.process_output(now()); + mem::drop(server.process(out.dgram(), now())); // We have a data_readable event. let stream_readable = |e| matches!(e, ConnectionEvent::RecvStreamReadable { .. }); @@ -832,8 +832,8 @@ fn no_dupdata_readable_events_empty_last_frame() { // An empty frame with a fin will not produce a new DataReadable event, because // the previous stream data has not been read yet. client.stream_close_send(stream_id).unwrap(); - let out_second_data_frame = client.process(None, now()); - mem::drop(server.process(out_second_data_frame.as_dgram_ref(), now())); + let out_second_data_frame = client.process_output(now()); + mem::drop(server.process(out_second_data_frame.dgram(), now())); assert!(!server.events().any(stream_readable)); } @@ -854,15 +854,15 @@ fn change_flow_control(stream_type: StreamType, new_fc: u64) { assert_eq!(u64::try_from(written1).unwrap(), RECV_BUFFER_START); // Send the stream to the client. - let out = server.process(None, now()); - mem::drop(client.process(out.as_dgram_ref(), now())); + let out = server.process_output(now()); + mem::drop(client.process(out.dgram(), now())); // change max_stream_data for stream_id. client.set_stream_max_data(stream_id, new_fc).unwrap(); // server should receive a MAX_SREAM_DATA frame if the flow control window is updated. - let out2 = client.process(None, now()); - let out3 = server.process(out2.as_dgram_ref(), now()); + let out2 = client.process_output(now()); + let out3 = server.process(out2.dgram(), now()); let expected = usize::from(RECV_BUFFER_START < new_fc); assert_eq!(server.stats().frame_rx.max_stream_data, expected); @@ -875,17 +875,17 @@ fn change_flow_control(stream_type: StreamType, new_fc: u64) { } // Exchange packets so that client gets all data. - let out4 = client.process(out3.as_dgram_ref(), now()); - let out5 = server.process(out4.as_dgram_ref(), now()); - mem::drop(client.process(out5.as_dgram_ref(), now())); + let out4 = client.process(out3.dgram(), now()); + let out5 = server.process(out4.dgram(), now()); + mem::drop(client.process(out5.dgram(), now())); // read all data by client let mut buf = [0x0; 10000]; let (read, _) = client.stream_recv(stream_id, &mut buf).unwrap(); assert_eq!(u64::try_from(read).unwrap(), max(RECV_BUFFER_START, new_fc)); - let out4 = client.process(None, now()); - mem::drop(server.process(out4.as_dgram_ref(), now())); + let out4 = client.process_output(now()); + mem::drop(server.process(out4.dgram(), now())); let written3 = server.stream_send(stream_id, &[0x0; 10000]).unwrap(); assert_eq!(u64::try_from(written3).unwrap(), new_fc); @@ -939,13 +939,13 @@ fn session_flow_control_stop_sending_state_recv() { // In this case the final size is only known after RESET frame is received. // The server sends STOP_SENDING -> the client sends RESET -> the server // sends MAX_DATA. - let out = server.process(None, now()).dgram(); - let out = client.process(out.as_ref(), now()).dgram(); + let out = server.process_output(now()).dgram(); + let out = client.process(out, now()).dgram(); // the client is still limited. let stream_id2 = client.stream_create(StreamType::UniDi).unwrap(); assert_eq!(client.stream_avail_send_space(stream_id2).unwrap(), 0); - let out = server.process(out.as_ref(), now()).dgram(); - client.process_input(&out.unwrap(), now()); + let out = server.process(out, now()).dgram(); + client.process_input(out.unwrap(), now()); assert_eq!( client.stream_avail_send_space(stream_id2).unwrap(), SMALL_MAX_DATA @@ -977,12 +977,12 @@ fn session_flow_control_stop_sending_state_size_known() { SMALL_MAX_DATA ); - let out1 = client.process(None, now()).dgram(); + let out1 = client.process_output(now()).dgram(); // Delay this packet and let the server receive fin first (it will enter SizeKnown state). client.stream_close_send(stream_id).unwrap(); - let out2 = client.process(None, now()).dgram(); + let out2 = client.process_output(now()).dgram(); - server.process_input(&out2.unwrap(), now()); + server.process_input(out2.unwrap(), now()); server .stream_stop_sending(stream_id, Error::NoError.code()) @@ -991,8 +991,8 @@ fn session_flow_control_stop_sending_state_size_known() { // In this case the final size is known when stream_stop_sending is called // and the server releases flow control immediately and sends STOP_SENDING and // MAX_DATA in the same packet. - let out = server.process(out1.as_ref(), now()).dgram(); - client.process_input(&out.unwrap(), now()); + let out = server.process(out1, now()).dgram(); + client.process_input(out.unwrap(), now()); // The flow control should have been updated and the client can again send // SMALL_MAX_DATA. @@ -1108,16 +1108,16 @@ fn session_flow_control_affects_all_streams() { fn connect_w_different_limit(bidi_limit: u64, unidi_limit: u64) { let mut client = default_client(); - let out = client.process(None, now()); + let out = client.process_output(now()); let mut server = new_server( ConnectionParameters::default() .max_streams(StreamType::BiDi, bidi_limit) .max_streams(StreamType::UniDi, unidi_limit), ); - let out = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); - let out = client.process(out.as_dgram_ref(), now()); - mem::drop(server.process(out.as_dgram_ref(), now())); + let out = client.process(out.dgram(), now()); + mem::drop(server.process(out.dgram(), now())); assert!(maybe_authenticate(&mut client)); diff --git a/neqo-transport/src/connection/tests/vn.rs b/neqo-transport/src/connection/tests/vn.rs index 87ab7b2401..6a2f5a3582 100644 --- a/neqo-transport/src/connection/tests/vn.rs +++ b/neqo-transport/src/connection/tests/vn.rs @@ -27,11 +27,11 @@ const INITIAL_PTO: Duration = Duration::from_millis(300); fn unknown_version() { let mut client = default_client(); // Start the handshake. - mem::drop(client.process(None, now()).dgram()); + mem::drop(client.process_output(now()).dgram()); let mut unknown_version_packet = vec![0x80, 0x1a, 0x1a, 0x1a, 0x1a]; unknown_version_packet.resize(MIN_INITIAL_PACKET_SIZE, 0x0); - mem::drop(client.process(Some(&datagram(unknown_version_packet)), now())); + mem::drop(client.process(Some(datagram(unknown_version_packet)), now())); assert_eq!(1, client.stats().dropped_rx); } @@ -43,7 +43,7 @@ fn server_receive_unknown_first_packet() { unknown_version_packet.resize(MIN_INITIAL_PACKET_SIZE, 0x0); assert_eq!( - server.process(Some(&datagram(unknown_version_packet)), now()), + server.process(Some(datagram(unknown_version_packet)), now()), Output::None ); @@ -72,7 +72,7 @@ fn version_negotiation_current_version() { let mut client = default_client(); // Start the handshake. let initial_pkt = client - .process(None, now()) + .process_output(now()) .dgram() .expect("a datagram") .to_vec(); @@ -83,7 +83,7 @@ fn version_negotiation_current_version() { ); let dgram = datagram(vn); - let delay = client.process(Some(&dgram), now()).callback(); + let delay = client.process(Some(dgram), now()).callback(); assert_eq!(delay, INITIAL_PTO); assert_eq!(*client.state(), State::WaitInitial); assert_eq!(1, client.stats().dropped_rx); @@ -94,7 +94,7 @@ fn version_negotiation_version0() { let mut client = default_client(); // Start the handshake. let initial_pkt = client - .process(None, now()) + .process_output(now()) .dgram() .expect("a datagram") .to_vec(); @@ -102,7 +102,7 @@ fn version_negotiation_version0() { let vn = create_vn(&initial_pkt, &[0, 0x1a1a_1a1a]); let dgram = datagram(vn); - let delay = client.process(Some(&dgram), now()).callback(); + let delay = client.process(Some(dgram), now()).callback(); assert_eq!(delay, INITIAL_PTO); assert_eq!(*client.state(), State::WaitInitial); assert_eq!(1, client.stats().dropped_rx); @@ -113,7 +113,7 @@ fn version_negotiation_only_reserved() { let mut client = default_client(); // Start the handshake. let initial_pkt = client - .process(None, now()) + .process_output(now()) .dgram() .expect("a datagram") .to_vec(); @@ -121,7 +121,7 @@ fn version_negotiation_only_reserved() { let vn = create_vn(&initial_pkt, &[0x1a1a_1a1a, 0x2a2a_2a2a]); let dgram = datagram(vn); - assert_eq!(client.process(Some(&dgram), now()), Output::None); + assert_eq!(client.process(Some(dgram), now()), Output::None); match client.state() { State::Closed(err) => { assert_eq!(*err, CloseReason::Transport(Error::VersionNegotiation)); @@ -135,7 +135,7 @@ fn version_negotiation_corrupted() { let mut client = default_client(); // Start the handshake. let initial_pkt = client - .process(None, now()) + .process_output(now()) .dgram() .expect("a datagram") .to_vec(); @@ -143,7 +143,7 @@ fn version_negotiation_corrupted() { let vn = create_vn(&initial_pkt, &[0x1a1a_1a1a, 0x2a2a_2a2a]); let dgram = datagram(vn[..vn.len() - 1].to_vec()); - let delay = client.process(Some(&dgram), now()).callback(); + let delay = client.process(Some(dgram), now()).callback(); assert_eq!(delay, INITIAL_PTO); assert_eq!(*client.state(), State::WaitInitial); assert_eq!(1, client.stats().dropped_rx); @@ -154,7 +154,7 @@ fn version_negotiation_empty() { let mut client = default_client(); // Start the handshake. let initial_pkt = client - .process(None, now()) + .process_output(now()) .dgram() .expect("a datagram") .to_vec(); @@ -162,7 +162,7 @@ fn version_negotiation_empty() { let vn = create_vn(&initial_pkt, &[]); let dgram = datagram(vn); - let delay = client.process(Some(&dgram), now()).callback(); + let delay = client.process(Some(dgram), now()).callback(); assert_eq!(delay, INITIAL_PTO); assert_eq!(*client.state(), State::WaitInitial); assert_eq!(1, client.stats().dropped_rx); @@ -173,14 +173,14 @@ fn version_negotiation_not_supported() { let mut client = default_client(); // Start the handshake. let initial_pkt = client - .process(None, now()) + .process_output(now()) .dgram() .expect("a datagram") .to_vec(); let vn = create_vn(&initial_pkt, &[0x1a1a_1a1a, 0x2a2a_2a2a, 0xff00_0001]); let dgram = datagram(vn); - assert_eq!(client.process(Some(&dgram), now()), Output::None); + assert_eq!(client.process(Some(dgram), now()), Output::None); match client.state() { State::Closed(err) => { assert_eq!(*err, CloseReason::Transport(Error::VersionNegotiation)); @@ -194,7 +194,7 @@ fn version_negotiation_bad_cid() { let mut client = default_client(); // Start the handshake. let mut initial_pkt = client - .process(None, now()) + .process_output(now()) .dgram() .expect("a datagram") .to_vec(); @@ -203,7 +203,7 @@ fn version_negotiation_bad_cid() { let vn = create_vn(&initial_pkt, &[0x1a1a_1a1a, 0x2a2a_2a2a, 0xff00_0001]); let dgram = datagram(vn); - let delay = client.process(Some(&dgram), now()).callback(); + let delay = client.process(Some(dgram), now()).callback(); assert_eq!(delay, INITIAL_PTO); assert_eq!(*client.state(), State::WaitInitial); assert_eq!(1, client.stats().dropped_rx); @@ -240,11 +240,11 @@ fn compatible_upgrade_large_initial() { // Each should elicit a Version 1 ACK from the server. let dgram = client.process_output(now()).dgram(); assert!(dgram.is_some()); - let dgram = server.process(dgram.as_ref(), now()).dgram(); + let dgram = server.process(dgram, now()).dgram(); assert!(dgram.is_some()); // The following uses the Version from *outside* this crate. assertions::assert_version(dgram.as_ref().unwrap(), Version::Version1.wire_version()); - client.process_input(&dgram.unwrap(), now()); + client.process_input(dgram.unwrap(), now()); connect(&mut client, &mut server); assert_eq!(client.version(), Version::Version2); @@ -308,7 +308,7 @@ fn version_negotiation_downgrade() { let initial = client.process_output(now()).dgram().unwrap(); let vn = create_vn(&initial, &[DOWNGRADE.wire_version()]); let dgram = datagram(vn); - client.process_input(&dgram, now()); + client.process_input(dgram, now()); connect_fail( &mut client, @@ -328,7 +328,7 @@ fn invalid_server_version() { new_server(ConnectionParameters::default().versions(Version::Version2, Version::all())); let dgram = client.process_output(now()).dgram(); - server.process_input(&dgram.unwrap(), now()); + server.process_input(dgram.unwrap(), now()); // One packet received. assert_eq!(server.stats().packets_rx, 1); @@ -459,7 +459,7 @@ fn compatible_upgrade_0rtt_rejected() { let initial = send_something(&mut client, now()); assertions::assert_version(&initial, Version::Version1.wire_version()); assertions::assert_coalesced_0rtt(&initial); - server.process_input(&initial, now()); + server.process_input(initial, now()); assert!(!server .events() .any(|e| matches!(e, ConnectionEvent::NewStream { .. }))); @@ -467,9 +467,9 @@ fn compatible_upgrade_0rtt_rejected() { // Finalize the connection. Don't use connect() because it uses // maybe_authenticate() too liberally and that eats the events we want to check. let dgram = server.process_output(now()).dgram(); // ServerHello flight - let dgram = client.process(dgram.as_ref(), now()).dgram(); // Client Finished (note: no authentication) - let dgram = server.process(dgram.as_ref(), now()).dgram(); // HANDSHAKE_DONE - client.process_input(&dgram.unwrap(), now()); + let dgram = client.process(dgram, now()).dgram(); // Client Finished (note: no authentication) + let dgram = server.process(dgram, now()).dgram(); // HANDSHAKE_DONE + client.process_input(dgram.unwrap(), now()); assert!(matches!(client.state(), State::Confirmed)); assert!(matches!(server.state(), State::Confirmed)); diff --git a/neqo-transport/src/connection/tests/zerortt.rs b/neqo-transport/src/connection/tests/zerortt.rs index 0411103407..1370e3f659 100644 --- a/neqo-transport/src/connection/tests/zerortt.rs +++ b/neqo-transport/src/connection/tests/zerortt.rs @@ -52,24 +52,24 @@ fn zero_rtt_send_recv() { let mut server = resumed_server(&client); // Send ClientHello. - let client_hs = client.process(None, now()); + let client_hs = client.process_output(now()); assert!(client_hs.as_dgram_ref().is_some()); // Now send a 0-RTT packet. let client_stream_id = client.stream_create(StreamType::UniDi).unwrap(); client.stream_send(client_stream_id, &[1, 2, 3]).unwrap(); - let client_0rtt = client.process(None, now()); + let client_0rtt = client.process_output(now()); assert!(client_0rtt.as_dgram_ref().is_some()); // 0-RTT packets on their own shouldn't be padded to MIN_INITIAL_PACKET_SIZE. assert!(client_0rtt.as_dgram_ref().unwrap().len() < MIN_INITIAL_PACKET_SIZE); - let server_hs = server.process(client_hs.as_dgram_ref(), now()); + let server_hs = server.process(client_hs.dgram(), now()); assert!(server_hs.as_dgram_ref().is_some()); // ServerHello, etc... let all_frames = server.stats().frame_tx.all(); let ack_frames = server.stats().frame_tx.ack; - let server_process_0rtt = server.process(client_0rtt.as_dgram_ref(), now()); - assert!(server_process_0rtt.as_dgram_ref().is_some()); + let server_process_0rtt = server.process(client_0rtt.dgram(), now()); + assert!(server_process_0rtt.dgram().is_some()); assert_eq!(server.stats().frame_tx.all(), all_frames + 1); assert_eq!(server.stats().frame_tx.ack, ack_frames + 1); @@ -100,12 +100,12 @@ fn zero_rtt_send_coalesce() { // This should result in a datagram that coalesces Initial and 0-RTT. let client_stream_id = client.stream_create(StreamType::UniDi).unwrap(); client.stream_send(client_stream_id, &[1, 2, 3]).unwrap(); - let client_0rtt = client.process(None, now()); + let client_0rtt = client.process_output(now()); assert!(client_0rtt.as_dgram_ref().is_some()); assertions::assert_coalesced_0rtt(&client_0rtt.as_dgram_ref().unwrap()[..]); - let server_hs = server.process(client_0rtt.as_dgram_ref(), now()); + let server_hs = server.process(client_0rtt.dgram(), now()); assert!(server_hs.as_dgram_ref().is_some()); // Should produce ServerHello etc... let server_stream_id = server @@ -153,18 +153,18 @@ fn zero_rtt_send_reject() { .expect("enable 0-RTT"); // Send ClientHello. - let client_hs = client.process(None, now()); + let client_hs = client.process_output(now()); assert!(client_hs.as_dgram_ref().is_some()); // Write some data on the client. let stream_id = client.stream_create(StreamType::UniDi).unwrap(); client.stream_send(stream_id, MESSAGE).unwrap(); - let client_0rtt = client.process(None, now()); + let client_0rtt = client.process_output(now()); assert!(client_0rtt.as_dgram_ref().is_some()); - let server_hs = server.process(client_hs.as_dgram_ref(), now()); + let server_hs = server.process(client_hs.dgram(), now()); assert!(server_hs.as_dgram_ref().is_some()); // Should produce ServerHello etc... - let server_ignored = server.process(client_0rtt.as_dgram_ref(), now()); + let server_ignored = server.process(client_0rtt.dgram(), now()); assert!(server_ignored.as_dgram_ref().is_none()); // The server shouldn't receive that 0-RTT data. @@ -172,14 +172,14 @@ fn zero_rtt_send_reject() { assert!(!server.events().any(recvd_stream_evt)); // Client should get a rejection. - let client_fin = client.process(server_hs.as_dgram_ref(), now()); + let client_fin = client.process(server_hs.dgram(), now()); let recvd_0rtt_reject = |e| e == ConnectionEvent::ZeroRttRejected; assert!(client.events().any(recvd_0rtt_reject)); // Server consume client_fin - let server_ack = server.process(client_fin.as_dgram_ref(), now()); + let server_ack = server.process(client_fin.dgram(), now()); assert!(server_ack.as_dgram_ref().is_some()); - let client_out = client.process(server_ack.as_dgram_ref(), now()); + let client_out = client.process(server_ack.dgram(), now()); assert!(client_out.as_dgram_ref().is_none()); // ...and the client stream should be gone. @@ -191,11 +191,11 @@ fn zero_rtt_send_reject() { let stream_id_after_reject = client.stream_create(StreamType::UniDi).unwrap(); assert_eq!(stream_id, stream_id_after_reject); client.stream_send(stream_id_after_reject, MESSAGE).unwrap(); - let client_after_reject = client.process(None, now()).dgram(); + let client_after_reject = client.process_output(now()).dgram(); assert!(client_after_reject.is_some()); // The server should receive new stream - server.process_input(&client_after_reject.unwrap(), now()); + server.process_input(client_after_reject.unwrap(), now()); assert!(server.events().any(recvd_stream_evt)); } @@ -227,15 +227,15 @@ fn zero_rtt_update_flow_control() { ); // Stream limits should be low for 0-RTT. - let client_hs = client.process(None, now()).dgram(); + let client_hs = client.process_output(now()).dgram(); let uni_stream = client.stream_create(StreamType::UniDi).unwrap(); assert!(!client.stream_send_atomic(uni_stream, MESSAGE).unwrap()); let bidi_stream = client.stream_create(StreamType::BiDi).unwrap(); assert!(!client.stream_send_atomic(bidi_stream, MESSAGE).unwrap()); // Now get the server transport parameters. - let server_hs = server.process(client_hs.as_ref(), now()).dgram(); - client.process_input(&server_hs.unwrap(), now()); + let server_hs = server.process(client_hs, now()).dgram(); + client.process_input(server_hs.unwrap(), now()); // The streams should report a writeable event. let mut uni_stream_event = false; @@ -299,7 +299,7 @@ fn zero_rtt_loss_accepted() { } // Process CI/0-RTT - let si = server.process(ci.as_dgram_ref(), now); + let si = server.process(ci.dgram(), now); assert!(si.as_dgram_ref().is_some()); let server_stream_id = server @@ -312,7 +312,7 @@ fn zero_rtt_loss_accepted() { assert_eq!(client_stream_id, server_stream_id.as_u64()); // 0-RTT should be accepted - client.process_input(si.as_dgram_ref().unwrap(), now); + client.process_input(si.dgram().unwrap(), now); let recvd_0rtt_reject = |e| e == ConnectionEvent::ZeroRttRejected; assert!( !client.events().any(recvd_0rtt_reject), diff --git a/neqo-transport/src/path.rs b/neqo-transport/src/path.rs index 71b9fa96d8..1f94b3205e 100644 --- a/neqo-transport/src/path.rs +++ b/neqo-transport/src/path.rs @@ -718,7 +718,7 @@ impl Path { // with the current value. let tos = self.tos(); self.ecn_info.on_packet_sent(stats); - Datagram::new(self.local, self.remote, tos, payload) + Datagram::new(self.local, self.remote, tos, payload.into()) } /// Get local address as `SocketAddr` diff --git a/neqo-transport/src/server.rs b/neqo-transport/src/server.rs index e2066f2932..66bec3d77e 100644 --- a/neqo-transport/src/server.rs +++ b/neqo-transport/src/server.rs @@ -195,7 +195,7 @@ impl Server { fn handle_initial( &mut self, initial: InitialDetails, - dgram: &Datagram, + dgram: Datagram>, now: Instant, ) -> Output { qdebug!([self], "Handle initial"); @@ -297,7 +297,7 @@ impl Server { fn accept_connection( &mut self, initial: InitialDetails, - dgram: &Datagram, + dgram: Datagram>, orig_dcid: Option, now: Instant, ) -> Output { @@ -339,7 +339,7 @@ impl Server { } } - fn process_input(&mut self, dgram: &Datagram, now: Instant) -> Output { + fn process_input(&mut self, dgram: Datagram>, now: Instant) -> Output { qtrace!("Process datagram: {}", hex(&dgram[..])); // This is only looking at the first packet header in the datagram. @@ -430,7 +430,7 @@ impl Server { let mut callback = None; for connection in &mut self.connections { - match connection.borrow_mut().process(None, now) { + match connection.borrow_mut().process_output(now) { Output::None => {} d @ Output::Datagram(_) => return d, Output::Callback(next) => match callback { @@ -443,8 +443,14 @@ impl Server { callback.map_or(Output::None, Output::Callback) } + /// Short-hand for [`Server::process`] without an input datagram. #[must_use] - pub fn process(&mut self, dgram: Option<&Datagram>, now: Instant) -> Output { + pub fn process_output(&mut self, now: Instant) -> Output { + self.process(None::, now) + } + + #[must_use] + pub fn process(&mut self, dgram: Option>>, now: Instant) -> Output { let out = dgram .map_or(Output::None, |d| self.process_input(d, now)) .or_else(|| self.process_next_output(now)); diff --git a/neqo-transport/tests/common/mod.rs b/neqo-transport/tests/common/mod.rs index 9fadf4e2af..a16c5f2c92 100644 --- a/neqo-transport/tests/common/mod.rs +++ b/neqo-transport/tests/common/mod.rs @@ -58,27 +58,27 @@ pub fn connect(client: &mut Connection, server: &mut Server) -> ConnectionRef { server.set_validation(ValidateAddress::Never); assert_eq!(*client.state(), State::Init); - let out = client.process(None, now()); // ClientHello + let out = client.process_output(now()); // ClientHello assert!(out.as_dgram_ref().is_some()); - let out = server.process(out.as_dgram_ref(), now()); // ServerHello... + let out = server.process(out.dgram(), now()); // ServerHello... assert!(out.as_dgram_ref().is_some()); // Ingest the server Certificate. - let out = client.process(out.as_dgram_ref(), now()); + let out = client.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_some()); // This should just be an ACK. - let out = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_none()); // So the server should have nothing to say. // Now mark the server as authenticated. client.authenticated(AuthenticationStatus::Ok, now()); - let out = client.process(None, now()); + let out = client.process_output(now()); assert!(out.as_dgram_ref().is_some()); assert_eq!(*client.state(), State::Connected); - let out = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_some()); // ACK + HANDSHAKE_DONE + NST // Have the client process the HANDSHAKE_DONE. - let out = client.process(out.as_dgram_ref(), now()); + let out = client.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_none()); assert_eq!(*client.state(), State::Confirmed); @@ -105,14 +105,14 @@ pub fn generate_ticket(server: &mut Server) -> ResumptionToken { let mut server_conn = connect(&mut client, server); server_conn.borrow_mut().send_ticket(now(), &[]).unwrap(); - let out = server.process(None, now()); - client.process_input(out.as_dgram_ref().unwrap(), now()); // Consume ticket, ignore output. + let out = server.process_output(now()); + client.process_input(out.dgram().unwrap(), now()); // Consume ticket, ignore output. let ticket = find_ticket(&mut client); // Have the client close the connection and then let the server clean up. client.close(now(), 0, "got a ticket"); let out = client.process_output(now()); - mem::drop(server.process(out.as_dgram_ref(), now())); + mem::drop(server.process(out.dgram(), now())); // Calling active_connections clears the set of active connections. assert_eq!(server.active_connections().len(), 1); ticket diff --git a/neqo-transport/tests/conn_vectors.rs b/neqo-transport/tests/conn_vectors.rs index 86fe9d36fc..93824f8d8d 100644 --- a/neqo-transport/tests/conn_vectors.rs +++ b/neqo-transport/tests/conn_vectors.rs @@ -265,7 +265,7 @@ fn process_client_initial(v: Version, packet: &[u8]) { let dgram = datagram(packet.to_vec()); assert_eq!(*server.state(), State::Init); - let out = server.process(Some(&dgram), now()); + let out = server.process(Some(dgram), now()); assert_eq!(*server.state(), State::Handshaking); assert!(out.dgram().is_some()); } diff --git a/neqo-transport/tests/connection.rs b/neqo-transport/tests/connection.rs index 934199022b..fcbcf228e5 100644 --- a/neqo-transport/tests/connection.rs +++ b/neqo-transport/tests/connection.rs @@ -29,9 +29,9 @@ fn truncate_long_packet() { let mut client = default_client(); let mut server = default_server(); - let out = client.process(None, now()); + let out = client.process_output(now()); assert!(out.as_dgram_ref().is_some()); - let out = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_some()); // This will truncate the Handshake packet from the server. @@ -44,18 +44,18 @@ fn truncate_long_packet() { dupe.tos(), &dupe[..(dupe.len() - tail)], ); - let hs_probe = client.process(Some(&truncated), now()).dgram(); + let hs_probe = client.process(Some(truncated), now()).dgram(); assert!(hs_probe.is_some()); // Now feed in the untruncated packet. - let out = client.process(out.as_dgram_ref(), now()); + let out = client.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_some()); // Throw this ACK away. assert!(test_fixture::maybe_authenticate(&mut client)); - let out = client.process(None, now()); + let out = client.process_output(now()); assert!(out.as_dgram_ref().is_some()); assert!(client.state().connected()); - let out = server.process(out.as_dgram_ref(), now()); + let out = server.process(out.dgram(), now()); assert!(out.as_dgram_ref().is_some()); assert!(server.state().connected()); } @@ -76,7 +76,7 @@ fn reorder_server_initial() { decode_initial_header(client_initial.as_dgram_ref().unwrap(), Role::Client).unwrap(); let client_dcid = client_dcid.to_owned(); - let server_packet = server.process(client_initial.as_dgram_ref(), now()).dgram(); + let server_packet = server.process(client_initial.dgram(), now()).dgram(); let (server_initial, server_hs) = split_datagram(server_packet.as_ref().unwrap()); let (protected_header, _, _, payload) = decode_initial_header(&server_initial, Role::Server).unwrap(); @@ -119,16 +119,16 @@ fn reorder_server_initial() { // Now a connection can be made successfully. // Though we modified the server's Initial packet, we get away with it. // TLS only authenticates the content of the CRYPTO frame, which was untouched. - client.process_input(&reordered, now()); - client.process_input(&server_hs.unwrap(), now()); + client.process_input(reordered, now()); + client.process_input(server_hs.unwrap(), now()); assert!(test_fixture::maybe_authenticate(&mut client)); let finished = client.process_output(now()); assert_eq!(*client.state(), State::Connected); - let done = server.process(finished.as_dgram_ref(), now()); + let done = server.process(finished.dgram(), now()); assert_eq!(*server.state(), State::Confirmed); - client.process_input(done.as_dgram_ref().unwrap(), now()); + client.process_input(done.dgram().unwrap(), now()); assert_eq!(*client.state(), State::Confirmed); } @@ -171,12 +171,13 @@ fn packet_without_frames() { let mut server = default_server(); let client_initial = client.process_output(now()); + let client_initial_clone = client_initial.as_dgram_ref().unwrap().clone(); let (_, client_dcid, _, _) = - decode_initial_header(client_initial.as_dgram_ref().unwrap(), Role::Client).unwrap(); + decode_initial_header(&client_initial_clone, Role::Client).unwrap(); - let server_packet = server.process(client_initial.as_dgram_ref(), now()).dgram(); + let server_packet = server.process(client_initial.dgram(), now()).dgram(); let modified = set_payload(server_packet.as_ref(), client_dcid, &[]); - client.process_input(&modified, now()); + client.process_input(modified, now()); assert_eq!( client.state(), &State::Closed(CloseReason::Transport(Error::ProtocolViolation)) @@ -192,12 +193,13 @@ fn packet_with_only_padding() { let mut server = default_server(); let client_initial = client.process_output(now()); + let client_initial_clone = client_initial.as_dgram_ref().unwrap().clone(); let (_, client_dcid, _, _) = - decode_initial_header(client_initial.as_dgram_ref().unwrap(), Role::Client).unwrap(); + decode_initial_header(&client_initial_clone, Role::Client).unwrap(); - let server_packet = server.process(client_initial.as_dgram_ref(), now()).dgram(); + let server_packet = server.process(client_initial.dgram(), now()).dgram(); let modified = set_payload(server_packet.as_ref(), client_dcid, &[0]); - client.process_input(&modified, now()); + client.process_input(modified, now()); assert_eq!(client.state(), &State::WaitInitial); } @@ -215,7 +217,7 @@ fn overflow_crypto() { decode_initial_header(client_initial.as_ref().unwrap(), Role::Client).unwrap(); let client_dcid = client_dcid.to_owned(); - let server_packet = server.process(client_initial.as_ref(), now()).dgram(); + let server_packet = server.process(client_initial, now()).dgram(); let (server_initial, _) = split_datagram(server_packet.as_ref().unwrap()); // Now decrypt the server packet to get AEAD and HP instances. @@ -261,7 +263,7 @@ fn overflow_crypto() { server_initial.tos(), packet, ); - client.process_input(&dgram, now()); + client.process_input(dgram, now()); if let State::Closing { error, .. } = client.state() { assert!( matches!(error, CloseReason::Transport(Error::CryptoBufferExceeded)), diff --git a/neqo-transport/tests/retry.rs b/neqo-transport/tests/retry.rs index a29af07a7c..36325be2e1 100644 --- a/neqo-transport/tests/retry.rs +++ b/neqo-transport/tests/retry.rs @@ -35,23 +35,23 @@ fn retry_basic() { server.set_validation(ValidateAddress::Always); let mut client = default_client(); - let dgram = client.process(None, now()).dgram(); // Initial + let dgram = client.process_output(now()).dgram(); // Initial assert!(dgram.is_some()); - let dgram = server.process(dgram.as_ref(), now()).dgram(); // Retry + let dgram = server.process(dgram, now()).dgram(); // Retry assert!(dgram.is_some()); assertions::assert_retry(dgram.as_ref().unwrap()); - let dgram = client.process(dgram.as_ref(), now()).dgram(); // Initial w/token + let dgram = client.process(dgram, now()).dgram(); // Initial w/token assert!(dgram.is_some()); - let dgram = server.process(dgram.as_ref(), now()).dgram(); // Initial, HS + let dgram = server.process(dgram, now()).dgram(); // Initial, HS assert!(dgram.is_some()); - mem::drop(client.process(dgram.as_ref(), now()).dgram()); // Ingest, drop any ACK. + mem::drop(client.process(dgram, now()).dgram()); // Ingest, drop any ACK. client.authenticated(AuthenticationStatus::Ok, now()); - let dgram = client.process(None, now()).dgram(); // Send Finished + let dgram = client.process_output(now()).dgram(); // Send Finished assert!(dgram.is_some()); assert_eq!(*client.state(), State::Connected); - let dgram = server.process(dgram.as_ref(), now()).dgram(); // (done) + let dgram = server.process(dgram, now()).dgram(); // (done) assert!(dgram.is_some()); // Note that this packet will be dropped... connected_server(&server); } @@ -66,12 +66,12 @@ fn implicit_rtt_retry() { let mut client = default_client(); let mut now = now(); - let dgram = client.process(None, now).dgram(); + let dgram = client.process_output(now).dgram(); now += RTT / 2; - let dgram = server.process(dgram.as_ref(), now).dgram(); + let dgram = server.process(dgram, now).dgram(); assertions::assert_retry(dgram.as_ref().unwrap()); now += RTT / 2; - client.process_input(&dgram.unwrap(), now); + client.process_input(dgram.unwrap(), now); assert_eq!(client.stats().rtt, RTT); } @@ -83,18 +83,18 @@ fn retry_expired() { let mut client = default_client(); let mut now = now(); - let dgram = client.process(None, now).dgram(); // Initial + let dgram = client.process_output(now).dgram(); // Initial assert!(dgram.is_some()); - let dgram = server.process(dgram.as_ref(), now).dgram(); // Retry + let dgram = server.process(dgram, now).dgram(); // Retry assert!(dgram.is_some()); assertions::assert_retry(dgram.as_ref().unwrap()); - let dgram = client.process(dgram.as_ref(), now).dgram(); // Initial w/token + let dgram = client.process(dgram, now).dgram(); // Initial w/token assert!(dgram.is_some()); now += Duration::from_secs(60); // Too long for Retry. - let dgram = server.process(dgram.as_ref(), now).dgram(); // Initial, HS + let dgram = server.process(dgram, now).dgram(); // Initial, HS assert!(dgram.is_none()); } @@ -111,26 +111,26 @@ fn retry_0rtt() { let client_stream = client.stream_create(StreamType::UniDi).unwrap(); client.stream_send(client_stream, &[1, 2, 3]).unwrap(); - let dgram = client.process(None, now()).dgram(); // Initial w/0-RTT + let dgram = client.process_output(now()).dgram(); // Initial w/0-RTT assert!(dgram.is_some()); assertions::assert_coalesced_0rtt(dgram.as_ref().unwrap()); - let dgram = server.process(dgram.as_ref(), now()).dgram(); // Retry + let dgram = server.process(dgram, now()).dgram(); // Retry assert!(dgram.is_some()); assertions::assert_retry(dgram.as_ref().unwrap()); // After retry, there should be a token and still coalesced 0-RTT. - let dgram = client.process(dgram.as_ref(), now()).dgram(); + let dgram = client.process(dgram, now()).dgram(); assert!(dgram.is_some()); assertions::assert_coalesced_0rtt(dgram.as_ref().unwrap()); - let dgram = server.process(dgram.as_ref(), now()).dgram(); // Initial, HS + let dgram = server.process(dgram, now()).dgram(); // Initial, HS assert!(dgram.is_some()); - let dgram = client.process(dgram.as_ref(), now()).dgram(); + let dgram = client.process(dgram, now()).dgram(); // Note: the client doesn't need to authenticate the server here // as there is no certificate; authentication is based on the ticket. assert!(dgram.is_some()); assert_eq!(*client.state(), State::Connected); - let dgram = server.process(dgram.as_ref(), now()).dgram(); // (done) + let dgram = server.process(dgram, now()).dgram(); // (done) assert!(dgram.is_some()); connected_server(&server); assert!(client.tls_info().unwrap().resumed()); @@ -142,14 +142,14 @@ fn retry_different_ip() { server.set_validation(ValidateAddress::Always); let mut client = default_client(); - let dgram = client.process(None.as_ref(), now()).dgram(); // Initial + let dgram = client.process_output(now()).dgram(); // Initial assert!(dgram.is_some()); - let dgram = server.process(dgram.as_ref(), now()).dgram(); // Retry + let dgram = server.process(dgram, now()).dgram(); // Retry assert!(dgram.is_some()); assertions::assert_retry(dgram.as_ref().unwrap()); - let dgram = client.process(dgram.as_ref(), now()).dgram(); // Initial w/token + let dgram = client.process(dgram, now()).dgram(); // Initial w/token assert!(dgram.is_some()); // Change the source IP on the address from the client. @@ -157,7 +157,7 @@ fn retry_different_ip() { let other_v4 = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 2)); let other_addr = SocketAddr::new(other_v4, 443); let from_other = Datagram::new(other_addr, dgram.destination(), dgram.tos(), &dgram[..]); - let dgram = server.process(Some(&from_other), now()).dgram(); + let dgram = server.process(Some(from_other), now()).dgram(); assert!(dgram.is_none()); } @@ -170,7 +170,7 @@ fn new_token_different_ip() { let mut client = default_client(); client.enable_resumption(now(), &token).unwrap(); - let dgram = client.process(None, now()).dgram(); // Initial + let dgram = client.process_output(now()).dgram(); // Initial assert!(dgram.is_some()); assertions::assert_initial(dgram.as_ref().unwrap(), true); @@ -178,7 +178,7 @@ fn new_token_different_ip() { let d = dgram.unwrap(); let src = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 2)), d.source().port()); let dgram = Some(Datagram::new(src, d.destination(), d.tos(), &d[..])); - let dgram = server.process(dgram.as_ref(), now()).dgram(); // Retry + let dgram = server.process(dgram, now()).dgram(); // Retry assert!(dgram.is_some()); assertions::assert_retry(dgram.as_ref().unwrap()); } @@ -192,7 +192,7 @@ fn new_token_expired() { let mut client = default_client(); client.enable_resumption(now(), &token).unwrap(); - let dgram = client.process(None, now()).dgram(); // Initial + let dgram = client.process_output(now()).dgram(); // Initial assert!(dgram.is_some()); assertions::assert_initial(dgram.as_ref().unwrap(), true); @@ -203,7 +203,7 @@ fn new_token_expired() { let d = dgram.unwrap(); let src = SocketAddr::new(d.source().ip(), d.source().port() + 1); let dgram = Some(Datagram::new(src, d.destination(), d.tos(), &d[..])); - let dgram = server.process(dgram.as_ref(), the_future).dgram(); // Retry + let dgram = server.process(dgram, the_future).dgram(); // Retry assert!(dgram.is_some()); assertions::assert_retry(dgram.as_ref().unwrap()); } @@ -215,34 +215,34 @@ fn retry_after_initial() { retry_server.set_validation(ValidateAddress::Always); let mut client = default_client(); - let cinit = client.process(None, now()).dgram(); // Initial + let cinit = client.process_output(now()).dgram(); // Initial assert!(cinit.is_some()); - let server_flight = server.process(cinit.as_ref(), now()).dgram(); // Initial + let server_flight = server.process(cinit.clone(), now()).dgram(); // Initial assert!(server_flight.is_some()); // We need to have the client just process the Initial. let (server_initial, _other) = split_datagram(server_flight.as_ref().unwrap()); - let dgram = client.process(Some(&server_initial), now()).dgram(); + let dgram = client.process(Some(server_initial), now()).dgram(); assert!(dgram.is_some()); assert!(*client.state() != State::Connected); - let retry = retry_server.process(cinit.as_ref(), now()).dgram(); // Retry! + let retry = retry_server.process(cinit, now()).dgram(); // Retry! assert!(retry.is_some()); assertions::assert_retry(retry.as_ref().unwrap()); // The client should ignore the retry. - let junk = client.process(retry.as_ref(), now()).dgram(); + let junk = client.process(retry, now()).dgram(); assert!(junk.is_none()); // Either way, the client should still be able to process the server flight and connect. - let dgram = client.process(server_flight.as_ref(), now()).dgram(); + let dgram = client.process(server_flight, now()).dgram(); assert!(dgram.is_some()); // Drop this one. assert!(test_fixture::maybe_authenticate(&mut client)); - let dgram = client.process(None, now()).dgram(); + let dgram = client.process_output(now()).dgram(); assert!(dgram.is_some()); assert_eq!(*client.state(), State::Connected); - let dgram = server.process(dgram.as_ref(), now()).dgram(); // (done) + let dgram = server.process(dgram, now()).dgram(); // (done) assert!(dgram.is_some()); connected_server(&server); } @@ -253,9 +253,9 @@ fn retry_bad_integrity() { server.set_validation(ValidateAddress::Always); let mut client = default_client(); - let dgram = client.process(None, now()).dgram(); // Initial + let dgram = client.process_output(now()).dgram(); // Initial assert!(dgram.is_some()); - let dgram = server.process(dgram.as_ref(), now()).dgram(); // Retry + let dgram = server.process(dgram, now()).dgram(); // Retry assert!(dgram.is_some()); let retry = &dgram.as_ref().unwrap(); @@ -266,7 +266,7 @@ fn retry_bad_integrity() { let tweaked_packet = Datagram::new(retry.source(), retry.destination(), retry.tos(), tweaked); // The client should ignore this packet. - let dgram = client.process(Some(&tweaked_packet), now()).dgram(); + let dgram = client.process(Some(tweaked_packet), now()).dgram(); assert!(dgram.is_none()); } @@ -278,16 +278,14 @@ fn retry_bad_token() { let mut server = default_server(); // Send a retry to one server, then replay it to the other. - let client_initial1 = client.process(None, now()).dgram(); + let client_initial1 = client.process_output(now()).dgram(); assert!(client_initial1.is_some()); - let retry = retry_server - .process(client_initial1.as_ref(), now()) - .dgram(); + let retry = retry_server.process(client_initial1, now()).dgram(); assert!(retry.is_some()); - let client_initial2 = client.process(retry.as_ref(), now()).dgram(); + let client_initial2 = client.process(retry, now()).dgram(); assert!(client_initial2.is_some()); - let dgram = server.process(client_initial2.as_ref(), now()).dgram(); + let dgram = server.process(client_initial2, now()).dgram(); assert!(dgram.is_none()); } @@ -303,20 +301,20 @@ fn retry_after_pto() { server.set_validation(ValidateAddress::Always); let mut now = now(); - let ci = client.process(None, now).dgram(); + let ci = client.process_output(now).dgram(); assert!(ci.is_some()); // sit on this for a bit.RefCell // Let PTO fire on the client and then let it exhaust its PTO packets. now += Duration::from_secs(1); - let pto = client.process(None, now).dgram(); + let pto = client.process_output(now).dgram(); assert!(pto.unwrap().len() >= MIN_INITIAL_PACKET_SIZE); - let cb = client.process(None, now).callback(); + let cb = client.process_output(now).callback(); assert_ne!(cb, Duration::new(0, 0)); - let retry = server.process(ci.as_ref(), now).dgram(); + let retry = server.process(ci, now).dgram(); assertions::assert_retry(retry.as_ref().unwrap()); - let ci2 = client.process(retry.as_ref(), now).dgram(); + let ci2 = client.process(retry, now).dgram(); assert!(ci2.unwrap().len() >= MIN_INITIAL_PACKET_SIZE); } @@ -326,14 +324,14 @@ fn vn_after_retry() { server.set_validation(ValidateAddress::Always); let mut client = default_client(); - let dgram = client.process(None, now()).dgram(); // Initial + let dgram = client.process_output(now()).dgram(); // Initial assert!(dgram.is_some()); - let dgram = server.process(dgram.as_ref(), now()).dgram(); // Retry + let dgram = server.process(dgram, now()).dgram(); // Retry assert!(dgram.is_some()); assertions::assert_retry(dgram.as_ref().unwrap()); - let dgram = client.process(dgram.as_ref(), now()).dgram(); // Initial w/token + let dgram = client.process(dgram, now()).dgram(); // Initial w/token assert!(dgram.is_some()); let mut encoder = Encoder::default(); @@ -345,7 +343,7 @@ fn vn_after_retry() { let vn = datagram(encoder.into()); assert_ne!( - client.process(Some(&vn), now()).callback(), + client.process(Some(vn), now()).callback(), Duration::from_secs(0) ); } @@ -368,13 +366,11 @@ fn mitm_retry() { let mut server = default_server(); // Trigger initial and a second client Initial. - let client_initial1 = client.process(None, now()).dgram(); + let client_initial1 = client.process_output(now()).dgram(); assert!(client_initial1.is_some()); - let retry = retry_server - .process(client_initial1.as_ref(), now()) - .dgram(); + let retry = retry_server.process(client_initial1, now()).dgram(); assert!(retry.is_some()); - let client_initial2 = client.process(retry.as_ref(), now()).dgram(); + let client_initial2 = client.process(retry, now()).dgram(); assert!(client_initial2.is_some()); // Now to start the epic process of decrypting the packet, @@ -432,15 +428,15 @@ fn mitm_retry() { notoken_packet, ); qdebug!("passing modified Initial to the main server"); - let dgram = server.process(Some(&new_datagram), now()).dgram(); + let dgram = server.process(Some(new_datagram), now()).dgram(); assert!(dgram.is_some()); - let dgram = client.process(dgram.as_ref(), now()).dgram(); // Generate an ACK. + let dgram = client.process(dgram, now()).dgram(); // Generate an ACK. assert!(dgram.is_some()); - let dgram = server.process(dgram.as_ref(), now()).dgram(); + let dgram = server.process(dgram, now()).dgram(); assert!(dgram.is_none()); assert!(test_fixture::maybe_authenticate(&mut client)); - let dgram = client.process(dgram.as_ref(), now()).dgram(); + let dgram = client.process(dgram, now()).dgram(); assert!(dgram.is_some()); // Client sending CLOSE_CONNECTIONs assert!(matches!( *client.state(), diff --git a/neqo-transport/tests/server.rs b/neqo-transport/tests/server.rs index 71ed21b881..12078a8960 100644 --- a/neqo-transport/tests/server.rs +++ b/neqo-transport/tests/server.rs @@ -47,8 +47,8 @@ pub fn complete_connection( }; while !is_done(client) { _ = test_fixture::maybe_authenticate(client); - let out = client.process(datagram.as_ref(), now()); - let out = server.process(out.as_dgram_ref(), now()); + let out = client.process(datagram, now()); + let out = server.process(out.dgram(), now()); datagram = out.dgram(); } @@ -111,9 +111,9 @@ fn connect_single_version_server() { // Run the version negotiation exchange if necessary. let out = client.process_output(now()); assert!(out.as_dgram_ref().is_some()); - let dgram = server.process(out.as_dgram_ref(), now()).dgram(); + let dgram = server.process(out.dgram(), now()).dgram(); assertions::assert_vn(dgram.as_ref().unwrap()); - client.process_input(&dgram.unwrap(), now()); + client.process_input(dgram.unwrap(), now()); } let server_conn = connect(&mut client, &mut server); @@ -133,14 +133,16 @@ fn duplicate_initial() { let mut client = default_client(); assert_eq!(*client.state(), State::Init); - let initial = client.process(None, now()); + let initial = client.process_output(now()); assert!(initial.as_dgram_ref().is_some()); // The server should ignore a packets with the same remote address and // destination connection ID as an existing connection attempt. - let server_initial = server.process(initial.as_dgram_ref(), now()).dgram(); + let server_initial = server + .process(initial.as_dgram_ref().cloned(), now()) + .dgram(); assert!(server_initial.is_some()); - let dgram = server.process(initial.as_dgram_ref(), now()).dgram(); + let dgram = server.process(initial.dgram(), now()).dgram(); assert!(dgram.is_none()); assert_eq!(server.active_connections().len(), 1); @@ -153,7 +155,7 @@ fn duplicate_initial_new_path() { let mut client = default_client(); assert_eq!(*client.state(), State::Init); - let initial = client.process(None, now()).dgram().unwrap(); + let initial = client.process_output(now()).dgram().unwrap(); let other = Datagram::new( SocketAddr::new(initial.source().ip(), initial.source().port() ^ 23), initial.destination(), @@ -161,11 +163,11 @@ fn duplicate_initial_new_path() { &initial[..], ); - let server_initial = server.process(Some(&initial), now()).dgram(); + let server_initial = server.process(Some(initial), now()).dgram(); assert!(server_initial.is_some()); // The server should ignore a packet with the same destination connection ID. - let dgram = server.process(Some(&other), now()).dgram(); + let dgram = server.process(Some(other), now()).dgram(); assert!(dgram.is_none()); assert_eq!(server.active_connections().len(), 1); @@ -178,20 +180,16 @@ fn different_initials_same_path() { let mut client1 = default_client(); let mut client2 = default_client(); - let client_initial1 = client1.process(None, now()); + let client_initial1 = client1.process_output(now()); assert!(client_initial1.as_dgram_ref().is_some()); - let client_initial2 = client2.process(None, now()); + let client_initial2 = client2.process_output(now()); assert!(client_initial2.as_dgram_ref().is_some()); // The server should respond to both as these came from different addresses. - let server_initial1 = server - .process(client_initial1.as_dgram_ref(), now()) - .dgram(); + let server_initial1 = server.process(client_initial1.dgram(), now()).dgram(); assert!(server_initial1.is_some()); - let server_initial2 = server - .process(client_initial2.as_dgram_ref(), now()) - .dgram(); + let server_initial2 = server.process(client_initial2.dgram(), now()).dgram(); assert!(server_initial2.is_some()); assert_eq!(server.active_connections().len(), 2); @@ -204,17 +202,19 @@ fn same_initial_after_connected() { let mut server = default_server(); let mut client = default_client(); - let client_initial = client.process(None, now()); + let client_initial = client.process_output(now()); assert!(client_initial.as_dgram_ref().is_some()); - let server_initial = server.process(client_initial.as_dgram_ref(), now()).dgram(); + let server_initial = server + .process(client_initial.as_dgram_ref().cloned(), now()) + .dgram(); assert!(server_initial.is_some()); complete_connection(&mut client, &mut server, server_initial); assert_eq!(server.active_connections().len(), 1); // Now make a new connection using the exact same initial as before. // The server should respond to an attempt to connect with the same Initial. - let dgram = server.process(client_initial.as_dgram_ref(), now()).dgram(); + let dgram = server.process(client_initial.dgram(), now()).dgram(); assert!(dgram.is_some()); // The server should make a new connection object. assert_eq!(server.active_connections().len(), 2); @@ -236,7 +236,7 @@ fn drop_non_initial() { bogus_data.resize(MIN_INITIAL_PACKET_SIZE, 66); let bogus = datagram(bogus_data); - assert!(server.process(Some(&bogus), now()).dgram().is_none()); + assert!(server.process(Some(bogus), now()).dgram().is_none()); } #[test] @@ -255,7 +255,7 @@ fn drop_short_initial() { bogus_data.resize(1199, 66); let bogus = datagram(bogus_data); - assert!(server.process(Some(&bogus), now()).dgram().is_none()); + assert!(server.process(Some(bogus), now()).dgram().is_none()); } #[test] @@ -272,7 +272,7 @@ fn drop_short_header_packet_for_unknown_connection() { bogus_data.resize(MIN_INITIAL_PACKET_SIZE, 66); let bogus = datagram(bogus_data); - assert!(server.process(Some(&bogus), now()).dgram().is_none()); + assert!(server.process(Some(bogus), now()).dgram().is_none()); } /// Verify that the server can read 0-RTT properly. A more robust server would buffer @@ -286,9 +286,9 @@ fn zero_rtt() { // Discharge the old connection so that we don't have to worry about it. let mut now = now(); - let t = server.process(None, now).callback(); + let t = server.process_output(now).callback(); now += t; - assert_eq!(server.process(None, now), Output::None); + assert_eq!(server.process_output(now), Output::None); assert_eq!(server.active_connections().len(), 0); let start_time = now; @@ -298,12 +298,12 @@ fn zero_rtt() { let mut client_send = || { let client_stream = client.stream_create(StreamType::UniDi).unwrap(); client.stream_send(client_stream, &[1, 2, 3]).unwrap(); - match client.process(None, now) { + match client.process_output(now) { Output::Datagram(d) => d, Output::Callback(t) => { // Pacing... now += t; - client.process(None, now).dgram().unwrap() + client.process_output(now).dgram().unwrap() } Output::None => panic!(), } @@ -317,12 +317,12 @@ fn zero_rtt() { let c4 = client_send(); // 0-RTT packets that arrive before the handshake get dropped. - mem::drop(server.process(Some(&c2), now)); + mem::drop(server.process(Some(c2), now)); assert!(server.active_connections().is_empty()); // Now handshake and let another 0-RTT packet in. - let shs = server.process(Some(&c1), now); - mem::drop(server.process(Some(&c3), now)); + let shs = server.process(Some(c1), now); + mem::drop(server.process(Some(c3), now)); // The server will have received two STREAM frames now if it processed both packets. // `ActiveConnectionRef` `Hash` implementation doesn’t access any of the interior mutable types. #[allow(clippy::mutable_key_type)] @@ -343,11 +343,11 @@ fn zero_rtt() { // Complete the handshake. As the client was pacing 0-RTT packets, extend the time // a little so that the pacer doesn't prevent the Finished from being sent. now += now - start_time; - let cfin = client.process(shs.as_dgram_ref(), now); - mem::drop(server.process(cfin.as_dgram_ref(), now)); + let cfin = client.process(shs.dgram(), now); + mem::drop(server.process(cfin.dgram(), now)); // The server will drop this last 0-RTT packet. - mem::drop(server.process(Some(&c4), now)); + mem::drop(server.process(Some(c4), now)); // `ActiveConnectionRef` `Hash` implementation doesn’t access any of the interior mutable types. #[allow(clippy::mutable_key_type)] let active = server.active_connections(); @@ -377,20 +377,20 @@ fn new_token_0rtt() { let client_stream = client.stream_create(StreamType::UniDi).unwrap(); client.stream_send(client_stream, &[1, 2, 3]).unwrap(); - let out = client.process(None, now()); // Initial w/0-RTT + let out = client.process_output(now()); // Initial w/0-RTT assert!(out.as_dgram_ref().is_some()); assertions::assert_initial(out.as_dgram_ref().unwrap(), true); assertions::assert_coalesced_0rtt(out.as_dgram_ref().unwrap()); - let out = server.process(out.as_dgram_ref(), now()); // Initial + let out = server.process(out.dgram(), now()); // Initial assert!(out.as_dgram_ref().is_some()); assertions::assert_initial(out.as_dgram_ref().unwrap(), false); - let dgram = client.process(out.as_dgram_ref(), now()); + let dgram = client.process(out.as_dgram_ref().cloned(), now()); // Note: the client doesn't need to authenticate the server here // as there is no certificate; authentication is based on the ticket. assert!(out.as_dgram_ref().is_some()); assert_eq!(*client.state(), State::Connected); - let dgram = server.process(dgram.as_dgram_ref(), now()); // (done) + let dgram = server.process(dgram.dgram(), now()); // (done) assert!(dgram.as_dgram_ref().is_some()); connected_server(&server); assert!(client.tls_info().unwrap().resumed()); @@ -405,7 +405,7 @@ fn new_token_different_port() { let mut client = default_client(); client.enable_resumption(now(), &token).unwrap(); - let dgram = client.process(None, now()).dgram(); // Initial + let dgram = client.process_output(now()).dgram(); // Initial assert!(dgram.is_some()); assertions::assert_initial(dgram.as_ref().unwrap(), true); @@ -413,7 +413,7 @@ fn new_token_different_port() { let d = dgram.unwrap(); let src = SocketAddr::new(d.source().ip(), d.source().port() + 1); let dgram = Some(Datagram::new(src, d.destination(), d.tos(), &d[..])); - let dgram = server.process(dgram.as_ref(), now()).dgram(); // Retry + let dgram = server.process(dgram, now()).dgram(); // Retry assert!(dgram.is_some()); assertions::assert_initial(dgram.as_ref().unwrap(), false); } @@ -423,7 +423,7 @@ fn bad_client_initial() { let mut client = default_client(); let mut server = default_server(); - let dgram = client.process(None, now()).dgram().expect("a datagram"); + let dgram = client.process_output(now()).dgram().expect("a datagram"); let (header, d_cid, s_cid, payload) = decode_initial_header(&dgram, Role::Client).unwrap(); let (aead, hp) = initial_aead_and_hp(d_cid, Role::Client); let (fixed_header, pn) = remove_header_protection(&hp, header, payload); @@ -470,7 +470,7 @@ fn bad_client_initial() { let bad_dgram = Datagram::new(dgram.source(), dgram.destination(), dgram.tos(), ciphertext); // The server should reject this. - let response = server.process(Some(&bad_dgram), now()); + let response = server.process(Some(bad_dgram), now()); let close_dgram = response.dgram().unwrap(); // The resulting datagram might contain multiple packets, but each is small. let (initial_close, rest) = split_datagram(&close_dgram); @@ -484,10 +484,10 @@ fn bad_client_initial() { // The client should accept this new and stop trying to connect. // It will generate a CONNECTION_CLOSE first though. - let response = client.process(Some(&close_dgram), now()).dgram(); + let response = client.process(Some(close_dgram), now()).dgram(); assert!(response.is_some()); // The client will now wait out its closing period. - let delay = client.process(None, now()).callback(); + let delay = client.process_output(now()).callback(); assert_ne!(delay, Duration::from_secs(0)); assert!(matches!( *client.state(), @@ -502,7 +502,7 @@ fn bad_client_initial() { } // After sending the CONNECTION_CLOSE, the server goes idle. - let res = server.process(None, now()); + let res = server.process_output(now()); assert_eq!(res, Output::None); } @@ -511,7 +511,7 @@ fn bad_client_initial_connection_close() { let mut client = default_client(); let mut server = default_server(); - let dgram = client.process(None, now()).dgram().expect("a datagram"); + let dgram = client.process_output(now()).dgram().expect("a datagram"); let (header, d_cid, s_cid, payload) = decode_initial_header(&dgram, Role::Client).unwrap(); let (aead, hp) = initial_aead_and_hp(d_cid, Role::Client); let (_, pn) = remove_header_protection(&hp, header, payload); @@ -553,9 +553,9 @@ fn bad_client_initial_connection_close() { // The server should ignore this and go to Draining. let mut now = now(); - let response = server.process(Some(&bad_dgram), now); + let response = server.process(Some(bad_dgram), now); now += response.callback(); - let response = server.process(None, now); + let response = server.process_output(now); assert_eq!(response, Output::None); } @@ -565,7 +565,7 @@ fn version_negotiation_ignored() { let mut client = default_client(); // Any packet will do, but let's make something that looks real. - let dgram = client.process(None, now()).dgram().expect("a datagram"); + let dgram = client.process_output(now()).dgram().expect("a datagram"); let mut input = dgram.to_vec(); input[1] ^= 0x12; let damaged = Datagram::new( @@ -574,7 +574,7 @@ fn version_negotiation_ignored() { dgram.tos(), input.clone(), ); - let vn = server.process(Some(&damaged), now()).dgram(); + let vn = server.process(Some(damaged), now()).dgram(); let mut dec = Decoder::from(&input[5..]); // Skip past version. let d_cid = dec.decode_vec(1).expect("client DCID").to_vec(); @@ -595,7 +595,7 @@ fn version_negotiation_ignored() { assert!(found, "valid version not found"); // Client ignores VN packet that contain negotiated version. - let res = client.process(Some(&vn), now()); + let res = client.process(Some(vn), now()); assert!(res.callback() > Duration::new(0, 120)); assert_eq!(client.state(), &State::WaitInitial); } @@ -615,9 +615,9 @@ fn version_negotiation() { // `connect()` runs a fixed exchange, so manually run the Version Negotiation. let dgram = client.process_output(now()).dgram(); assert!(dgram.is_some()); - let dgram = server.process(dgram.as_ref(), now()).dgram(); + let dgram = server.process(dgram, now()).dgram(); assertions::assert_vn(dgram.as_ref().unwrap()); - client.process_input(&dgram.unwrap(), now()); + client.process_input(dgram.unwrap(), now()); let sconn = connect(&mut client, &mut server); assert_eq!(client.version(), VN_VERSION); @@ -651,22 +651,22 @@ fn version_negotiation_and_compatible() { let dgram = client.process_output(now()).dgram(); assert!(dgram.is_some()); assertions::assert_version(dgram.as_ref().unwrap(), ORIG_VERSION.wire_version()); - let dgram = server.process(dgram.as_ref(), now()).dgram(); + let dgram = server.process(dgram, now()).dgram(); assertions::assert_vn(dgram.as_ref().unwrap()); - client.process_input(&dgram.unwrap(), now()); + client.process_input(dgram.unwrap(), now()); - let dgram = client.process(None, now()).dgram(); // ClientHello + let dgram = client.process_output(now()).dgram(); // ClientHello assertions::assert_version(dgram.as_ref().unwrap(), VN_VERSION.wire_version()); - let dgram = server.process(dgram.as_ref(), now()).dgram(); // ServerHello... + let dgram = server.process(dgram, now()).dgram(); // ServerHello... assertions::assert_version(dgram.as_ref().unwrap(), COMPAT_VERSION.wire_version()); - client.process_input(&dgram.unwrap(), now()); + client.process_input(dgram.unwrap(), now()); client.authenticated(AuthenticationStatus::Ok, now()); let dgram = client.process_output(now()).dgram(); assertions::assert_version(dgram.as_ref().unwrap(), COMPAT_VERSION.wire_version()); assert_eq!(*client.state(), State::Connected); - let dgram = server.process(dgram.as_ref(), now()).dgram(); // ACK + HANDSHAKE_DONE + NST - client.process_input(&dgram.unwrap(), now()); + let dgram = server.process(dgram, now()).dgram(); // ACK + HANDSHAKE_DONE + NST + client.process_input(dgram.unwrap(), now()); assert_eq!(*client.state(), State::Confirmed); let sconn = connected_server(&server); @@ -698,8 +698,8 @@ fn compatible_upgrade_resumption_and_vn() { assert_eq!(server_conn.borrow().version(), COMPAT_VERSION); server_conn.borrow_mut().send_ticket(now(), &[]).unwrap(); - let dgram = server.process(None, now()).dgram(); - client.process_input(&dgram.unwrap(), now()); // Consume ticket, ignore output. + let dgram = server.process_output(now()).dgram(); + client.process_input(dgram.unwrap(), now()); // Consume ticket, ignore output. let ticket = find_ticket(&mut client); // This new server will reject the ticket, but it will also generate a VN packet. @@ -713,9 +713,9 @@ fn compatible_upgrade_resumption_and_vn() { let dgram = client.process_output(now()).dgram(); assert!(dgram.is_some()); assertions::assert_version(dgram.as_ref().unwrap(), COMPAT_VERSION.wire_version()); - let dgram = server.process(dgram.as_ref(), now()).dgram(); + let dgram = server.process(dgram, now()).dgram(); assertions::assert_vn(dgram.as_ref().unwrap()); - client.process_input(&dgram.unwrap(), now()); + client.process_input(dgram.unwrap(), now()); let server_conn = connect(&mut client, &mut server); assert_eq!(client.version(), RESUMPTION_VERSION); @@ -730,14 +730,14 @@ fn closed() { connect(&mut client, &mut server); // The server will have sent a few things, so it will be on PTO. - let res = server.process(None, now()); + let res = server.process_output(now()); assert!(res.callback() > Duration::new(0, 0)); // The client will be on the delayed ACK timer. - let res = client.process(None, now()); + let res = client.process_output(now()); assert!(res.callback() > Duration::new(0, 0)); qtrace!("60s later"); - let res = server.process(None, now() + Duration::from_secs(60)); + let res = server.process_output(now() + Duration::from_secs(60)); assert_eq!(res, Output::None); } @@ -825,8 +825,8 @@ fn max_streams_after_0rtt_rejection() { client.enable_resumption(now(), &token).unwrap(); _ = client.stream_create(StreamType::BiDi).unwrap(); let dgram = client.process_output(now()).dgram(); - let dgram = server.process(dgram.as_ref(), now()).dgram(); - let dgram = client.process(dgram.as_ref(), now()).dgram(); + let dgram = server.process(dgram, now()).dgram(); + let dgram = client.process(dgram, now()).dgram(); assert!(dgram.is_some()); // We're far enough along to complete the test now. // Make sure that we can create MAX_STREAMS uni- and bidirectional streams. @@ -863,8 +863,8 @@ fn has_active_connections() { assert!(!server.has_active_connections()); - let initial = client.process(None, now()); - _ = server.process(initial.as_dgram_ref(), now()).dgram(); + let initial = client.process_output(now()); + _ = server.process(initial.dgram(), now()).dgram(); assert!(server.has_active_connections()); } diff --git a/test-fixture/src/lib.rs b/test-fixture/src/lib.rs index 0b10471594..97b68e50c6 100644 --- a/test-fixture/src/lib.rs +++ b/test-fixture/src/lib.rs @@ -235,7 +235,7 @@ pub fn handshake(client: &mut Connection, server: &mut Connection) { }; while !is_done(a) { _ = maybe_authenticate(a); - let d = a.process(datagram.as_ref(), now()); + let d = a.process(datagram, now()); datagram = d.dgram(); mem::swap(&mut a, &mut b); } diff --git a/test-fixture/src/sim/connection.rs b/test-fixture/src/sim/connection.rs index 17aa6091e2..63fb56ce0b 100644 --- a/test-fixture/src/sim/connection.rs +++ b/test-fixture/src/sim/connection.rs @@ -141,7 +141,7 @@ impl Node for ConnectionNode { fn process(&mut self, mut dgram: Option, now: Instant) -> Output { _ = self.process_goals(|goal, c| goal.process(c, now)); loop { - let res = self.c.process(dgram.take().as_ref(), now); + let res = self.c.process(dgram.take(), now); let mut active = false; while let Some(e) = self.c.next_event() { From 63d11dfd723b9667a4fb27db334f257bf255cb63 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Thu, 17 Oct 2024 12:15:45 +0200 Subject: [PATCH 2/3] feat(udp): return borrowed Datagram on receive Previously `recv_inner` would return `Datagram>`. In other words, it would allocate a new `Vec` for each UDP datagram payload. Now `recv_inner` reads into a provided buffer and returns `Datagram<&[u8]>`, i.e. it returns a view into the provided buffer without allocating. --- neqo-bin/src/udp.rs | 5 +- neqo-udp/src/lib.rs | 158 +++++++++++++++++++++++++------------------- 2 files changed, 95 insertions(+), 68 deletions(-) diff --git a/neqo-bin/src/udp.rs b/neqo-bin/src/udp.rs index 148ff43175..c418f5ee3c 100644 --- a/neqo-bin/src/udp.rs +++ b/neqo-bin/src/udp.rs @@ -7,6 +7,7 @@ use std::{io, net::SocketAddr}; use neqo_common::Datagram; +use neqo_transport::RECV_BUFFER_SIZE; /// Ideally this would live in [`neqo-udp`]. [`neqo-udp`] is used in Firefox. /// @@ -56,10 +57,12 @@ impl Socket { /// Receive a batch of [`Datagram`]s on the given [`Socket`], each set with /// the provided local address. pub fn recv(&self, local_address: &SocketAddr) -> Result, io::Error> { + let mut recv_buf = vec![0; RECV_BUFFER_SIZE]; self.inner .try_io(tokio::io::Interest::READABLE, || { - neqo_udp::recv_inner(local_address, &self.state, &self.inner) + neqo_udp::recv_inner(local_address, &self.state, &self.inner, &mut recv_buf) }) + .map(|dgrams| dgrams.map(|d| d.to_owned()).collect()) .or_else(|e| { if e.kind() == io::ErrorKind::WouldBlock { Ok(vec![]) diff --git a/neqo-udp/src/lib.rs b/neqo-udp/src/lib.rs index 5f1fb3dbe6..560eb55f50 100644 --- a/neqo-udp/src/lib.rs +++ b/neqo-udp/src/lib.rs @@ -7,10 +7,9 @@ #![allow(clippy::missing_errors_doc)] // Functions simply delegate to tokio and quinn-udp. use std::{ - cell::RefCell, io::{self, IoSliceMut}, net::SocketAddr, - slice, + slice::{self, Chunks}, }; use neqo_common::{qdebug, qtrace, Datagram, IpTos}; @@ -21,11 +20,7 @@ use quinn_udp::{EcnCodepoint, RecvMeta, Transmit, UdpSocketState}; /// Allows reading multiple datagrams in a single [`Socket::recv`] call. // // TODO: Experiment with different values across platforms. -const RECV_BUF_SIZE: usize = u16::MAX as usize; - -std::thread_local! { - static RECV_BUF: RefCell> = RefCell::new(vec![0; RECV_BUF_SIZE]); -} +pub const RECV_BUF_SIZE: usize = u16::MAX as usize; pub fn send_inner( state: &UdpSocketState, @@ -57,63 +52,89 @@ use std::os::fd::AsFd as SocketRef; #[cfg(windows)] use std::os::windows::io::AsSocket as SocketRef; -pub fn recv_inner( +pub fn recv_inner<'a>( local_address: &SocketAddr, state: &UdpSocketState, socket: impl SocketRef, -) -> Result, io::Error> { - let dgrams = RECV_BUF.with_borrow_mut(|recv_buf| -> Result, io::Error> { - let mut meta; - - loop { - meta = RecvMeta::default(); - - state.recv( - (&socket).into(), - &mut [IoSliceMut::new(recv_buf)], - slice::from_mut(&mut meta), - )?; - - if meta.len == 0 || meta.stride == 0 { - qdebug!( - "ignoring datagram from {} to {} len {} stride {}", - meta.addr, - local_address, - meta.len, - meta.stride - ); - continue; - } - - break; + recv_buf: &'a mut [u8], +) -> Result, io::Error> { + let mut meta; + + let data = loop { + meta = RecvMeta::default(); + + state.recv( + (&socket).into(), + &mut [IoSliceMut::new(recv_buf)], + slice::from_mut(&mut meta), + )?; + + if meta.len == 0 || meta.stride == 0 { + qdebug!( + "ignoring datagram from {} to {} len {} stride {}", + meta.addr, + local_address, + meta.len, + meta.stride + ); + continue; } - Ok(recv_buf[0..meta.len] - .chunks(meta.stride) - .map(|d| { - qtrace!( - "received {} bytes from {} to {}", - d.len(), - meta.addr, - local_address, - ); - Datagram::new( - meta.addr, - *local_address, - meta.ecn.map(|n| IpTos::from(n as u8)).unwrap_or_default(), - d, - ) - }) - .collect()) - })?; + break &recv_buf[..meta.len]; + }; qtrace!( - "received {} datagrams ({:?})", - dgrams.len(), - dgrams.iter().map(|d| d.len()).collect::>(), + "received {} bytes from {} to {} in {} segments", + data.len(), + meta.addr, + local_address, + data.len().div_ceil(meta.stride), ); - Ok(dgrams) + Ok(DatagramIter { + meta, + datagrams: data.chunks(meta.stride), + local_address: *local_address, + }) +} + +pub struct DatagramIter<'a> { + meta: RecvMeta, + datagrams: Chunks<'a, u8>, + local_address: SocketAddr, +} + +impl std::fmt::Debug for DatagramIter<'_> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Datagrams") + .field("meta", &self.meta) + .field("local_address", &self.local_address) + .finish() + } +} + +impl<'a> Iterator for DatagramIter<'a> { + type Item = Datagram<&'a [u8]>; + + fn next(&mut self) -> Option { + self.datagrams.next().map(|d| { + Datagram::from_slice( + self.meta.addr, + self.local_address, + self.meta + .ecn + .map(|n| IpTos::from(n as u8)) + .unwrap_or_default(), + d, + ) + }) + } +} + +impl ExactSizeIterator for DatagramIter<'_> { + fn len(&self) -> usize { + self.datagrams.len() + } } /// A wrapper around a UDP socket, sending and receiving [`Datagram`]s. @@ -138,8 +159,12 @@ impl Socket { /// Receive a batch of [`Datagram`]s on the given [`Socket`], each /// set with the provided local address. - pub fn recv(&self, local_address: &SocketAddr) -> Result, io::Error> { - recv_inner(local_address, &self.state, &self.inner) + pub fn recv<'a>( + &self, + local_address: &SocketAddr, + recv_buf: &'a mut [u8], + ) -> Result, io::Error> { + recv_inner(local_address, &self.state, &self.inner, recv_buf) } } @@ -170,7 +195,8 @@ mod tests { ); sender.send(&datagram)?; - let res = receiver.recv(&receiver_addr); + let mut recv_buf = vec![0; RECV_BUF_SIZE]; + let res = receiver.recv(&receiver_addr, &mut recv_buf); assert_eq!(res.unwrap_err().kind(), std::io::ErrorKind::WouldBlock); Ok(()) @@ -191,17 +217,15 @@ mod tests { sender.send(&datagram)?; - let received_datagram = receiver - .recv(&receiver_addr) - .expect("receive to succeed") - .into_iter() - .next() - .expect("receive to yield datagram"); + let mut recv_buf = vec![0; RECV_BUF_SIZE]; + let mut received_datagrams = receiver + .recv(&receiver_addr, &mut recv_buf) + .expect("receive to succeed"); // Assert that the ECN is correct. assert_eq!( IpTosEcn::from(datagram.tos()), - IpTosEcn::from(received_datagram.tos()) + IpTosEcn::from(received_datagrams.next().unwrap().tos()) ); Ok(()) @@ -236,11 +260,11 @@ mod tests { // Allow for one GSO sendmmsg to result in multiple GRO recvmmsg. let mut num_received = 0; + let mut recv_buf = vec![0; RECV_BUF_SIZE]; while num_received < max_gso_segments { receiver - .recv(&receiver_addr) + .recv(&receiver_addr, &mut recv_buf) .expect("receive to succeed") - .into_iter() .for_each(|d| { assert_eq!( SEGMENT_SIZE, From dd5fc94c177729d6a6414f99786c83934a9c23cd Mon Sep 17 00:00:00 2001 From: Max Inden Date: Fri, 18 Oct 2024 11:08:04 +0200 Subject: [PATCH 3/3] feat(bin): don't allocate in UDP recv path (#2189) Pass a long lived receive buffer to `neqo_udp::recv_inner`, receiving an iterator of `Datagram<&[u8]>`s pointing into that buffer, thus no longer allocating in UDP receive path. --- neqo-bin/src/client/http09.rs | 9 ++--- neqo-bin/src/client/http3.rs | 9 ++--- neqo-bin/src/client/mod.rs | 62 ++++++++++++++++++++--------------- neqo-bin/src/server/http09.rs | 2 +- neqo-bin/src/server/http3.rs | 2 +- neqo-bin/src/server/mod.rs | 15 ++++++--- neqo-bin/src/udp.rs | 15 +++++---- 7 files changed, 66 insertions(+), 48 deletions(-) diff --git a/neqo-bin/src/client/http09.rs b/neqo-bin/src/client/http09.rs index d4a1829892..728088a3f8 100644 --- a/neqo-bin/src/client/http09.rs +++ b/neqo-bin/src/client/http09.rs @@ -181,10 +181,11 @@ impl super::Client for Connection { self.process_output(now) } - fn process_multiple_input<'a, I>(&mut self, dgrams: I, now: Instant) - where - I: IntoIterator>, - { + fn process_multiple_input<'a>( + &mut self, + dgrams: impl IntoIterator>, + now: Instant, + ) { self.process_multiple_input(dgrams, now); } diff --git a/neqo-bin/src/client/http3.rs b/neqo-bin/src/client/http3.rs index b8745a1fd6..e667355d9b 100644 --- a/neqo-bin/src/client/http3.rs +++ b/neqo-bin/src/client/http3.rs @@ -132,10 +132,11 @@ impl super::Client for Http3Client { self.process_output(now) } - fn process_multiple_input<'a, I>(&mut self, dgrams: I, now: Instant) - where - I: IntoIterator>, - { + fn process_multiple_input<'a>( + &mut self, + dgrams: impl IntoIterator>, + now: Instant, + ) { self.process_multiple_input(dgrams, now); } diff --git a/neqo-bin/src/client/mod.rs b/neqo-bin/src/client/mod.rs index beac31dda3..9b06195ec7 100644 --- a/neqo-bin/src/client/mod.rs +++ b/neqo-bin/src/client/mod.rs @@ -374,9 +374,11 @@ enum CloseState { /// Network client, e.g. [`neqo_transport::Connection`] or [`neqo_http3::Http3Client`]. trait Client { fn process_output(&mut self, now: Instant) -> Output; - fn process_multiple_input<'a, I>(&mut self, dgrams: I, now: Instant) - where - I: IntoIterator>; + fn process_multiple_input<'a>( + &mut self, + dgrams: impl IntoIterator>, + now: Instant, + ); fn has_events(&self) -> bool; fn close(&mut self, now: Instant, app_error: AppError, msg: S) where @@ -392,9 +394,28 @@ struct Runner<'a, H: Handler> { handler: H, timeout: Option>>, args: &'a Args, + recv_buf: Vec, } impl<'a, H: Handler> Runner<'a, H> { + fn new( + local_addr: SocketAddr, + socket: &'a mut crate::udp::Socket, + client: H::Client, + handler: H, + args: &'a Args, + ) -> Self { + Self { + local_addr, + socket, + client, + handler, + args, + timeout: None, + recv_buf: vec![0; neqo_udp::RECV_BUF_SIZE], + } + } + async fn run(mut self) -> Res> { loop { let handler_done = self.handler.handle(&mut self.client)?; @@ -457,12 +478,13 @@ impl<'a, H: Handler> Runner<'a, H> { async fn process_multiple_input(&mut self) -> Res<()> { loop { - let dgrams = self.socket.recv(&self.local_addr)?; - if dgrams.is_empty() { + let Some(dgrams) = self.socket.recv(&self.local_addr, &mut self.recv_buf)? else { + break; + }; + if dgrams.len() == 0 { break; } - self.client - .process_multiple_input(dgrams.iter().map(Datagram::borrow), Instant::now()); + self.client.process_multiple_input(dgrams, Instant::now()); self.process_output().await?; } @@ -573,32 +595,18 @@ pub async fn client(mut args: Args) -> Res<()> { let handler = http09::Handler::new(to_request, &args); - Runner { - args: &args, - client, - handler, - local_addr: real_local, - socket: &mut socket, - timeout: None, - } - .run() - .await? + Runner::new(real_local, &mut socket, client, handler, &args) + .run() + .await? } else { let client = http3::create_client(&args, real_local, remote_addr, &hostname, token) .expect("failed to create client"); let handler = http3::Handler::new(to_request, &args); - Runner { - args: &args, - client, - handler, - local_addr: real_local, - socket: &mut socket, - timeout: None, - } - .run() - .await? + Runner::new(real_local, &mut socket, client, handler, &args) + .run() + .await? }; } } diff --git a/neqo-bin/src/server/http09.rs b/neqo-bin/src/server/http09.rs index ff7214f3a8..1815140b01 100644 --- a/neqo-bin/src/server/http09.rs +++ b/neqo-bin/src/server/http09.rs @@ -185,7 +185,7 @@ impl HttpServer { } impl super::HttpServer for HttpServer { - fn process(&mut self, dgram: Option<&Datagram>, now: Instant) -> Output { + fn process(&mut self, dgram: Option, now: Instant) -> Output { self.server.process(dgram, now) } diff --git a/neqo-bin/src/server/http3.rs b/neqo-bin/src/server/http3.rs index 1cb9daf6d2..3506387a62 100644 --- a/neqo-bin/src/server/http3.rs +++ b/neqo-bin/src/server/http3.rs @@ -79,7 +79,7 @@ impl Display for HttpServer { } impl super::HttpServer for HttpServer { - fn process(&mut self, dgram: Option<&Datagram>, now: Instant) -> neqo_http3::Output { + fn process(&mut self, dgram: Option, now: Instant) -> neqo_http3::Output { self.server.process(dgram, now) } diff --git a/neqo-bin/src/server/mod.rs b/neqo-bin/src/server/mod.rs index abf614f1f8..4dce9d243f 100644 --- a/neqo-bin/src/server/mod.rs +++ b/neqo-bin/src/server/mod.rs @@ -194,7 +194,7 @@ fn qns_read_response(filename: &str) -> Result, io::Error> { #[allow(clippy::module_name_repetitions)] pub trait HttpServer: Display { - fn process(&mut self, dgram: Option<&Datagram>, now: Instant) -> Output; + fn process(&mut self, dgram: Option, now: Instant) -> Output; fn process_events(&mut self, now: Instant); fn has_events(&self) -> bool; } @@ -205,6 +205,7 @@ pub struct ServerRunner { server: Box, timeout: Option>>, sockets: Vec<(SocketAddr, crate::udp::Socket)>, + recv_buf: Vec, } impl ServerRunner { @@ -219,6 +220,7 @@ impl ServerRunner { server, timeout: None, sockets, + recv_buf: vec![0; neqo_udp::RECV_BUF_SIZE], } } @@ -236,7 +238,7 @@ impl ServerRunner { .unwrap_or(first_socket) } - async fn process(&mut self, mut dgram: Option<&Datagram>) -> Result<(), io::Error> { + async fn process(&mut self, mut dgram: Option) -> Result<(), io::Error> { loop { match self.server.process(dgram.take(), (self.now)()) { Output::Datagram(dgram) => { @@ -289,12 +291,15 @@ impl ServerRunner { match self.ready().await? { Ready::Socket(inx) => loop { let (host, socket) = self.sockets.get_mut(inx).unwrap(); - let dgrams = socket.recv(host)?; - if dgrams.is_empty() { + let Some(dgrams) = socket.recv(host, &mut self.recv_buf)? else { + break; + }; + if dgrams.len() == 0 { break; } + let dgrams: Vec = dgrams.map(|d| d.to_owned()).collect(); for dgram in dgrams { - self.process(Some(&dgram)).await?; + self.process(Some(dgram)).await?; } }, Ready::Timeout => { diff --git a/neqo-bin/src/udp.rs b/neqo-bin/src/udp.rs index c418f5ee3c..0ea6edc449 100644 --- a/neqo-bin/src/udp.rs +++ b/neqo-bin/src/udp.rs @@ -7,7 +7,7 @@ use std::{io, net::SocketAddr}; use neqo_common::Datagram; -use neqo_transport::RECV_BUFFER_SIZE; +use neqo_udp::DatagramIter; /// Ideally this would live in [`neqo-udp`]. [`neqo-udp`] is used in Firefox. /// @@ -56,16 +56,19 @@ impl Socket { /// Receive a batch of [`Datagram`]s on the given [`Socket`], each set with /// the provided local address. - pub fn recv(&self, local_address: &SocketAddr) -> Result, io::Error> { - let mut recv_buf = vec![0; RECV_BUFFER_SIZE]; + pub fn recv<'a>( + &self, + local_address: &SocketAddr, + recv_buf: &'a mut [u8], + ) -> Result>, io::Error> { self.inner .try_io(tokio::io::Interest::READABLE, || { - neqo_udp::recv_inner(local_address, &self.state, &self.inner, &mut recv_buf) + neqo_udp::recv_inner(local_address, &self.state, &self.inner, recv_buf) }) - .map(|dgrams| dgrams.map(|d| d.to_owned()).collect()) + .map(Some) .or_else(|e| { if e.kind() == io::ErrorKind::WouldBlock { - Ok(vec![]) + Ok(None) } else { Err(e) }