use std::time::Duration;
#[derive(Debug, Clone, PartialEq)]
pub enum CongestionEvent {
PacketAcked {
packet_number: u64,
bytes: u64,
rtt: Duration,
},
PacketLost {
packet_number: u64,
bytes: u64,
},
ExplicitCongestionNotification,
}
impl CongestionEvent {
pub fn bytes(&self) -> Option<u64> {
match self {
CongestionEvent::PacketAcked { bytes, .. } => Some(*bytes),
CongestionEvent::PacketLost { bytes, .. } => Some(*bytes),
CongestionEvent::ExplicitCongestionNotification => None,
}
}
pub fn packet_number(&self) -> Option<u64> {
match self {
CongestionEvent::PacketAcked { packet_number, .. } => Some(*packet_number),
CongestionEvent::PacketLost { packet_number, .. } => Some(*packet_number),
CongestionEvent::ExplicitCongestionNotification => None,
}
}
pub fn rtt(&self) -> Option<Duration> {
match self {
CongestionEvent::PacketAcked { rtt, .. } => Some(*rtt),
_ => None,
}
}
pub fn is_positive(&self) -> bool {
matches!(self, CongestionEvent::PacketAcked { .. })
}
pub fn is_negative(&self) -> bool {
matches!(
self,
CongestionEvent::PacketLost { .. } | CongestionEvent::ExplicitCongestionNotification
)
}
}