Skip to content

Commit

Permalink
private
Browse files Browse the repository at this point in the history
  • Loading branch information
toidiu committed Jun 11, 2024
1 parent 50ddba4 commit 384a116
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
25 changes: 14 additions & 11 deletions quic/s2n-quic-core/src/path/mtu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,26 +305,29 @@ impl Config {
pub fn is_valid(&self) -> bool {
self.base_mtu.0 <= self.initial_mtu.0 && self.initial_mtu.0 <= self.max_mtu.0
}
}

// A checked MTU Config created after validating the values from the
// IO provider against the values from mtu provider.
#[derive(Copy, Clone, Debug, Default)]
pub struct CheckedConfig(Config);

impl CheckedConfig {
// Check that the Application provided MTU values are valid for this endpoint.
pub fn checked(self, info: &mtu::ConnectionInfo) -> Result<CheckedConfig, MtuError> {
ensure!(self.is_valid(), Err(MtuError::Validation));
pub fn new_checked(
config: Config,
info: &mtu::ConnectionInfo,
) -> Result<CheckedConfig, MtuError> {
ensure!(config.is_valid(), Err(MtuError::Validation));
// ensure that the max_mtu is <= the value configured on the IO provider.
ensure!(
u16::from(self.max_mtu) <= u16::from(info.endpoint_config.max_mtu),
u16::from(config.max_mtu) <= u16::from(info.endpoint_config.max_mtu),
Err(MtuError::Validation)
);

Ok(CheckedConfig(self))
Ok(CheckedConfig(config))
}
}

// A checked MTU Config created after validating the values from the
// IO provider against the values from mtu provider.
#[derive(Copy, Clone, Debug, Default)]
pub struct CheckedConfig(Config);

impl CheckedConfig {
pub fn initial_mtu(&self) -> InitialMtu {
self.0.initial_mtu
}
Expand Down
4 changes: 2 additions & 2 deletions quic/s2n-quic-transport/src/endpoint/initial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use s2n_quic_core::{
event::{self, supervisor, ConnectionPublisher, IntoEvent, Subscriber as _},
inet::{datagram, DatagramInfo},
packet::initial::ProtectedInitial,
path::{mtu, mtu::Configurator as _, Handle as _},
path::{mtu, mtu::Configurator as _, CheckedConfig, Handle as _},
stateless_reset::token::Generator as _,
transport::{self, parameters::ServerTransportParameters},
};
Expand Down Expand Up @@ -175,7 +175,7 @@ impl<Config: endpoint::Config> endpoint::Endpoint<Config> {
.context()
.mtu
.on_connection(&info)
.and_then(|config| config.checked(&info))
.and_then(|config| CheckedConfig::new_checked(config, &info))
.map_err(|_| {
// TODO emit datagram dropped event
connection::Error::validation("failed to instantiate a valid MTU provider")
Expand Down
6 changes: 3 additions & 3 deletions quic/s2n-quic-transport/src/endpoint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use s2n_quic_core::{
io::{rx, tx},
packet::{initial::ProtectedInitial, interceptor::Interceptor, ProtectedPacket},
path,
path::{mtu, mtu::Configurator as _, Handle as _},
path::{mtu, mtu::Configurator as _, CheckedConfig, Handle as _},
random::Generator as _,
stateless_reset::token::{Generator as _, LEN as StatelessResetTokenLen},
time::{Clock, Timestamp},
Expand Down Expand Up @@ -560,7 +560,7 @@ impl<Cfg: Config> Endpoint<Cfg> {
let mtu_config = endpoint_context
.mtu
.on_connection(&info)
.and_then(|config| config.checked(&info));
.and_then(|config| CheckedConfig::new_checked(config, &info));
let mtu_config = match mtu_config {
Ok(config) => config,
Err(_) => {
Expand Down Expand Up @@ -1069,7 +1069,7 @@ impl<Cfg: Config> Endpoint<Cfg> {
let mtu_config = endpoint_context
.mtu
.on_connection(&info)
.and_then(|config| config.checked(&info))
.and_then(|config| CheckedConfig::new_checked(config, &info))
.map_err(|_err| {
// TODO emit datagram dropped event
connection::Error::validation("failed to instantiate a valid MTU provider")
Expand Down

0 comments on commit 384a116

Please sign in to comment.