diff options
Diffstat (limited to 'crates/tor-proto/src/stream')
| -rw-r--r-- | crates/tor-proto/src/stream/flow_ctrl/state.rs | 17 | ||||
| -rw-r--r-- | crates/tor-proto/src/stream/flow_ctrl/xon_xoff/reader.rs | 12 | ||||
| -rw-r--r-- | crates/tor-proto/src/stream/flow_ctrl/xon_xoff/state.rs | 12 |
3 files changed, 30 insertions, 11 deletions
diff --git a/crates/tor-proto/src/stream/flow_ctrl/state.rs b/crates/tor-proto/src/stream/flow_ctrl/state.rs index 41682fac2..ff51abeba 100644 --- a/crates/tor-proto/src/stream/flow_ctrl/state.rs +++ b/crates/tor-proto/src/stream/flow_ctrl/state.rs @@ -52,14 +52,14 @@ impl StreamFlowCtrl { #[cfg(feature = "flowctl-cc")] pub(crate) fn new_xon_xoff( params: Arc<FlowCtrlParameters>, - use_sidechannel_mitigations: bool, + with_sidechannel_mitigations: WithSidechannelMitigations, rate_limit_updater: watch::Sender<StreamRateLimit>, drain_rate_requester: NotifySender<DrainRateRequest>, ) -> Self { Self { inner: StreamFlowCtrlInner::XonXoff(XonXoffFlowCtrl::new( params, - use_sidechannel_mitigations, + with_sidechannel_mitigations, rate_limit_updater, drain_rate_requester, )), @@ -261,6 +261,19 @@ impl StreamRateLimit { } } +/// Whether sidechannel mitigations are enabled or not for flow control. +#[derive(Copy, Clone, Debug, PartialEq, Eq)] +pub(crate) enum WithSidechannelMitigations { + /// Flow control sidechannel mitigations are *enabled*. + /// + /// Should be enabled for clients (including onion services). + Enabled, + /// Flow control sidechannel mitigations are *disabled*. + /// + /// Should be disabled for exits. + Disabled, +} + impl std::fmt::Display for StreamRateLimit { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{} bytes/s", self.rate) diff --git a/crates/tor-proto/src/stream/flow_ctrl/xon_xoff/reader.rs b/crates/tor-proto/src/stream/flow_ctrl/xon_xoff/reader.rs index 2d02c0d18..182a0fef3 100644 --- a/crates/tor-proto/src/stream/flow_ctrl/xon_xoff/reader.rs +++ b/crates/tor-proto/src/stream/flow_ctrl/xon_xoff/reader.rs @@ -204,7 +204,9 @@ mod test { use std::sync::atomic::{AtomicU64, Ordering}; use crate::stream::flow_ctrl::params::FlowCtrlParameters; - use crate::stream::flow_ctrl::state::{FlowCtrlHooks, StreamRateLimit}; + use crate::stream::flow_ctrl::state::{ + FlowCtrlHooks, StreamRateLimit, WithSidechannelMitigations, + }; use crate::stream::flow_ctrl::xon_xoff::state::XonXoffFlowCtrl; use crate::util::notify::NotifySender; @@ -345,7 +347,7 @@ mod test { /// 4. The flow control logic. #[allow(clippy::type_complexity)] fn init_flow_ctrl( - use_sidechannel_mitigations: bool, + with_sidechannel_mitigations: WithSidechannelMitigations, ) -> ( WriterWithLength<Compat<DuplexStream>>, XonXoffReader<ReaderWithLength<Compat<DuplexStream>>, TestingDrainRateUpdates>, @@ -365,7 +367,7 @@ mod test { // The flow control logic. let flow_ctrl = XonXoffFlowCtrl::new( Arc::new(params), - use_sidechannel_mitigations, + with_sidechannel_mitigations, rate_limit_tx, drain_rate_request_tx, ); @@ -443,7 +445,7 @@ mod test { // This is the stream queue for incoming data. // So the `reader` is the stream reader and the `writer` would be within the reactor. let (mut writer, mut reader, mut drain_rate_receiver, mut flow_ctrl) = - init_flow_ctrl(/* use_sidechannel_mitigations= */ true); + init_flow_ctrl(WithSidechannelMitigations::Enabled); // Data has arrived on the stream. // We always consider sending an XOFF when a stream has received data. @@ -528,7 +530,7 @@ mod test { // This is the stream queue for incoming data. // So the `reader` is the stream reader and the `writer` would be within the reactor. let (mut writer, mut reader, mut drain_rate_receiver, mut flow_ctrl) = - init_flow_ctrl(/* use_sidechannel_mitigations= */ true); + init_flow_ctrl(WithSidechannelMitigations::Enabled); // Data has arrived on the stream. // We always consider sending an XOFF when a stream has received data. diff --git a/crates/tor-proto/src/stream/flow_ctrl/xon_xoff/state.rs b/crates/tor-proto/src/stream/flow_ctrl/xon_xoff/state.rs index 49795cc68..b2236edc1 100644 --- a/crates/tor-proto/src/stream/flow_ctrl/xon_xoff/state.rs +++ b/crates/tor-proto/src/stream/flow_ctrl/xon_xoff/state.rs @@ -43,7 +43,9 @@ use tracing::trace; use super::reader::DrainRateRequest; use crate::stream::flow_ctrl::params::{CellCount, FlowCtrlParameters}; -use crate::stream::flow_ctrl::state::{FlowCtrlHooks, HalfStreamFlowCtrlHooks, StreamRateLimit}; +use crate::stream::flow_ctrl::state::{ + FlowCtrlHooks, HalfStreamFlowCtrlHooks, StreamRateLimit, WithSidechannelMitigations, +}; use crate::util::notify::NotifySender; use crate::{Error, Result}; @@ -83,12 +85,14 @@ impl XonXoffFlowCtrl { /// Returns a new xon/xoff-based state. pub(crate) fn new( params: Arc<FlowCtrlParameters>, - use_sidechannel_mitigations: bool, + with_sidechannel_mitigations: WithSidechannelMitigations, rate_limit_updater: watch::Sender<StreamRateLimit>, drain_rate_requester: NotifySender<DrainRateRequest>, ) -> Self { - let sidechannel_mitigation = - use_sidechannel_mitigations.then_some(SidechannelMitigation::new()); + let sidechannel_mitigation = match with_sidechannel_mitigations { + WithSidechannelMitigations::Enabled => Some(SidechannelMitigation::new()), + WithSidechannelMitigations::Disabled => None, + }; // We use the same XOFF limit regardless of if we're a client or exit. // See https://gitlab.torproject.org/tpo/core/torspec/-/issues/371#note_3260658 |
