diff --git a/Cargo.lock b/Cargo.lock index be7b2cd2c..9d84e95a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3869,6 +3869,7 @@ dependencies = [ "bytes", "cipher", "coarsetime", + "derive_builder_fork_arti", "digest 0.10.3", "educe", "futures", diff --git a/crates/tor-proto/Cargo.toml b/crates/tor-proto/Cargo.toml index 360bfa8a6..6cc592446 100644 --- a/crates/tor-proto/Cargo.toml +++ b/crates/tor-proto/Cargo.toml @@ -25,6 +25,7 @@ asynchronous-codec = "0.6.0" bytes = "1" cipher = "0.4.1" coarsetime = "0.1.20" +derive_builder = { version = "0.11.2", package = "derive_builder_fork_arti" } digest = "0.10.0" educe = "0.4.6" futures = "0.3.14" diff --git a/crates/tor-proto/src/channel.rs b/crates/tor-proto/src/channel.rs index 7e8e16953..fd1590cb9 100644 --- a/crates/tor-proto/src/channel.rs +++ b/crates/tor-proto/src/channel.rs @@ -59,7 +59,7 @@ pub const CHANNEL_BUFFER_SIZE: usize = 128; mod circmap; mod codec; mod handshake; -mod padding; +pub mod padding; mod reactor; mod unique_id; diff --git a/crates/tor-proto/src/channel/padding.rs b/crates/tor-proto/src/channel/padding.rs index afc511f87..0e5f16a67 100644 --- a/crates/tor-proto/src/channel/padding.rs +++ b/crates/tor-proto/src/channel/padding.rs @@ -6,6 +6,7 @@ use std::pin::Pin; // TODO, coarsetime maybe? But see arti#496 and also we want to use the mockable SleepProvider use std::time::{Duration, Instant}; +use derive_builder::Builder; use educe::Educe; use futures::future::{self, FusedFuture}; use futures::FutureExt; @@ -91,14 +92,24 @@ pub(crate) struct Timer { } /// Timing parameters, as described in `padding-spec.txt` -#[derive(Debug, Copy, Clone, Eq, PartialEq)] -pub(crate) struct Parameters { +#[derive(Debug, Copy, Clone, Eq, PartialEq, Builder)] +pub struct Parameters { /// Low end of the distribution of `X` + #[builder(default = "1500")] pub(crate) low_ms: u32, /// High end of the distribution of `X` (inclusive) + #[builder(default = "9500")] pub(crate) high_ms: u32, } +impl Default for Parameters { + fn default() -> Self { + ParametersBuilder::default() + .build() + .expect("could not build default channel padding Parameters") + } +} + /// Timing parameters, "compiled" into a form which can be sampled more efficiently /// /// According to the docs for [`rand::Rng::gen_range`],