diff --git a/Cargo.toml b/Cargo.toml index 4c21ac2..ce0854d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,4 @@ [workspace] resolver = "2" -members = ["stun-agent", - "stun-agent", - "stun-rs", - "stun-vectors", -] +members = ["stun-agent", "stun-rs", "stun-vectors"] diff --git a/stun-agent/src/events.rs b/stun-agent/src/events.rs index 3b53505..aac2480 100644 --- a/stun-agent/src/events.rs +++ b/stun-agent/src/events.rs @@ -44,7 +44,7 @@ pub struct TransactionEventHandler { } impl TransactionEventHandler { - pub fn init(&mut self) -> TransactionEvents { + pub fn init(&mut self) -> TransactionEvents<'_> { TransactionEvents { handler: self, events: Vec::new(), diff --git a/stun-agent/src/rtt.rs b/stun-agent/src/rtt.rs index f300021..d9f6cb0 100644 --- a/stun-agent/src/rtt.rs +++ b/stun-agent/src/rtt.rs @@ -8,17 +8,6 @@ const BETA: f32 = 0.25; // (1/4) pub const DEFAULT_GRANULARITY: Duration = Duration::from_millis(1); -// TODO: Remove this hack once duration_abs_diff -// [#117618](https://github.com/rust-lang/rust/issues/117618) -// was not nightly -fn abs_diff(a: Duration, b: Duration) -> Duration { - if a > b { - a - b - } else { - b - a - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct RttCalcuator { rto: Duration, @@ -70,7 +59,7 @@ impl RttCalcuator { ); } else { // Subsequent RTT measurements - self.rttvar = self.rttvar.mul_f32(1.0 - BETA) + abs_diff(self.srtt, r).mul_f32(BETA); + self.rttvar = self.rttvar.mul_f32(1.0 - BETA) + self.srtt.abs_diff(r).mul_f32(BETA); self.srtt = self.srtt.mul_f32(1.0 - ALPHA) + r.mul_f32(ALPHA); self.rto = self.srtt + cmp::max(self.granularity, self.rttvar.mul_f32(K as f32)); trace!( diff --git a/stun-rs/Cargo.toml b/stun-rs/Cargo.toml index 6de5537..e95edbb 100644 --- a/stun-rs/Cargo.toml +++ b/stun-rs/Cargo.toml @@ -12,8 +12,16 @@ license = "MIT/Apache-2.0" categories = ["network-programming"] edition = "2021" -[dev-dependencies] -stun-vectors = { path = "../stun-vectors" } +[package.metadata.docs.rs] +all-features = true + +[features] +default = [] +discovery = [] +experiments = [] +ice = [] +mobility = [] +turn = [] [dependencies] base64 = "0.22.0" @@ -33,13 +41,5 @@ precis-profiles = "0.1.12" quoted-string-parser = "0.1.0" rand = "0.9.0" -[features] -default = [] -experiments = [] -ice = [] -turn = [] -mobility = [] -discovery = [] - -[package.metadata.docs.rs] -all-features = true +[dev-dependencies] +stun-vectors = { path = "../stun-vectors" } diff --git a/stun-rs/src/attributes/turn/requested_transport.rs b/stun-rs/src/attributes/turn/requested_transport.rs index 0b12f71..e494907 100644 --- a/stun-rs/src/attributes/turn/requested_transport.rs +++ b/stun-rs/src/attributes/turn/requested_transport.rs @@ -30,11 +30,11 @@ impl RequestedTrasport { /// Creates a new attribute. /// # Arguments: /// - `protocol`- The protocol specifies the desired protocol. The code points - /// used in this field are taken from those allowed in the Protocol - /// field in the IPv4 header and the Next Header field in the IPv6 - /// header [PROTOCOL-NUMBERS](https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml). - /// This specification only allows the use of code point 17 - /// (User Datagram Protocol). + /// used in this field are taken from those allowed in the Protocol + /// field in the IPv4 header and the Next Header field in the IPv6 + /// header [PROTOCOL-NUMBERS](https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml). + /// This specification only allows the use of code point 17 + /// (User Datagram Protocol). pub fn new(protocol: ProtocolNumber) -> Self { Self(protocol) } diff --git a/stun-rs/src/lib.rs b/stun-rs/src/lib.rs index 82403b0..dd4e6eb 100644 --- a/stun-rs/src/lib.rs +++ b/stun-rs/src/lib.rs @@ -124,20 +124,20 @@ //! # Common features //! This crate defines next feature flags that can be enabled: //! * **turn**: Extends support for parsing attributes defined in -//! [`RFC8656`](https://datatracker.ietf.org/doc/html/rfc8656). -//! Traversal Using Relays around NAT (TURN). +//! [`RFC8656`](https://datatracker.ietf.org/doc/html/rfc8656). +//! Traversal Using Relays around NAT (TURN). //! * **ice**: Extends support for parsing attributes defined in -//! [`RFC8445`](https://datatracker.ietf.org/doc/html/rfc8445). -//! Interactive Connectivity Establishment (ICE). +//! [`RFC8445`](https://datatracker.ietf.org/doc/html/rfc8445). +//! Interactive Connectivity Establishment (ICE). //! * **mobility**: Extends support for parsing attributes defined in -//! [`RFC8016`](https://datatracker.ietf.org/doc/html/rfc8016). -//! Mobility with Traversal Using Relays around NAT (TURN). +//! [`RFC8016`](https://datatracker.ietf.org/doc/html/rfc8016). +//! Mobility with Traversal Using Relays around NAT (TURN). //! * **experiments**: This flag can be set to adjust some behavior -//! of the library, such as default padding. When testing protocols, -//! we can use this flag to force the library to keep the data -//! associated with [Unknown](crate::attributes::Unknown) attributes. -//! By default, [Unknown](crate::attributes::Unknown) attributes -//! store no data to save memory consumption. +//! of the library, such as default padding. When testing protocols, +//! we can use this flag to force the library to keep the data +//! associated with [Unknown](crate::attributes::Unknown) attributes. +//! By default, [Unknown](crate::attributes::Unknown) attributes +//! store no data to save memory consumption. #![deny(missing_docs)] diff --git a/stun-rs/src/types.rs b/stun-rs/src/types.rs index c8b8614..b512e70 100644 --- a/stun-rs/src/types.rs +++ b/stun-rs/src/types.rs @@ -228,9 +228,9 @@ impl HMACKey { /// - `username` - The user name /// - `realm` - The realm. /// - `algorithm`- Optional value for the algorithm used to generate the key. If - /// algorithm is None, [`AlgorithmId::MD5`](crate::AlgorithmId::MD5) will be used. - /// The resulting key length is 16 bytes when `MD5` is used, or 32 bytes if - /// SHA-256 algorithm is used. + /// algorithm is None, [`AlgorithmId::MD5`](crate::AlgorithmId::MD5) will be used. + /// The resulting key length is 16 bytes when `MD5` is used, or 32 bytes if + /// SHA-256 algorithm is used. /// # Returns /// The new [`HMACKey`] used for long term credential mechanism, or a `StunError` if /// `username`, `realm` or `password` can not be processed using the opaque string profile.