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
This commit is contained in:
Ian Jackson 2022-08-11 11:58:31 +01:00
parent 8a484a26e6
commit 8339558ba8
2 changed files with 6 additions and 7 deletions

View File

@ -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),
});

View File

@ -106,11 +106,6 @@ macro_rules! define_channels_insns_and_automatic_impls { { $(
pub fn initial_update(&self) -> Option<ChannelPaddingInstructionsUpdates> {
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