Rename ChannelsParams types to ChannelPaddingInstructions

As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/657#note_2826167

This makes some lines too long; I will run rustfmt in a separate
commit for clarity.
This commit is contained in:
Ian Jackson 2022-08-09 10:49:46 +01:00
parent d1a709f46d
commit 94dd3361e2
8 changed files with 63 additions and 63 deletions

View File

@ -10,7 +10,7 @@ use std::time::Duration;
use tor_error::{bad_api_usage, internal};
use tor_linkspec::{HasAddrs, HasRelayIds, OwnedChanTarget};
use tor_llcrypto::pk;
use tor_proto::channel::params::ChannelsParamsUpdates;
use tor_proto::channel::params::ChannelPaddingInstructionsUpdates;
use tor_rtcompat::{tls::TlsConnector, Runtime, TcpProvider, TlsProvider};
use async_trait::async_trait;
@ -251,7 +251,7 @@ impl crate::mgr::AbstractChannel for tor_proto::channel::Channel {
fn duration_unused(&self) -> Option<Duration> {
self.duration_unused()
}
fn reparameterize(&mut self, updates: Arc<ChannelsParamsUpdates>) -> tor_proto::Result<()> {
fn reparameterize(&mut self, updates: Arc<ChannelPaddingInstructionsUpdates>) -> tor_proto::Result<()> {
self.reparameterize(updates)
}
fn engage_padding_activities(&self) {

View File

@ -13,7 +13,7 @@ use std::sync::Arc;
use std::time::Duration;
use tor_error::internal;
use tor_netdir::params::NetParameters;
use tor_proto::channel::params::ChannelsParamsUpdates;
use tor_proto::channel::params::ChannelPaddingInstructionsUpdates;
mod map;
@ -35,11 +35,11 @@ pub(crate) trait AbstractChannel: Clone {
/// Return None if the channel is currently in use.
fn duration_unused(&self) -> Option<Duration>;
/// Reparameterise this channel according to the provided `ChannelsParamsUpdates`
/// Reparameterise this channel according to the provided `ChannelPaddingInstructionsUpdates`
///
/// The changed parameters may not be implemented "immediately",
/// but this will be done "reasonably soon".
fn reparameterize(&mut self, updates: Arc<ChannelsParamsUpdates>) -> tor_proto::Result<()>;
fn reparameterize(&mut self, updates: Arc<ChannelPaddingInstructionsUpdates>) -> tor_proto::Result<()>;
/// Specify that this channel should do activities related to channel padding
///
@ -369,7 +369,7 @@ mod test {
mood: char,
closing: Arc<AtomicBool>,
detect_reuse: Arc<char>,
last_params: Option<ChannelsParamsUpdates>,
last_params: Option<ChannelPaddingInstructionsUpdates>,
}
impl PartialEq for FakeChannel {
@ -389,7 +389,7 @@ mod test {
fn duration_unused(&self) -> Option<Duration> {
None
}
fn reparameterize(&mut self, updates: Arc<ChannelsParamsUpdates>) -> tor_proto::Result<()> {
fn reparameterize(&mut self, updates: Arc<ChannelPaddingInstructionsUpdates>) -> tor_proto::Result<()> {
self.last_params = Some((*updates).clone());
Ok(())
}

View File

@ -14,8 +14,8 @@ use tor_error::{internal, into_internal};
use tor_netdir::{params::NetParameters, params::CHANNEL_PADDING_TIMEOUT_UPPER_BOUND};
use tor_proto::channel::padding::Parameters as PaddingParameters;
use tor_proto::channel::padding::ParametersBuilder as PaddingParametersBuilder;
use tor_proto::channel::ChannelsParamsUpdates;
use tor_proto::ChannelsParams;
use tor_proto::channel::ChannelPaddingInstructionsUpdates;
use tor_proto::ChannelPaddingInstructions;
use tor_units::{BoundedInt32, IntegerMilliseconds};
use tracing::info;
use void::{Void, ResultVoidExt as _};
@ -49,7 +49,7 @@ struct Inner<C: AbstractChannel> {
///
/// (Must be protected by the same lock as `channels`, or a channel might be
/// created using being-replaced parameters, but not get an update.)
channels_params: ChannelsParams,
channels_params: ChannelPaddingInstructions,
/// The configuration (from the config file or API caller)
config: ChannelConfig,
@ -224,7 +224,7 @@ impl<C: AbstractChannel> ChannelMap<C> {
dormancy: Dormancy,
netparams: &NetParameters,
) -> Self {
let mut channels_params = ChannelsParams::default();
let mut channels_params = ChannelPaddingInstructions::default();
let netparams = NetParamsExtract::from(netparams);
let update = parameterize(&mut channels_params, &config, dormancy, &netparams)
.unwrap_or_else(|e: tor_error::Bug| panic!("bug detected on startup: {:?}", e));
@ -277,7 +277,7 @@ impl<C: AbstractChannel> ChannelMap<C> {
func: F,
) -> Result<Option<ChannelState<C>>>
where
F: FnOnce(&ChannelsParams) -> Result<ChannelState<C>>,
F: FnOnce(&ChannelPaddingInstructions) -> Result<ChannelState<C>>,
{
let mut inner = self.inner.lock()?;
let newval = func(&inner.channels_params)?;
@ -442,15 +442,15 @@ impl<C: AbstractChannel> ChannelMap<C> {
/// This is called in two places:
///
/// 1. During chanmgr creation, it is called once to analyse the initial state
/// and construct a corresponding ChannelsParams.
/// and construct a corresponding ChannelPaddingInstructions.
///
/// 2. During reconfiguration.
fn parameterize(
channels_params: &mut ChannelsParams,
channels_params: &mut ChannelPaddingInstructions,
config: &ChannelConfig,
dormancy: Dormancy,
netdir: &NetParamsExtract,
) -> StdResult<Option<ChannelsParamsUpdates>, tor_error::Bug> {
) -> StdResult<Option<ChannelPaddingInstructionsUpdates>, tor_error::Bug> {
// Everything in this calculation applies to *all* channels, disregarding
// channel usage. Usage is handled downstream, in the channel frontend.
// See the module doc in `crates/tor-proto/src/channel/padding.rs`.
@ -573,7 +573,7 @@ mod test {
use super::*;
use std::sync::Arc;
use tor_proto::channel::params::ChannelsParamsUpdates;
use tor_proto::channel::params::ChannelPaddingInstructionsUpdates;
fn new_test_channel_map<C: AbstractChannel>() -> ChannelMap<C> {
ChannelMap::new(
@ -588,7 +588,7 @@ mod test {
ident: &'static str,
usable: bool,
unused_duration: Option<u64>,
params_update: Option<Arc<ChannelsParamsUpdates>>,
params_update: Option<Arc<ChannelPaddingInstructionsUpdates>>,
}
impl AbstractChannel for FakeChannel {
type Ident = u8;
@ -601,7 +601,7 @@ mod test {
fn duration_unused(&self) -> Option<Duration> {
self.unused_duration.map(Duration::from_secs)
}
fn reparameterize(&mut self, update: Arc<ChannelsParamsUpdates>) -> tor_proto::Result<()> {
fn reparameterize(&mut self, update: Arc<ChannelPaddingInstructionsUpdates>) -> tor_proto::Result<()> {
self.params_update = Some(update);
Ok(())
}
@ -785,7 +785,7 @@ mod test {
assert_eq!(
format!("{:?}", ch.params_update.take().unwrap()),
// evade field visibility by (ab)using Debug impl
"ChannelsParamsUpdates { padding_enable: None, \
"ChannelPaddingInstructionsUpdates { padding_enable: None, \
padding_parameters: Some(Parameters { \
low: IntegerMilliseconds { value: 1500 }, \
high: IntegerMilliseconds { value: 9500 } }), \

View File

@ -191,7 +191,7 @@ impl CaseContext {
for (i, (got, exp)) in zip_eq(messages, expected).enumerate() {
eprintln!("{i} {got:?} {exp:?}");
let got: ChannelsParamsUpdates = match got {
let got: ChannelPaddingInstructionsUpdates = match got {
Ok(CtrlMsg::ConfigUpdate(u)) => (*u).clone(),
_ => panic!("wrong message {got:?}"),
};

View File

@ -179,7 +179,7 @@ struct MutableDetails {
/// We store this here because:
///
/// 1. It must be per-channel, because it depends on channel usage. So it can't be in
/// (for example) `ChannelsParamsUpdate`.
/// (for example) `ChannelPaddingInstructionsUpdate`.
///
/// 2. It could be in the channel manager's per-channel state but (for code flow reasons
/// there, really) at the point at which the channel manager concludes for a pending
@ -196,7 +196,7 @@ struct MutableDetails {
enum PaddingControlState {
/// No usage of this channel, so far, implies sending or negotiating channel padding.
///
/// This means we do not send (have not sent) any `ChannelsParamsUpdates` to the reactor,
/// This means we do not send (have not sent) any `ChannelPaddingInstructionsUpdates` to the reactor,
/// with the following consequences:
///
/// * We don't enable our own padding.
@ -210,7 +210,7 @@ enum PaddingControlState {
///
/// We keep this so that we can send it if and when
/// this channel starts to be used in a way that implies (possibly) sending padding.
padding_params: ChannelsParamsUpdates,
padding_params: ChannelPaddingInstructionsUpdates,
},
/// Some usage of this channel implies possibly sending channel padding
@ -459,7 +459,7 @@ impl Channel {
/// Reparameterise (update parameters; reconfigure)
///
/// Returns `Err` if the channel was closed earlier
pub fn reparameterize(&mut self, params: Arc<ChannelsParamsUpdates>) -> Result<()> {
pub fn reparameterize(&mut self, params: Arc<ChannelPaddingInstructionsUpdates>) -> Result<()> {
let mut mutable = self
.details
.mutable

View File

@ -9,20 +9,20 @@ use super::padding;
/// Generate most of the module: things which contain or process all params fields (or each one)
///
/// There is one call to this macro, which has as argument
/// the body of `struct ChannelsParams`, with the following differences:
/// the body of `struct ChannelPaddingInstructions`, with the following differences:
///
/// * field visibility specifiers are not specified; they are provided by the macro
/// * non-doc attributes that ought to be applied to fields in `ChannelsParams`
/// * non-doc attributes that ought to be applied to fields in `ChannelPaddingInstructions`
/// are prefixed with `field`, e.g. `#[field educe(Default ...)]`;
/// this allows applying doc attributes to other items too.
///
/// Generates, fairly straightforwardly:
///
/// ```ignore
/// pub struct ChannelsParams { ... } // containing the fields as specified
/// pub struct ChannelsParamsUpdates { ... } // containing `Option` of each field
/// pub fn ChannelsParams::initial_update(&self) -> ChannelsParamsUpdates;
/// pub fn ChannelsParamsUpdatesBuilder::$field(self, new_value: _) -> Self;
/// pub struct ChannelPaddingInstructions { ... } // containing the fields as specified
/// pub struct ChannelPaddingInstructionsUpdates { ... } // containing `Option` of each field
/// pub fn ChannelPaddingInstructions::initial_update(&self) -> ChannelPaddingInstructionsUpdates;
/// pub fn ChannelPaddingInstructionsUpdatesBuilder::$field(self, new_value: _) -> Self;
/// ```
///
/// Within the macro body, we indent the per-field `$( )*` with 2 spaces.
@ -39,18 +39,18 @@ macro_rules! define_channels_params_and_automatic_impls { { $(
/// when used for handling updates,
/// it contains the last parameters that has been implemented.
///
/// Central code managing all channels will contain a `ChannelsParams`,
/// and use `ChannelsParamsUpdatesBuilder` to both update that params
/// and generate `ChannelsParamsUpdates` messages representing the changes.
/// Central code managing all channels will contain a `ChannelPaddingInstructions`,
/// and use `ChannelPaddingInstructionsUpdatesBuilder` to both update that params
/// and generate `ChannelPaddingInstructionsUpdates` messages representing the changes.
///
/// The channel frontend (methods on `Channel`)
/// processes `ChannelsParamsUpdates` from the channel manager,
/// processes `ChannelPaddingInstructionsUpdates` from the channel manager,
/// possibly into channel-specific updates.
///
/// `Default` is a placeholder to use pending availability of a netdir etc.
#[derive(Debug, Educe, Clone, Eq, PartialEq)]
#[educe(Default)]
pub struct ChannelsParams {
pub struct ChannelPaddingInstructions {
$(
$( #[doc $($doc_attr)*] )*
$( #[$other_attr] )*
@ -60,13 +60,13 @@ macro_rules! define_channels_params_and_automatic_impls { { $(
/// Reparameterisation message
///
/// Can contain updates to each of the fields in `ChannelsParams`.
/// Constructed via [`ChannelsParamsUpdatesBuilder`],
/// which is obtained from [`ChannelsParams::start_update`].
/// Can contain updates to each of the fields in `ChannelPaddingInstructions`.
/// Constructed via [`ChannelPaddingInstructionsUpdatesBuilder`],
/// which is obtained from [`ChannelPaddingInstructions::start_update`].
///
/// Sent to all channel implementations, when they ought to change their behaviour.
#[derive(Debug, Default, Clone, Eq, PartialEq)]
pub struct ChannelsParamsUpdates {
pub struct ChannelPaddingInstructionsUpdates {
$(
/// New value, if it has changed.
///
@ -77,13 +77,13 @@ macro_rules! define_channels_params_and_automatic_impls { { $(
)*
}
impl ChannelsParams {
impl ChannelPaddingInstructions {
/// Create an update message which sets all non-default settings in `self`
///
/// Used during channel startup.
#[must_use = "initial_update makes an updates message that must be sent to have effect"]
pub fn initial_update(&self) -> Option<ChannelsParamsUpdates> {
let mut supposed = ChannelsParams::default();
pub fn initial_update(&self) -> Option<ChannelPaddingInstructionsUpdates> {
let mut supposed = ChannelPaddingInstructions::default();
supposed.start_update()
$(
.$field(self.$field.clone())
@ -92,7 +92,7 @@ macro_rules! define_channels_params_and_automatic_impls { { $(
}
}
impl<'c> ChannelsParamsUpdatesBuilder<'c> {
impl<'c> ChannelPaddingInstructionsUpdatesBuilder<'c> {
$(
$( #[doc $($doc_attr)*] )*
///
@ -110,7 +110,7 @@ macro_rules! define_channels_params_and_automatic_impls { { $(
)*
}
impl ChannelsParamsUpdates {
impl ChannelPaddingInstructionsUpdates {
/// Combines `more` into `self`
///
/// Values from `more` override ones in `self`.
@ -161,44 +161,44 @@ pub(crate) fn interim_enable_by_env_var() -> bool {
/// Builder for a channels params update
///
/// Obtain this from `ChannelsParams::update`,
/// Obtain this from `ChannelPaddingInstructions::update`,
/// call zero or more setter methods,
/// call [`finish`](ChannelsParamsUpdatesBuilder::finish),
/// call [`finish`](ChannelPaddingInstructionsUpdatesBuilder::finish),
/// and then send the resulting message.
///
/// # Panics
///
/// Panics if dropped. Instead, call `finish`.
pub struct ChannelsParamsUpdatesBuilder<'c> {
pub struct ChannelPaddingInstructionsUpdatesBuilder<'c> {
/// Tracking the existing params
params: &'c mut ChannelsParams,
params: &'c mut ChannelPaddingInstructions,
/// The update we are building
///
/// `None` means nothing has changed yet.
update: Option<ChannelsParamsUpdates>,
update: Option<ChannelPaddingInstructionsUpdates>,
/// Make it hard to write code paths that drop this
drop_bomb: bool,
}
impl ChannelsParams {
impl ChannelPaddingInstructions {
/// Start building an update to channel parameters
///
/// The builder **must not be dropped**, once created;
/// instead, [`finish`](ChannelsParamsUpdatesBuilder::finish) must be called.
/// instead, [`finish`](ChannelPaddingInstructionsUpdatesBuilder::finish) must be called.
/// So prepare your new values first, perhaps fallibly,
/// and only then create and use the builder and send the update, infallibly.
///
/// (This is because the builder uses `self: ChannelsParams`
/// (This is because the builder uses `self: ChannelPaddingInstructions`
/// to track which values have changed,
/// and the values in `self` are updated immediately by the field update methods.)
///
/// # Panics
///
/// [`ChannelsParamsUpdatesBuilder`] panics if it is dropped.
pub fn start_update(&mut self) -> ChannelsParamsUpdatesBuilder {
ChannelsParamsUpdatesBuilder {
/// [`ChannelPaddingInstructionsUpdatesBuilder`] panics if it is dropped.
pub fn start_update(&mut self) -> ChannelPaddingInstructionsUpdatesBuilder {
ChannelPaddingInstructionsUpdatesBuilder {
params: self,
update: None,
drop_bomb: true,
@ -206,13 +206,13 @@ impl ChannelsParams {
}
}
impl<'c> Drop for ChannelsParamsUpdatesBuilder<'c> {
impl<'c> Drop for ChannelPaddingInstructionsUpdatesBuilder<'c> {
fn drop(&mut self) {
assert!(!self.drop_bomb, "ChannelsParamsUpdatesBuilder dropped");
assert!(!self.drop_bomb, "ChannelPaddingInstructionsUpdatesBuilder dropped");
}
}
impl<'c> ChannelsParamsUpdatesBuilder<'c> {
impl<'c> ChannelPaddingInstructionsUpdatesBuilder<'c> {
/// Finalise the update
///
/// If nothing actually changed, returns `None`.
@ -220,9 +220,9 @@ impl<'c> ChannelsParamsUpdatesBuilder<'c> {
/// every channel with a null update.)
///
/// If `Some` is returned, the update **must** be implemented,
/// since the underlying tracking [`ChannelsParams`] has already been updated.
/// since the underlying tracking [`ChannelPaddingInstructions`] has already been updated.
#[must_use = "the update from finish() must be sent, to avoid losing params changes"]
pub fn finish(mut self) -> Option<ChannelsParamsUpdates> {
pub fn finish(mut self) -> Option<ChannelPaddingInstructionsUpdates> {
self.drop_bomb = false;
self.update.take()
}

View File

@ -79,7 +79,7 @@ pub enum CtrlMsg {
///
/// These updates are done via a control message to avoid adding additional branches to the
/// main reactor `select!`.
ConfigUpdate(Arc<ChannelsParamsUpdates>),
ConfigUpdate(Arc<ChannelPaddingInstructionsUpdates>),
}
/// Object to handle incoming cells and background tasks on a channel.
@ -260,7 +260,7 @@ impl<S: SleepProvider> Reactor<S> {
self.update_disused_since();
}
CtrlMsg::ConfigUpdate(updates) => {
let ChannelsParamsUpdates {
let ChannelPaddingInstructionsUpdates {
// List all the fields explicitly; that way the compiler will warn us
// if one is added and we fail to handle it here.
padding_enable,

View File

@ -143,7 +143,7 @@ mod util;
pub use util::err::{Error, ResolveError};
pub use util::skew::ClockSkew;
pub use channel::params::ChannelsParams;
pub use channel::params::ChannelPaddingInstructions;
/// A Result type for this crate.
pub type Result<T> = std::result::Result<T, Error>;