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, Default, PartialEq, Eq, Hash)]
15#[cfg_attr(any(test, feature = "generator"), derive(TypeGenerator))]
16pub enum AckElicitation {
17    #[default]
18    NonEliciting,
19    Eliciting,
20}
21
22impl AckElicitation {
23    /// Returns true if the `AckElicitation` is set to `Eliciting`
24    pub fn is_ack_eliciting(self) -> bool {
25        matches!(self, Self::Eliciting)
26    }
27}
28
29impl BitOr<AckElicitation> for AckElicitation {
30    type Output = Self;
31
32    fn bitor(self, rhs: Self) -> Self {
33        match (self, rhs) {
34            (Self::Eliciting, _) => Self::Eliciting,
35            (_, Self::Eliciting) => Self::Eliciting,
36            (_, _) => Self::NonEliciting,
37        }
38    }
39}
40
41impl BitOrAssign<AckElicitation> for AckElicitation {
42    fn bitor_assign(&mut self, rhs: Self) {
43        *self = *self | rhs;
44    }
45}
46
47/// Trait to retrieve the AckElicitation for a given value
48pub trait AckElicitable {
49    #[inline]
50    fn ack_elicitation(&self) -> AckElicitation {
51        AckElicitation::Eliciting
52    }
53}
54
55//= https://www.rfc-editor.org/rfc/rfc9002#section-2
56//# Ack-eliciting Frames:  All frames other than ACK, PADDING, and
57//#    CONNECTION_CLOSE are considered ack-eliciting.
58
59impl<AckRanges> AckElicitable for crate::frame::Ack<AckRanges> {
60    #[inline]
61    fn ack_elicitation(&self) -> AckElicitation {
62        AckElicitation::NonEliciting
63    }
64}
65impl AckElicitable for crate::frame::ConnectionClose<'_> {
66    #[inline]
67    fn ack_elicitation(&self) -> AckElicitation {
68        AckElicitation::NonEliciting
69    }
70}
71impl<Data> AckElicitable for crate::frame::Crypto<Data> {}
72//= https://www.rfc-editor.org/rfc/rfc9221#section-5.2
73//# Although DATAGRAM frames are not retransmitted upon loss detection,
74//# they are ack-eliciting ([RFC9002]).
75impl<Data> AckElicitable for crate::frame::Datagram<Data> {}
76impl AckElicitable for crate::frame::DataBlocked {}
77//= https://www.rfc-editor.org/rfc/rfc9000#section-19.21
78//# Extension frames MUST be congestion controlled and MUST cause
79//# an ACK frame to be sent.
80impl AckElicitable for crate::frame::DcStatelessResetTokens<'_> {}
81impl AckElicitable for crate::frame::MtuProbingComplete {}
82impl AckElicitable for crate::frame::HandshakeDone {}
83impl AckElicitable for crate::frame::MaxData {}
84impl AckElicitable for crate::frame::MaxStreamData {}
85impl AckElicitable for crate::frame::MaxStreams {}
86impl AckElicitable for crate::frame::NewConnectionId<'_> {}
87impl AckElicitable for crate::frame::NewToken<'_> {}
88impl AckElicitable for crate::frame::Padding {
89    #[inline]
90    fn ack_elicitation(&self) -> AckElicitation {
91        AckElicitation::NonEliciting
92    }
93}
94impl AckElicitable for crate::frame::PathChallenge<'_> {}
95impl AckElicitable for crate::frame::PathResponse<'_> {}
96impl AckElicitable for crate::frame::Ping {}
97impl AckElicitable for crate::frame::ResetStream {}
98impl AckElicitable for crate::frame::RetireConnectionId {}
99impl AckElicitable for crate::frame::StopSending {}
100impl<Data> AckElicitable for crate::frame::Stream<Data> {}
101impl AckElicitable for crate::frame::StreamDataBlocked {}
102impl AckElicitable for crate::frame::StreamsBlocked {}