s2n_quic_core/frame/
ack_elicitation.rs

1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4#[cfg(any(test, feature = "generator"))]
5use bolero_generator::prelude::*;
6use core::ops::{BitOr, BitOrAssign};
7
8//= https://www.rfc-editor.org/rfc/rfc9002#section-2
9//# Ack-eliciting packets:  Packets that contain ack-eliciting frames
10//#    elicit an ACK from the receiver within the maximum acknowledgement
11//#    delay and are called ack-eliciting packets.
12
13/// Describes if a frame or packet requires an ACK from the peer
14#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
15#[cfg_attr(any(test, feature = "generator"), derive(TypeGenerator))]
16pub enum AckElicitation {
17    NonEliciting,
18    Eliciting,
19}
20
21impl Default for AckElicitation {
22    fn default() -> Self {
23        Self::NonEliciting
24    }
25}
26
27impl AckElicitation {
28    /// Returns true if the `AckElicitation` is set to `Eliciting`
29    pub fn is_ack_eliciting(self) -> bool {
30        matches!(self, Self::Eliciting)
31    }
32}
33
34impl BitOr<AckElicitation> for AckElicitation {
35    type Output = Self;
36
37    fn bitor(self, rhs: Self) -> Self {
38        match (self, rhs) {
39            (Self::Eliciting, _) => Self::Eliciting,
40            (_, Self::Eliciting) => Self::Eliciting,
41            (_, _) => Self::NonEliciting,
42        }
43    }
44}
45
46impl BitOrAssign<AckElicitation> for AckElicitation {
47    fn bitor_assign(&mut self, rhs: Self) {
48        *self = *self | rhs;
49    }
50}
51
52/// Trait to retrieve the AckElicitation for a given value
53pub trait AckElicitable {
54    #[inline]
55    fn ack_elicitation(&self) -> AckElicitation {
56        AckElicitation::Eliciting
57    }
58}
59
60//= https://www.rfc-editor.org/rfc/rfc9002#section-2
61//# Ack-eliciting Frames:  All frames other than ACK, PADDING, and
62//#    CONNECTION_CLOSE are considered ack-eliciting.
63
64impl<AckRanges> AckElicitable for crate::frame::Ack<AckRanges> {
65    #[inline]
66    fn ack_elicitation(&self) -> AckElicitation {
67        AckElicitation::NonEliciting
68    }
69}
70impl AckElicitable for crate::frame::ConnectionClose<'_> {
71    #[inline]
72    fn ack_elicitation(&self) -> AckElicitation {
73        AckElicitation::NonEliciting
74    }
75}
76impl<Data> AckElicitable for crate::frame::Crypto<Data> {}
77//= https://www.rfc-editor.org/rfc/rfc9221#section-5.2
78//# Although DATAGRAM frames are not retransmitted upon loss detection,
79//# they are ack-eliciting ([RFC9002]).
80impl<Data> AckElicitable for crate::frame::Datagram<Data> {}
81impl AckElicitable for crate::frame::DataBlocked {}
82//= https://www.rfc-editor.org/rfc/rfc9000#section-19.21
83//# Extension frames MUST be congestion controlled and MUST cause
84//# an ACK frame to be sent.
85impl AckElicitable for crate::frame::DcStatelessResetTokens<'_> {}
86impl AckElicitable for crate::frame::HandshakeDone {}
87impl AckElicitable for crate::frame::MaxData {}
88impl AckElicitable for crate::frame::MaxStreamData {}
89impl AckElicitable for crate::frame::MaxStreams {}
90impl AckElicitable for crate::frame::NewConnectionId<'_> {}
91impl AckElicitable for crate::frame::NewToken<'_> {}
92impl AckElicitable for crate::frame::Padding {
93    #[inline]
94    fn ack_elicitation(&self) -> AckElicitation {
95        AckElicitation::NonEliciting
96    }
97}
98impl AckElicitable for crate::frame::PathChallenge<'_> {}
99impl AckElicitable for crate::frame::PathResponse<'_> {}
100impl AckElicitable for crate::frame::Ping {}
101impl AckElicitable for crate::frame::ResetStream {}
102impl AckElicitable for crate::frame::RetireConnectionId {}
103impl AckElicitable for crate::frame::StopSending {}
104impl<Data> AckElicitable for crate::frame::Stream<Data> {}
105impl AckElicitable for crate::frame::StreamDataBlocked {}
106impl AckElicitable for crate::frame::StreamsBlocked {}