Skip to content

Commit

Permalink
generate packet numbers from a single sequence
Browse files Browse the repository at this point in the history
This reverts commit 40e2433.
  • Loading branch information
ghedo committed May 8, 2024
1 parent 70b67f9 commit 657b50d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
25 changes: 15 additions & 10 deletions quiche/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,9 @@ pub struct Connection {
/// Packet number spaces.
pkt_num_spaces: [packet::PktNumSpace; packet::Epoch::count()],

/// Next packet number.
next_pkt_num: u64,

/// Peer's transport parameters.
peer_transport_params: TransportParams,

Expand Down Expand Up @@ -1868,6 +1871,8 @@ impl Connection {
packet::PktNumSpace::new(),
],

next_pkt_num: 0,

peer_transport_params: TransportParams::default(),

local_transport_params: config.local_transport_params.clone(),
Expand Down Expand Up @@ -3599,7 +3604,7 @@ impl Connection {
b.cap()
};

let pn = pkt_space.next_pkt_num;
let pn = self.next_pkt_num;
let pn_len = packet::pkt_num_len(pn)?;

// The AEAD overhead at the current encryption level.
Expand Down Expand Up @@ -4589,7 +4594,7 @@ impl Connection {
path.recovery.delivery_rate_update_app_limited(true);
}

pkt_space.next_pkt_num += 1;
self.next_pkt_num += 1;

let handshake_status = recovery::HandshakeStatus {
has_handshake_keys: self.pkt_num_spaces[packet::Epoch::Handshake]
Expand Down Expand Up @@ -8687,7 +8692,7 @@ pub mod testing {

space.key_update = Some(packet::KeyUpdate {
crypto_open: open_prev.unwrap(),
pn_on_update: space.next_pkt_num,
pn_on_update: self.client.next_pkt_num,
update_acked: true,
timer: time::Instant::now(),
});
Expand Down Expand Up @@ -8789,7 +8794,7 @@ pub mod testing {

let space = &mut conn.pkt_num_spaces[epoch];

let pn = space.next_pkt_num;
let pn = conn.next_pkt_num;
let pn_len = 4;

let send_path = conn.paths.get_active()?;
Expand Down Expand Up @@ -8852,7 +8857,7 @@ pub mod testing {
aead,
)?;

space.next_pkt_num += 1;
conn.next_pkt_num += 1;

Ok(written)
}
Expand Down Expand Up @@ -11109,7 +11114,7 @@ mod tests {

// Client acks RESET_STREAM frame.
let mut ranges = ranges::RangeSet::default();
ranges.insert(0..6);
ranges.insert(pipe.server.next_pkt_num - 5..pipe.server.next_pkt_num);

let frames = [frame::Frame::ACK {
ack_delay: 15,
Expand Down Expand Up @@ -13451,15 +13456,15 @@ mod tests {
for _ in 0..512 {
let recv_count = pipe.server.recv_count;

last_packet_sent = pipe.client.pkt_num_spaces[epoch].next_pkt_num;
last_packet_sent = pipe.client.next_pkt_num;

pipe.send_pkt_to_server(pkt_type, &frames, &mut buf)
.unwrap();

assert_eq!(pipe.server.recv_count, recv_count + 1);

// Skip packet number.
pipe.client.pkt_num_spaces[epoch].next_pkt_num += 1;
pipe.client.next_pkt_num += 1;
}

assert_eq!(
Expand Down Expand Up @@ -17130,7 +17135,7 @@ mod tests {
let mut b = octets::OctetsMut::with_slice(&mut pkt_buf);
let epoch = packet::Type::Short.to_epoch().unwrap();
let space = &mut pipe.client.pkt_num_spaces[epoch];
let pn = space.next_pkt_num;
let pn = pipe.client.next_pkt_num;
let pn_len = 4;

let hdr = Header {
Expand Down Expand Up @@ -17166,7 +17171,7 @@ mod tests {
aead,
)
.expect("packet encrypt");
space.next_pkt_num += 1;
pipe.client.next_pkt_num += 1;

pipe.server
.recv(&mut pkt_buf[..written], RecvInfo {
Expand Down
4 changes: 0 additions & 4 deletions quiche/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,6 @@ pub struct PktNumSpace {

pub largest_rx_non_probing_pkt_num: u64,

pub next_pkt_num: u64,

pub recv_pkt_need_ack: ranges::RangeSet,

pub recv_pkt_num: PktNumWindow,
Expand All @@ -887,8 +885,6 @@ impl PktNumSpace {

largest_rx_non_probing_pkt_num: 0,

next_pkt_num: 0,

recv_pkt_need_ack: ranges::RangeSet::new(crate::MAX_ACK_RANGES),

recv_pkt_num: PktNumWindow::default(),
Expand Down

0 comments on commit 657b50d

Please sign in to comment.