Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Shuffle the client Initial crypto data #2228

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions neqo-transport/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2168,6 +2168,7 @@ impl Connection {
self.crypto.write_frame(
PacketNumberSpace::ApplicationData,
builder,
false,
tokens,
frame_stats,
);
Expand Down Expand Up @@ -2301,7 +2302,13 @@ impl Connection {
self.write_appdata_frames(builder, &mut tokens);
} else {
let stats = &mut self.stats.borrow_mut().frame_tx;
self.crypto.write_frame(space, builder, &mut tokens, stats);
self.crypto.write_frame(
space,
builder,
space == PacketNumberSpace::Initial && self.role == Role::Client,
&mut tokens,
stats,
);
}
}

Expand Down Expand Up @@ -2512,7 +2519,7 @@ impl Connection {
// Perform additional padding for Initial packets as necessary.
let mut packets: Vec<u8> = encoder.into();
if let Some(mut initial) = initial_sent.take() {
if needs_padding {
if needs_padding && packets.len() < profile.limit() {
qdebug!(
[self],
"pad Initial from {} to PLPMTU {}",
Expand Down
12 changes: 10 additions & 2 deletions neqo-transport/src/connection/tests/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,13 +1193,17 @@ 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.
let mut crypto_frames_in_first_ci = 0;
for i in 1..=5 {
let ci = client.process_output(now).dgram().unwrap();
if i == 1 {
crypto_frames_in_first_ci = client.stats().frame_tx.crypto;
}
assert_eq!(ci.len(), client.plpmtu());
assert_eq!(
client.stats().frame_tx,
FrameStats {
crypto: i,
crypto: i * crypto_frames_in_first_ci,
..Default::default()
}
);
Expand All @@ -1219,13 +1223,17 @@ fn server_initial_retransmits_identical() {
// 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);
let mut crypto_frames_in_first_si = 0;
for i in 1..=3 {
let si = server.process(ci.take(), now).dgram().unwrap();
if i == 1 {
crypto_frames_in_first_si = server.stats().frame_tx.crypto;
}
assert_eq!(si.len(), server.plpmtu());
assert_eq!(
server.stats().frame_tx,
FrameStats {
crypto: i * 2,
crypto: i * crypto_frames_in_first_si,
ack: i,
..Default::default()
}
Expand Down
2 changes: 2 additions & 0 deletions neqo-transport/src/connection/tests/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ fn idle_caching() {
server.crypto.streams.write_frame(
PacketNumberSpace::Initial,
&mut builder,
false,
&mut tokens,
&mut FrameStats::default(),
);
Expand All @@ -319,6 +320,7 @@ fn idle_caching() {
server.crypto.streams.write_frame(
PacketNumberSpace::Initial,
&mut builder,
false,
&mut tokens,
&mut FrameStats::default(),
);
Expand Down
2 changes: 1 addition & 1 deletion neqo-transport/src/connection/tests/vn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ fn compatible_upgrade_large_initial() {
assert_eq!(server.version(), Version::Version2);
// Only handshake padding is "dropped".
assert_eq!(client.stats().dropped_rx, 1);
assert_eq!(server.stats().dropped_rx, 1);
assert!(server.stats().dropped_rx >= 1);
}

/// A server that supports versions 1 and 2 might prefer version 1 and that's OK.
Expand Down
Loading