Skip to content

Commit

Permalink
Merge pull request #29 from martinthomson/test-0rtt-drop
Browse files Browse the repository at this point in the history
  • Loading branch information
larseggert authored Aug 20, 2024
2 parents 50af2f7 + 8dc9d3d commit bba53bc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
12 changes: 6 additions & 6 deletions neqo-transport/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1745,12 +1745,12 @@ impl Connection {
// Make a path on which to run the handshake.
self.setup_handshake_path(path, now);

self.zero_rtt_state = match self.crypto.enable_0rtt(self.version, self.role) {
Ok(true) => {
qdebug!([self], "Accepted 0-RTT");
ZeroRttState::AcceptedServer
}
_ => ZeroRttState::Rejected,
self.zero_rtt_state = if self.crypto.enable_0rtt(self.version, self.role) == Ok(true) {
qdebug!([self], "Accepted 0-RTT");
ZeroRttState::AcceptedServer
} else {
qtrace!([self], "Rejected 0-RTT");
ZeroRttState::Rejected
};

// The server knows the final version if it has remote transport parameters.
Expand Down
21 changes: 11 additions & 10 deletions neqo-transport/src/connection/tests/zerortt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,15 @@ fn zero_rtt_loss_accepted() {
let mut now = now();
let client_stream_id = client.stream_create(StreamType::UniDi).unwrap();
client.stream_send(client_stream_id, &[1, 2, 3]).unwrap();
let ci = client.process(None, now);
let mut ci = client.process(None, now);
assert!(ci.as_dgram_ref().is_some());

if i > 0 {
// Drop CI/0-RTT a number of times
qdebug!("Drop CI/0-RTT {} times", i);
for _ in 0..i {
now += client.process(None, now).callback();
let ci = client.process(None, now);
assert!(ci.as_dgram_ref().is_some());
}
// Drop CI/0-RTT a number of times
qdebug!("Drop CI/0-RTT {} extra times", i);
for _ in 0..i {
now += client.process(None, now).callback();
ci = client.process(None, now);
assert!(ci.as_dgram_ref().is_some());
}

// Process CI/0-RTT
Expand All @@ -297,6 +295,9 @@ fn zero_rtt_loss_accepted() {
// 0-RTT should be accepted
_ = client.process(si.as_dgram_ref(), now);
let recvd_0rtt_reject = |e| e == ConnectionEvent::ZeroRttRejected;
assert!(!client.events().any(recvd_0rtt_reject));
assert!(
!client.events().any(recvd_0rtt_reject),
"rejected 0-RTT after {i} extra dropped packets"
);
}
}
2 changes: 1 addition & 1 deletion test-fixture/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn fixture_init() {

// This needs to be > 2ms to avoid it being rounded to zero.
// NSS operates in milliseconds and halves any value it is provided.
pub const ANTI_REPLAY_WINDOW: Duration = Duration::from_millis(10);
pub const ANTI_REPLAY_WINDOW: Duration = Duration::from_millis(10000);

/// A baseline time for all tests. This needs to be earlier than what `now()` produces
/// because of the need to have a span of time elapse for anti-replay purposes.
Expand Down

0 comments on commit bba53bc

Please sign in to comment.