Skip to content

Commit

Permalink
feat(transport): accept borrowed instead of owned input datagram
Browse files Browse the repository at this point in the history
Previously `process_input` (and the like) took a `Datagram<Vec<u8>>` as input.
In other words, it required allocating each UDP datagram payload in a dedicated
`Vec<u8>` 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.
  • Loading branch information
mxinden committed Oct 21, 2024
1 parent 0dcc9b2 commit 6b99a55
Show file tree
Hide file tree
Showing 46 changed files with 1,309 additions and 1,299 deletions.
4 changes: 2 additions & 2 deletions fuzz/fuzz_targets/client_initial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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))]
Expand Down
9 changes: 3 additions & 6 deletions fuzz/fuzz_targets/server_initial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))]
Expand Down
2 changes: 1 addition & 1 deletion neqo-bin/src/client/http09.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl super::Client for Connection {

fn process_multiple_input<'a, I>(&mut self, dgrams: I, now: Instant)
where
I: IntoIterator<Item = &'a Datagram>,
I: IntoIterator<Item = Datagram<&'a [u8]>>,
{
self.process_multiple_input(dgrams, now);
}
Expand Down
2 changes: 1 addition & 1 deletion neqo-bin/src/client/http3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl super::Client for Http3Client {

fn process_multiple_input<'a, I>(&mut self, dgrams: I, now: Instant)
where
I: IntoIterator<Item = &'a Datagram>,
I: IntoIterator<Item = Datagram<&'a [u8]>>,
{
self.process_multiple_input(dgrams, now);
}
Expand Down
4 changes: 2 additions & 2 deletions neqo-bin/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = &'a Datagram>;
I: IntoIterator<Item = Datagram<&'a [u8]>>;
fn has_events(&self) -> bool;
fn close<S>(&mut self, now: Instant, app_error: AppError, msg: S)
where
Expand Down Expand Up @@ -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?;
}

Expand Down
Loading

0 comments on commit 6b99a55

Please sign in to comment.