From 8339558ba89e65e9994a74eaae66ef9da418fa84 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 11 Aug 2022 11:58:31 +0100 Subject: [PATCH] channel padding: Move initial config of ChannelPaddingInstructions Making ChannelPaddingInstructions::default() accurately reflect the initial state of the reactor's padding timer simplifies the code somewhat. (When padding is wanted, parameters are computed and inserted explicitly, so the only change is that if we start out dormant, we defer setting the timer parameters until necessary.) As per https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/657#note_2827249 --- crates/tor-chanmgr/src/mgr/map/padding_test.rs | 2 +- crates/tor-proto/src/channel/params.rs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/tor-chanmgr/src/mgr/map/padding_test.rs b/crates/tor-chanmgr/src/mgr/map/padding_test.rs index 591d28251..a23518f64 100644 --- a/crates/tor-chanmgr/src/mgr/map/padding_test.rs +++ b/crates/tor-chanmgr/src/mgr/map/padding_test.rs @@ -261,7 +261,7 @@ async fn padding_control_through_layers() { let mut c = case(PL::default(), Dormancy::Dormant, ChannelUsage::UserTraffic).await; c.expect_1(Expected { enabled: None, - timing: Some(DEF_MS), + timing: None, nego: Some(STOP_MSG), }); diff --git a/crates/tor-proto/src/channel/params.rs b/crates/tor-proto/src/channel/params.rs index 5917d40f4..1000a29b4 100644 --- a/crates/tor-proto/src/channel/params.rs +++ b/crates/tor-proto/src/channel/params.rs @@ -106,11 +106,6 @@ macro_rules! define_channels_insns_and_automatic_impls { { $( pub fn initial_update(&self) -> Option { let mut supposed = ChannelPaddingInstructions::default(); - // The initial configuration of the padding timer used by the reactor has no - // parameters, so does not send padding. We need to mirror that here, so that we - // give the reactor an initial set of timing parameters. - supposed.padding_parameters = padding::Parameters::disabled(); - supposed.start_update() $( .$field(self.$field.clone()) @@ -172,7 +167,11 @@ define_channels_insns_and_automatic_impls! { /// we still pass it because the usual case is that padding is enabled/disabled /// rather than the parameters changing, /// so the padding timer always keeps parameters, even when disabled. - #[field educe(Default(expression = "padding::Parameters::default_padding()"))] + // + // The initial configuration of the padding timer used by the reactor has no + // parameters, so does not send padding. We need to mirror that here, so that we + // give the reactor an initial set of timing parameters. + #[field educe(Default(expression = "padding::Parameters::disabled()"))] padding_parameters: padding::Parameters, /// Channel padding negotiation cell