Skip to content

Commit

Permalink
feat(s2n-quic): expose an mtu provider
Browse files Browse the repository at this point in the history
  • Loading branch information
toidiu committed Jun 12, 2024
1 parent c22cdb3 commit 9bb6ee0
Show file tree
Hide file tree
Showing 27 changed files with 712 additions and 163 deletions.
22 changes: 22 additions & 0 deletions quic/s2n-quic-core/src/connection/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ pub enum Error {
source: &'static panic::Location<'static>,
},

/// The connection was closed due to a validation failure
#[non_exhaustive]
Validation {
reason: &'static str,
source: &'static panic::Location<'static>,
},

/// The connection was closed due to an unspecified reason
#[non_exhaustive]
Unspecified {
Expand Down Expand Up @@ -149,6 +156,10 @@ impl fmt::Display for Error {
Self::EndpointClosing { .. } => {
write!(f, "The connection attempt was rejected because the endpoint is closing")
}
Self::Validation {reason, ..} => write!(
f,
"The connection was closed due to: {reason}"
),
Self::Unspecified { .. } => {
write!(f, "The connection was closed due to an unspecified reason")
}
Expand Down Expand Up @@ -235,6 +246,7 @@ impl Error {
Error::MaxHandshakeDurationExceeded { source, .. } => source,
Error::ImmediateClose { source, .. } => source,
Error::EndpointClosing { source } => source,
Error::Validation { source, .. } => source,
Error::Unspecified { source } => source,
}
}
Expand Down Expand Up @@ -339,6 +351,14 @@ impl Error {
Error::EndpointClosing { source }
}

#[inline]
#[track_caller]
#[doc(hidden)]
pub fn validation(reason: &'static str) -> Error {
let source = panic::Location::caller();
Error::Validation { source, reason }
}

#[inline]
#[track_caller]
#[doc(hidden)]
Expand Down Expand Up @@ -440,6 +460,7 @@ pub fn as_frame<'a, F: connection::close::Formatter>(
Error::MaxHandshakeDurationExceeded { .. } => None,
Error::ImmediateClose { .. } => None,
Error::EndpointClosing { .. } => None,
Error::Validation { .. } => None,
Error::Unspecified { .. } => {
let error =
transport::Error::INTERNAL_ERROR.with_reason("an unspecified error occurred");
Expand Down Expand Up @@ -518,6 +539,7 @@ impl From<Error> for std::io::ErrorKind {
Error::MaxHandshakeDurationExceeded { .. } => ErrorKind::TimedOut,
Error::ImmediateClose { .. } => ErrorKind::Other,
Error::EndpointClosing { .. } => ErrorKind::Other,
Error::Validation { .. } => ErrorKind::Other,
Error::Unspecified { .. } => ErrorKind::Other,
}
}
Expand Down
54 changes: 54 additions & 0 deletions quic/s2n-quic-core/src/event/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ pub mod api {
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct MtuConfig {
pub initial_mtu: u16,
pub base_mtu: u16,
pub max_mtu: u16,
}
#[derive(Clone, Debug)]
#[non_exhaustive]
#[doc = " A bandwidth delivery rate estimate with associated metadata"]
pub struct RateSample {
#[doc = " The length of the sampling interval"]
Expand Down Expand Up @@ -326,6 +333,12 @@ pub mod api {
#[non_exhaustive]
#[doc = " The peer initiated a connection migration without supplying enough connection IDs to use."]
InsufficientConnectionIds {},
#[non_exhaustive]
#[doc = " Application provided invalid MTU configuration."]
MtuValidation {
#[doc = " MTU configuration for the endpoint"]
endpoint_mtu_config: MtuConfig,
},
}
#[derive(Clone, Debug)]
#[non_exhaustive]
Expand Down Expand Up @@ -1650,6 +1663,16 @@ pub mod api {
}
}
}
impl<'a> IntoEvent<builder::MtuConfig> for &'a crate::path::mtu::Config {
#[inline]
fn into_event(self) -> builder::MtuConfig {
builder::MtuConfig {
initial_mtu: self.initial_mtu().into(),
base_mtu: self.base_mtu().into(),
max_mtu: self.max_mtu().into(),
}
}
}
impl CipherSuite {
#[inline]
pub fn as_str(&self) -> &'static str {
Expand Down Expand Up @@ -2654,6 +2677,27 @@ pub mod builder {
}
}
#[derive(Clone, Debug)]
pub struct MtuConfig {
pub initial_mtu: u16,
pub base_mtu: u16,
pub max_mtu: u16,
}
impl IntoEvent<api::MtuConfig> for MtuConfig {
#[inline]
fn into_event(self) -> api::MtuConfig {
let MtuConfig {
initial_mtu,
base_mtu,
max_mtu,
} = self;
api::MtuConfig {
initial_mtu: initial_mtu.into_event(),
base_mtu: base_mtu.into_event(),
max_mtu: max_mtu.into_event(),
}
}
}
#[derive(Clone, Debug)]
#[doc = " A bandwidth delivery rate estimate with associated metadata"]
pub struct RateSample {
#[doc = " The length of the sampling interval"]
Expand Down Expand Up @@ -3081,6 +3125,11 @@ pub mod builder {
PathLimitExceeded,
#[doc = " The peer initiated a connection migration without supplying enough connection IDs to use."]
InsufficientConnectionIds,
#[doc = " Application provided invalid MTU configuration."]
MtuValidation {
#[doc = " MTU configuration for the endpoint"]
endpoint_mtu_config: MtuConfig,
},
}
impl IntoEvent<api::DatagramDropReason> for DatagramDropReason {
#[inline]
Expand All @@ -3099,6 +3148,11 @@ pub mod builder {
Self::RejectedConnectionMigration => RejectedConnectionMigration {},
Self::PathLimitExceeded => PathLimitExceeded {},
Self::InsufficientConnectionIds => InsufficientConnectionIds {},
Self::MtuValidation {
endpoint_mtu_config,
} => MtuValidation {
endpoint_mtu_config: endpoint_mtu_config.into_event(),
},
}
}
}
Expand Down
Loading

0 comments on commit 9bb6ee0

Please sign in to comment.