diff --git a/crates/tor-chanmgr/src/mgr/map.rs b/crates/tor-chanmgr/src/mgr/map.rs index 1ed732047..af850ba71 100644 --- a/crates/tor-chanmgr/src/mgr/map.rs +++ b/crates/tor-chanmgr/src/mgr/map.rs @@ -9,10 +9,10 @@ use std::collections::{hash_map, HashMap}; use std::result::Result as StdResult; use std::sync::Arc; use tor_error::{internal, into_internal}; -use tor_netdir::NetDir; +use tor_netdir::{params::CHANNEL_PADDING_TIMEOUT_UPPER_BOUND, NetDir}; use tor_proto::channel::padding::ParametersBuilder as PaddingParametersBuilder; use tor_proto::ChannelsConfig; -use tor_units::IntegerMilliseconds; +use tor_units::BoundedInt32; use tracing::info; /// A map from channel id to channel state, plus necessary auxiliary state @@ -345,16 +345,14 @@ fn update_padding_parameters_from_netdir( // TODO and with reduced padding, send CELL_PADDING_NEGOTIATE let (low, high) = (¶ms.nf_ito_low, ¶ms.nf_ito_high); - let low = IntegerMilliseconds::::new( - low.get() - .try_into() - .map_err(|_| "low value out of range?!")?, - ); - let high = IntegerMilliseconds::::new( - high.get() - .try_into() - .map_err(|_| "high value out of range?!")?, - ); + let conv_timing_param = + |bounded: BoundedInt32<0, CHANNEL_PADDING_TIMEOUT_UPPER_BOUND>| bounded.get().try_into(); + let low = low + .try_map(conv_timing_param) + .map_err(|_| "low value out of range?!")?; + let high = high + .try_map(conv_timing_param) + .map_err(|_| "high value out of range?!")?; if high > low { return Err("high > low"); diff --git a/crates/tor-netdir/src/params.rs b/crates/tor-netdir/src/params.rs index 82f36253d..54da07099 100644 --- a/crates/tor-netdir/src/params.rs +++ b/crates/tor-netdir/src/params.rs @@ -276,16 +276,16 @@ pub struct NetParameters { from "min_paths_for_circs_pct", /// Channel padding, low end of random padding interval, milliseconds - pub nf_ito_low: BoundedInt32<0, CHANNEL_PADDING_TIMEOUT_UPPER_BOUND> = (1500) + pub nf_ito_low: IntegerMilliseconds> = (1500) from "nf_ito_low", /// Channel padding, high end of random padding interval, milliseconds - pub nf_ito_high: BoundedInt32<0, CHANNEL_PADDING_TIMEOUT_UPPER_BOUND> = (9500) + pub nf_ito_high: IntegerMilliseconds> = (9500) from "nf_ito_high", /// Channel padding, low end of random padding interval (reduced padding) milliseconds - pub nf_ito_low_reduced: BoundedInt32<0, CHANNEL_PADDING_TIMEOUT_UPPER_BOUND> = (9000) + pub nf_ito_low_reduced: IntegerMilliseconds> = (9000) from "nf_ito_low_reduced", /// Channel padding, high end of random padding interval (reduced padding) , milliseconds - pub nf_ito_high_reduced: BoundedInt32<0, CHANNEL_PADDING_TIMEOUT_UPPER_BOUND> = (14000) + pub nf_ito_high_reduced: IntegerMilliseconds> = (14000) from "nf_ito_high_reduced", /// The minimum sendme version to accept. @@ -526,10 +526,10 @@ mod test { assert_eq!(p.cbt_min_circs_for_estimate.get(), 5); assert_eq!(p.cbt_timeout_quantile.as_percent().get(), 61); assert_eq!(p.cbt_abandon_quantile.as_percent().get(), 15); - assert_eq!(p.nf_ito_low.get(), 1_000); - assert_eq!(p.nf_ito_high.get(), 20_000); - assert_eq!(p.nf_ito_low_reduced.get(), 3_000); - assert_eq!(p.nf_ito_high_reduced.get(), 40_000); + assert_eq!(p.nf_ito_low.as_millis().get(), 1_000); + assert_eq!(p.nf_ito_high.as_millis().get(), 20_000); + assert_eq!(p.nf_ito_low_reduced.as_millis().get(), 3_000); + assert_eq!(p.nf_ito_high_reduced.as_millis().get(), 40_000); assert_eq!( Duration::try_from(p.unused_client_circ_timeout_while_learning_cbt).unwrap(), Duration::from_secs(1900)