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

chore(transport): export ecn module #2384

Merged
merged 1 commit into from
Jan 27, 2025
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
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ description = "Neqo, the Mozilla implementation of QUIC in Rust."
keywords = ["quic", "http3", "neqo", "mozilla", "ietf", "firefox"]
categories = ["network-programming", "web-programming"]
readme = "README.md"
version = "0.12.1"
version = "0.12.2"
larseggert marked this conversation as resolved.
Show resolved Hide resolved
# Keep in sync with `.rustfmt.toml` `edition`.
edition = "2021"
license = "MIT OR Apache-2.0"
Expand Down
22 changes: 12 additions & 10 deletions neqo-transport/src/ecn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
};

/// The number of packets to use for testing a path for ECN capability.
pub const TEST_COUNT: usize = 10;
pub(crate) const TEST_COUNT: usize = 10;

/// The number of packets to use for testing a path for ECN capability when exchanging
/// Initials during the handshake. This is a lower number than [`TEST_COUNT`] to avoid
Expand Down Expand Up @@ -97,12 +97,14 @@ impl DerefMut for Count {
}

impl Count {
#[must_use]
pub const fn new(not_ect: u64, ect0: u64, ect1: u64, ce: u64) -> Self {
// Yes, the enum array order is different from the argument order.
Self(EnumMap::from_array([not_ect, ect1, ect0, ce]))
}

/// Whether any of the ECN counts are non-zero.
#[must_use]
pub fn is_some(&self) -> bool {
self[IpTosEcn::Ect0] > 0 || self[IpTosEcn::Ect1] > 0 || self[IpTosEcn::Ce] > 0
}
Expand Down Expand Up @@ -158,7 +160,7 @@ pub enum ValidationOutcome {
}

#[derive(Debug, Default)]
pub struct Info {
pub(crate) struct Info {
/// The current state of ECN validation on this path.
state: ValidationState,

Expand All @@ -171,20 +173,20 @@ pub struct Info {

impl Info {
/// Set the baseline (= the ECN counts from the last ACK Frame).
pub fn set_baseline(&mut self, baseline: Count) {
pub(crate) fn set_baseline(&mut self, baseline: Count) {
self.baseline = baseline;
}

/// Expose the current baseline.
pub const fn baseline(&self) -> Count {
pub(crate) const fn baseline(&self) -> Count {
self.baseline
}

/// Count the number of packets sent out on this path during ECN validation.
/// Exit ECN validation if the number of packets sent exceeds `TEST_COUNT`.
/// We do not implement the part of the RFC that says to exit ECN validation if the time since
/// the start of ECN validation exceeds 3 * PTO, since this seems to happen much too quickly.
pub fn on_packet_sent(&mut self, stats: &mut Stats) {
pub(crate) fn on_packet_sent(&mut self, stats: &mut Stats) {
if let ValidationState::Testing { probes_sent, .. } = &mut self.state {
*probes_sent += 1;
qdebug!("ECN probing: sent {probes_sent} probes");
Expand All @@ -196,14 +198,14 @@ impl Info {
}

/// Disable ECN.
pub fn disable_ecn(&mut self, stats: &mut Stats, reason: ValidationError) {
pub(crate) fn disable_ecn(&mut self, stats: &mut Stats, reason: ValidationError) {
self.state.set(ValidationState::Failed(reason), stats);
}

/// Process ECN counts from an ACK frame.
///
/// Returns whether ECN counts contain new valid ECN CE marks.
pub fn on_packets_acked(
pub(crate) fn on_packets_acked(
&mut self,
acked_packets: &[SentPacket],
ack_ecn: Option<Count>,
Expand All @@ -217,7 +219,7 @@ impl Info {
&& (self.baseline - prev_baseline)[IpTosEcn::Ce] > 0
}

pub fn on_packets_lost(&mut self, lost_packets: &[SentPacket], stats: &mut Stats) {
pub(crate) fn on_packets_lost(&mut self, lost_packets: &[SentPacket], stats: &mut Stats) {
if let ValidationState::Testing {
probes_sent,
initial_probes_lost: probes_lost,
Expand All @@ -239,7 +241,7 @@ impl Info {
}

/// After the ECN validation test has ended, check if the path is ECN capable.
pub fn validate_ack_ecn_and_update(
pub(crate) fn validate_ack_ecn_and_update(
&mut self,
acked_packets: &[SentPacket],
ack_ecn: Option<Count>,
Expand Down Expand Up @@ -316,7 +318,7 @@ impl Info {
}

/// The ECN mark to use for packets sent on this path.
pub const fn ecn_mark(&self) -> IpTosEcn {
pub(crate) const fn ecn_mark(&self) -> IpTosEcn {
match self.state {
ValidationState::Testing { .. } | ValidationState::Capable => IpTosEcn::Ect0,
ValidationState::Failed(_) | ValidationState::Unknown => IpTosEcn::NotEct,
Expand Down
2 changes: 1 addition & 1 deletion neqo-transport/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod cc;
mod cid;
mod connection;
mod crypto;
mod ecn;
pub mod ecn;
mod events;
mod fc;
#[cfg(fuzzing)]
Expand Down
16 changes: 16 additions & 0 deletions neqo-transport/tests/stats.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use neqo_transport::ecn;

#[test]
fn crate_exports_ecn_types() {
let stats = neqo_transport::Stats::default();

let _ = stats.ecn_path_validation[ecn::ValidationOutcome::Capable];
let _ = stats.ecn_path_validation
[ecn::ValidationOutcome::NotCapable(ecn::ValidationError::BlackHole)];
}
Loading