From 7ed983800d190c042beba2e90955e37a718c5685 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 2 Aug 2022 12:56:52 +0100 Subject: [PATCH] channel padding: Rename low_ms and high_ms These have the unit in the type. Putting that in the field name too is otiose. --- crates/tor-cell/src/chancell/msg.rs | 6 ++++- crates/tor-chanmgr/src/mgr/map.rs | 10 +++---- .../tor-chanmgr/src/mgr/map/padding_test.rs | 8 +++--- crates/tor-proto/src/channel/padding.rs | 26 +++++++++---------- 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/crates/tor-cell/src/chancell/msg.rs b/crates/tor-cell/src/chancell/msg.rs index 33cfc9c83..ab097c263 100644 --- a/crates/tor-cell/src/chancell/msg.rs +++ b/crates/tor-cell/src/chancell/msg.rs @@ -867,7 +867,11 @@ impl PaddingNegotiate { /// For testing only #[cfg(feature = "testing")] pub fn from_raw(command: PaddingNegotiateCmd, ito_low_ms: u16, ito_high_ms: u16) -> Self { - PaddingNegotiate { command, ito_low_ms, ito_high_ms, } + PaddingNegotiate { + command, + ito_low_ms, + ito_high_ms, + } } } impl Default for PaddingNegotiate { diff --git a/crates/tor-chanmgr/src/mgr/map.rs b/crates/tor-chanmgr/src/mgr/map.rs index 6335ec680..a25761e8d 100644 --- a/crates/tor-chanmgr/src/mgr/map.rs +++ b/crates/tor-chanmgr/src/mgr/map.rs @@ -514,8 +514,8 @@ fn padding_parameters( if low > high { return Err("low > high"); } - p.low_ms(low); - p.high_ms(high); + p.low(low); + p.high(high); Ok::<_, &'static str>(()) })() .unwrap_or_else(|e| { @@ -739,7 +739,7 @@ mod test { .start_update() .padding_parameters( PaddingParametersBuilder::default() - .low_ms(1234.into()) + .low(1234.into()) .build() .unwrap(), ) @@ -767,8 +767,8 @@ mod test { // evade field visibility by (ab)using Debug impl "ChannelsParamsUpdates { padding_enable: None, \ padding_parameters: Some(Parameters { \ - low_ms: IntegerMilliseconds { value: 1500 }, \ - high_ms: IntegerMilliseconds { value: 9500 } }), \ + low: IntegerMilliseconds { value: 1500 }, \ + high: IntegerMilliseconds { value: 9500 } }), \ padding_negotiate: None }" ); }); diff --git a/crates/tor-chanmgr/src/mgr/map/padding_test.rs b/crates/tor-chanmgr/src/mgr/map/padding_test.rs index 0bbe60715..0b7067e84 100644 --- a/crates/tor-chanmgr/src/mgr/map/padding_test.rs +++ b/crates/tor-chanmgr/src/mgr/map/padding_test.rs @@ -69,8 +69,8 @@ fn padding_parameters_calculation() { ); let got = padding_parameters(pconfig, netdir).unwrap(); let exp = PaddingParameters::builder() - .low_ms(exp[0].into()) - .high_ms(exp[1].into()) + .low(exp[0].into()) + .high(exp[1].into()) .build() .unwrap(); assert_eq!(got, exp); @@ -202,8 +202,8 @@ impl CaseContext { nego.map(|(cmd, [low, high])| PaddingNegotiate::from_raw(cmd, low as _, high as _)); let timing = timing.map(|[low, high]| { PaddingParameters::builder() - .low_ms(low.into()) - .high_ms(high.into()) + .low(low.into()) + .high(high.into()) .build() .unwrap() }); diff --git a/crates/tor-proto/src/channel/padding.rs b/crates/tor-proto/src/channel/padding.rs index b28366756..3866c81e0 100644 --- a/crates/tor-proto/src/channel/padding.rs +++ b/crates/tor-proto/src/channel/padding.rs @@ -126,10 +126,10 @@ pub(crate) struct Timer { pub struct Parameters { /// Low end of the distribution of `X` #[builder(default = "1500.into()")] - pub(crate) low_ms: IntegerMilliseconds, + pub(crate) low: IntegerMilliseconds, /// High end of the distribution of `X` (inclusive) #[builder(default = "9500.into()")] - pub(crate) high_ms: IntegerMilliseconds, + pub(crate) high: IntegerMilliseconds, } impl_standard_builder! { Parameters: !Deserialize + !Builder } @@ -140,8 +140,8 @@ impl Parameters { /// As per `torspec/padding-spec.txt` section 2.6 pub fn default_reduced() -> Self { Parameters { - low_ms: IntegerMilliseconds::new(9000), - high_ms: IntegerMilliseconds::new(14000), + low: IntegerMilliseconds::new(9000), + high: IntegerMilliseconds::new(14000), } } @@ -157,7 +157,7 @@ impl Parameters { .try_into() .map_err(into_internal!("padding negotiate out of range")) }; - Ok(PaddingNegotiate::start(get(self.low_ms)?, get(self.high_ms)?)) + Ok(PaddingNegotiate::start(get(self.low)?, get(self.high)?)) } /// Make a Parameters sentinel value, with both fields set to zero @@ -165,8 +165,8 @@ impl Parameters { /// The specification says to treat this as disabled, if found in the consensus. pub fn all_zeroes() -> Self { Parameters { - low_ms: 0.into(), - high_ms: 0.into(), + low: 0.into(), + high: 0.into(), } } } @@ -389,8 +389,8 @@ impl Parameters { fn prepare(self) -> PreparedParameters { PreparedParameters { x_distribution_ms: rand::distributions::Uniform::new_inclusive( - self.low_ms.as_millis(), - self.high_ms.as_millis(), + self.low.as_millis(), + self.high.as_millis(), ), } } @@ -448,8 +448,8 @@ mod test { let runtime = tor_rtmock::MockSleepRuntime::new(runtime); let parameters = Parameters { - low_ms: 1000.into(), - high_ms: 1000.into(), + low: 1000.into(), + high: 1000.into(), }; let () = runtime.block_on(async { @@ -617,8 +617,8 @@ mod test { let mut obs = [0_u32; n]; let params = Parameters { - low_ms: min.into(), - high_ms: (max - 1).into(), // convert exclusive to inclusive + low: min.into(), + high: (max - 1).into(), // convert exclusive to inclusive } .prepare();