s2n_quic_core/transmission/
constraint.rs

1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4#[cfg(feature = "generator")]
5use bolero_generator::prelude::*;
6
7#[cfg(test)]
8use bolero::generator::*;
9
10#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
11#[cfg_attr(any(feature = "generator", test), derive(TypeGenerator))]
12pub enum Constraint {
13    /// No constraints
14    None,
15    /// Congestion controller fast retransmission
16    RetransmissionOnly,
17    /// Congestion controller window size
18    CongestionLimited,
19    /// Anti-amplification limits
20    AmplificationLimited,
21}
22
23#[test]
24fn ordering_test() {
25    assert!(Constraint::None < Constraint::RetransmissionOnly);
26    assert!(Constraint::RetransmissionOnly < Constraint::CongestionLimited);
27    assert!(Constraint::CongestionLimited < Constraint::AmplificationLimited);
28}
29
30impl Constraint {
31    /// True if the transmission is constrained by anti-amplification limits
32    #[inline]
33    pub fn is_amplification_limited(self) -> bool {
34        matches!(self, Self::AmplificationLimited)
35    }
36
37    /// True if the transmission is constrained by congestion controller window size
38    #[inline]
39    pub fn is_congestion_limited(self) -> bool {
40        matches!(self, Self::CongestionLimited)
41    }
42
43    /// True if the transmission is constrained to only retransmissions due to the congestion
44    /// controller being in the fast retransmission state
45    #[inline]
46    pub fn is_retransmission_only(self) -> bool {
47        matches!(self, Self::RetransmissionOnly)
48    }
49
50    /// True if new data can be transmitted
51    #[inline]
52    pub fn can_transmit(self) -> bool {
53        self.is_none()
54    }
55
56    /// True if lost data can be retransmitted
57    #[inline]
58    pub fn can_retransmit(self) -> bool {
59        self.can_transmit() || self.is_retransmission_only()
60    }
61
62    /// True if there are no constraints
63    #[inline]
64    fn is_none(self) -> bool {
65        matches!(self, Self::None)
66    }
67}