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

refactor(s2n-quic-core): move ack::Transmission to core #2122

Merged
merged 1 commit into from
Feb 21, 2024
Merged
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
5 changes: 5 additions & 0 deletions quic/s2n-quic-core/src/ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
pub mod ranges;
pub mod set;
pub mod settings;
pub mod transmission;

#[cfg(feature = "alloc")]
pub use ranges::Ranges;
pub use set::Set;
pub use settings::Settings;
pub use transmission::Transmission;

#[cfg(any(test, feature = "testing"))]
pub mod testing;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: quic/s2n-quic-core/src/ack/transmission.rs
expression: "size_of::<Set>()"
---
32
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: quic/s2n-quic-core/src/ack/transmission.rs
expression: "size_of::<Transmission>()"
---
16
23 changes: 23 additions & 0 deletions quic/s2n-quic-core/src/ack/testing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

use crate::{
ack::transmission::Transmission,
packet::number::{PacketNumber, PacketNumberSpace},
varint::VarInt,
};

/// Generates AckElicitingTransmissions from increasing packet numbers
pub fn transmissions_iter() -> impl Iterator<Item = Transmission> {
packet_numbers_iter().map(|pn| Transmission {
sent_in_packet: pn,
largest_received_packet_number_acked: pn,
})
}

/// Generates increasing packet numbers
pub fn packet_numbers_iter() -> impl Iterator<Item = PacketNumber> {
Iterator::map(0u32.., |pn| {
PacketNumberSpace::ApplicationData.new_packet_number(VarInt::from_u32(pn))
})
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

use crate::{ack, packet::number::PacketNumber};
use core::ops::RangeInclusive;
use s2n_quic_core::{ack, packet::number::PacketNumber};

pub type AckRange = RangeInclusive<PacketNumber>;

#[derive(Clone, Debug, Default)]
pub struct AckElicitingTransmissionSet {
pub struct Set {
/// A stable ack-eliciting transmission
///
/// In this case, "stable" means the oldest transmission that
Expand All @@ -17,15 +17,16 @@ pub struct AckElicitingTransmissionSet {
/// are always either removed or declared lost. Without it,
/// the TX packet number would be a moving target
/// and packet number ranges would never be removed.
stable: Option<AckElicitingTransmission>,
stable: Option<Transmission>,

/// The latest ack-eliciting transmission
latest: Option<AckElicitingTransmission>,
latest: Option<Transmission>,
}

impl AckElicitingTransmissionSet {
impl Set {
/// Called when an ACK frame is bundled with an ack eliciting packet
pub fn on_transmit(&mut self, transmission: AckElicitingTransmission) {
#[inline]
pub fn on_transmit(&mut self, transmission: Transmission) {
self.latest = Some(transmission);

// only set the stable transmission if it's not set
Expand All @@ -35,6 +36,7 @@ impl AckElicitingTransmissionSet {
}

/// Called when a set of packets was acknowledged or lost
#[inline]
pub fn on_update<A: ack::Set>(&mut self, ack_set: &A) -> Option<AckRange> {
if let Some(ack_range) = self
.latest
Expand Down Expand Up @@ -69,13 +71,14 @@ impl AckElicitingTransmissionSet {
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd)]
pub struct AckElicitingTransmission {
pub struct Transmission {
pub sent_in_packet: PacketNumber,
pub largest_received_packet_number_acked: PacketNumber,
}

impl AckElicitingTransmission {
impl Transmission {
/// Called when a set of packets was acknowledged or lost
#[inline]
pub fn ack_range<A: ack::Set>(&self, ack_set: &A) -> Option<AckRange> {
//= https://www.rfc-editor.org/rfc/rfc9000#section-13.2.4
//# When a packet containing an ACK frame is acknowledged, the receiver can stop
Expand All @@ -97,12 +100,13 @@ impl AckElicitingTransmission {

#[cfg(test)]
mod tests {
use super::{super::tests::transmissions_iter, *};
use super::*;
use crate::ack::testing::transmissions_iter;

/// This test is meant to simulate an immediate ACK rate from a peer
#[test]
fn latest_ack_test() {
let mut set = AckElicitingTransmissionSet::default();
let mut set = Set::default();
assert!(set.is_empty());

let mut transmissions = transmissions_iter();
Expand Down Expand Up @@ -132,7 +136,7 @@ mod tests {
/// This test is meant to simulate a delayed ACK rate from a peer
#[test]
fn stable_ack_test() {
let mut set = AckElicitingTransmissionSet::default();
let mut set = Set::default();
assert!(set.is_empty());

let mut transmissions = transmissions_iter();
Expand Down Expand Up @@ -168,17 +172,12 @@ mod tests {
}

#[test]
#[cfg_attr(miri, ignore)] // miri is unable to read the file system
fn size_of_snapshots() {
use core::mem::size_of;
use insta::assert_debug_snapshot;

assert_debug_snapshot!(
"AckElicitingTransmission",
size_of::<AckElicitingTransmission>()
);
assert_debug_snapshot!(
"AckElicitingTransmissionSet",
size_of::<AckElicitingTransmissionSet>()
);
assert_debug_snapshot!("Transmission", size_of::<Transmission>());
assert_debug_snapshot!("Set", size_of::<Set>());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: values

---
[
Ack(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: frames
expression: values
---
[
ConnectionClose(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: frames
expression: values
---
[
Crypto(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: frames
expression: values
---
[
DataBlocked(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
assertion_line: 231
expression: values
---
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: frames
expression: values
---
[
HandshakeDone(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: frames
expression: values
---
[
MaxData(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: frames
expression: values
---
[
MaxStreamData(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: frames
expression: values
---
[
MaxStreams(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: values

---
[
NewConnectionId(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: frames
expression: values
---
[
NewToken(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: frames
expression: values
---
[
Padding(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: frames
expression: values
---
[
PathChallenge(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: frames
expression: values
---
[
PathResponse(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: frames
expression: values
---
[
Ping(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: frames
expression: values
---
[
ResetStream(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: values

---
[
RetireConnectionId(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: frames
expression: values
---
[
StopSending(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: frames
expression: values
---
[
Stream(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: frames
expression: values
---
[
StreamDataBlocked(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: quic/s2n-quic-core/src/frame/mod.rs
expression: frames
expression: values
---
[
StreamsBlocked(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: quic/s2n-quic-core/src/packet/number/mod.rs
source: quic/s2n-quic-core/src/packet/number/tests.rs
expression: "size_of::<PacketNumber>()"

---
8
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: quic/s2n-quic-core/src/packet/number/mod.rs
source: quic/s2n-quic-core/src/packet/number/tests.rs
expression: "size_of::<PacketNumberLen>()"

---
2
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: quic/s2n-quic-core/src/packet/number/mod.rs
source: quic/s2n-quic-core/src/packet/number/tests.rs
expression: "size_of::<PacketNumberSpace>()"

---
1
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: quic/s2n-quic-core/src/packet/number/mod.rs
source: quic/s2n-quic-core/src/packet/number/tests.rs
expression: "size_of::<ProtectedPacketNumber>()"

---
0
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: quic/s2n-quic-core/src/packet/number/mod.rs
source: quic/s2n-quic-core/src/packet/number/tests.rs
expression: "size_of::<TruncatedPacketNumber>()"

---
12
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: quic/s2n-quic-core/src/packet/mod.rs
expression: values

---
[
ZeroRtt(
Expand Down
2 changes: 1 addition & 1 deletion quic/s2n-quic-core/src/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ macro_rules! __probe_define__ {
name: stringify!($fun),
target: concat!(module_path!(), "::", stringify!($fun)),
$(
?$arg,
$arg = ?$arg,
)*
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: quic/s2n-quic-core/src/recovery/simulation.rs
assertion_line: 149
expression: self
---
Simulation {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: quic/s2n-quic-core/src/recovery/simulation.rs
assertion_line: 149
expression: self
---
Simulation {
Expand Down
Loading
Loading