diff --git a/quiche/src/lib.rs b/quiche/src/lib.rs index c6cd5fbc7e..b1228539d8 100644 --- a/quiche/src/lib.rs +++ b/quiche/src/lib.rs @@ -1355,9 +1355,6 @@ 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, @@ -1871,8 +1868,6 @@ impl Connection { packet::PktNumSpace::new(), ], - next_pkt_num: 0, - peer_transport_params: TransportParams::default(), local_transport_params: config.local_transport_params.clone(), @@ -3604,7 +3599,7 @@ impl Connection { b.cap() }; - let pn = self.next_pkt_num; + let pn = pkt_space.next_pkt_num; let pn_len = packet::pkt_num_len(pn)?; // The AEAD overhead at the current encryption level. @@ -4594,7 +4589,7 @@ impl Connection { path.recovery.delivery_rate_update_app_limited(true); } - self.next_pkt_num += 1; + pkt_space.next_pkt_num += 1; let handshake_status = recovery::HandshakeStatus { has_handshake_keys: self.pkt_num_spaces[packet::Epoch::Handshake] @@ -8692,7 +8687,7 @@ pub mod testing { space.key_update = Some(packet::KeyUpdate { crypto_open: open_prev.unwrap(), - pn_on_update: self.client.next_pkt_num, + pn_on_update: space.next_pkt_num, update_acked: true, timer: time::Instant::now(), }); @@ -8794,7 +8789,7 @@ pub mod testing { let space = &mut conn.pkt_num_spaces[epoch]; - let pn = conn.next_pkt_num; + let pn = space.next_pkt_num; let pn_len = 4; let send_path = conn.paths.get_active()?; @@ -8857,7 +8852,7 @@ pub mod testing { aead, )?; - conn.next_pkt_num += 1; + space.next_pkt_num += 1; Ok(written) } @@ -11118,7 +11113,7 @@ mod tests { // Client acks RESET_STREAM frame. let mut ranges = ranges::RangeSet::default(); - ranges.insert(pipe.server.next_pkt_num - 5..pipe.server.next_pkt_num); + ranges.insert(0..6); let frames = [frame::Frame::ACK { ack_delay: 15, @@ -13309,7 +13304,7 @@ mod tests { for _ in 0..512 { let recv_count = pipe.server.recv_count; - last_packet_sent = pipe.client.next_pkt_num; + last_packet_sent = pipe.client.pkt_num_spaces[epoch].next_pkt_num; pipe.send_pkt_to_server(pkt_type, &frames, &mut buf) .unwrap(); @@ -13317,7 +13312,7 @@ mod tests { assert_eq!(pipe.server.recv_count, recv_count + 1); // Skip packet number. - pipe.client.next_pkt_num += 1; + pipe.client.pkt_num_spaces[epoch].next_pkt_num += 1; } assert_eq!( @@ -16992,7 +16987,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 = pipe.client.next_pkt_num; + let pn = space.next_pkt_num; let pn_len = 4; let hdr = Header { @@ -17028,7 +17023,7 @@ mod tests { aead, ) .expect("packet encrypt"); - pipe.client.next_pkt_num += 1; + space.next_pkt_num += 1; pipe.server .recv(&mut pkt_buf[..written], RecvInfo { diff --git a/quiche/src/packet.rs b/quiche/src/packet.rs index 5478509d76..c19494a14a 100644 --- a/quiche/src/packet.rs +++ b/quiche/src/packet.rs @@ -860,6 +860,8 @@ 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, @@ -885,6 +887,8 @@ 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(),