channel padding: Use IntegerMilliseconds in netdir

This commit is contained in:
Ian Jackson 2022-06-16 18:03:30 +01:00
parent db71018021
commit 19c52ff8e4
2 changed files with 18 additions and 20 deletions

View File

@ -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) = (&params.nf_ito_low, &params.nf_ito_high);
let low = IntegerMilliseconds::<u32>::new(
low.get()
.try_into()
.map_err(|_| "low value out of range?!")?,
);
let high = IntegerMilliseconds::<u32>::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");

View File

@ -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<BoundedInt32<0, CHANNEL_PADDING_TIMEOUT_UPPER_BOUND>> = (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<BoundedInt32<0, CHANNEL_PADDING_TIMEOUT_UPPER_BOUND>> = (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<BoundedInt32<0, CHANNEL_PADDING_TIMEOUT_UPPER_BOUND>> = (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<BoundedInt32<0, CHANNEL_PADDING_TIMEOUT_UPPER_BOUND>> = (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)