diff options
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/tor-proto/src/tunnel/reactor/circuit.rs | 68 | ||||
| -rw-r--r-- | crates/tor-proto/src/tunnel/reactor/control.rs | 33 |
2 files changed, 40 insertions, 61 deletions
diff --git a/crates/tor-proto/src/tunnel/reactor/circuit.rs b/crates/tor-proto/src/tunnel/reactor/circuit.rs index ffb2ef516..2ca4c73da 100644 --- a/crates/tor-proto/src/tunnel/reactor/circuit.rs +++ b/crates/tor-proto/src/tunnel/reactor/circuit.rs @@ -1205,36 +1205,7 @@ impl Circuit { let relay_cell_protocol = RelayCryptLayerProtocol::Tor1(RelayCellFormat::V0); // Set the client extensions. - // allow 'unused_mut' because of the combinations of `cfg` conditions below - #[allow(unused_mut)] - let mut client_extensions = Vec::new(); - - if params.ccontrol.is_enabled() { - cfg_if::cfg_if! { - if #[cfg(feature = "flowctl-cc")] { - // TODO(arti#88): We have an `if false` in `exit_circparams_from_netparams` - // which should prevent the above `is_enabled()` from ever being true, - // even with the "flowctl-cc" feature enabled: - // https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/2932#note_3191196 - // The panic here is so that CI tests will hopefully catch if congestion - // control is unexpectedly enabled. - // We should remove this panic once xon/xoff flow is supported. - #[cfg(not(test))] - panic!("Congestion control is enabled on this circuit, but we don't yet support congestion control"); - - #[allow(unreachable_code)] - client_extensions.push(CircRequestExt::CcRequest(CcRequest::default())); - } else { - return Err( - internal!( - "Congestion control is enabled on this circuit, but 'flowctl-cc' feature is not enabled" - ) - .into() - ); - } - } - } - + let client_extensions = circ_extensions_from_params(params)?; let wrap = Create2Wrap { handshake_type: HandshakeType::NTOR_V3, }; @@ -1819,3 +1790,40 @@ impl CircHop { &self.ccontrol } } + +/// Return the client circuit-creation extensions that we should use in order to negotiate +/// a given set of circuit hop parameters. +#[allow(clippy::unnecessary_wraps)] +pub(super) fn circ_extensions_from_params(params: &CircParameters) -> Result<Vec<CircRequestExt>> { + // allow 'unused_mut' because of the combinations of `cfg` conditions below + #[allow(unused_mut)] + let mut client_extensions = Vec::new(); + + if params.ccontrol.is_enabled() { + cfg_if::cfg_if! { + if #[cfg(feature = "flowctl-cc")] { + // TODO(arti#88): We have an `if false` in `exit_circparams_from_netparams` + // which should prevent the above `is_enabled()` from ever being true, + // even with the "flowctl-cc" feature enabled: + // https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/2932#note_3191196 + // The panic here is so that CI tests will hopefully catch if congestion + // control is unexpectedly enabled. + // We should remove this panic once xon/xoff flow is supported. + #[cfg(not(test))] + panic!("Congestion control is enabled on this circuit, but we don't yet support congestion control"); + + #[allow(unreachable_code)] + client_extensions.push(CircRequestExt::CcRequest(CcRequest::default())); + } else { + return Err( + tor_error::internal!( + "Congestion control is enabled on this circuit, but 'flowctl-cc' feature is not enabled" + ) + .into() + ); + } + } + } + + Ok(client_extensions) +} diff --git a/crates/tor-proto/src/tunnel/reactor/control.rs b/crates/tor-proto/src/tunnel/reactor/control.rs index 2e4912700..9a14142af 100644 --- a/crates/tor-proto/src/tunnel/reactor/control.rs +++ b/crates/tor-proto/src/tunnel/reactor/control.rs @@ -11,12 +11,12 @@ use crate::crypto::handshake::ntor_v3::{NtorV3Client, NtorV3PublicKey}; use crate::stream::AnyCmdChecker; use crate::tunnel::circuit::celltypes::CreateResponse; use crate::tunnel::circuit::{path, CircParameters}; +use crate::tunnel::reactor::circuit::circ_extensions_from_params; use crate::tunnel::reactor::{NtorClient, ReactorError}; use crate::tunnel::{streammap, HopLocation, TargetHop}; use crate::util::skew::ClockSkew; use crate::Result; use tor_cell::chancell::msg::HandshakeType; -use tor_cell::relaycell::extend::{CcRequest, CircRequestExt}; use tor_cell::relaycell::msg::{AnyRelayMsg, Sendme}; use tor_cell::relaycell::{AnyRelayMsgOuter, RelayCellFormat, StreamId, UnparsedRelayMsg}; use tor_error::{bad_api_usage, into_bad_api_usage, Bug}; @@ -365,36 +365,7 @@ impl<'a> ControlHandler<'a> { // TODO #1067, TODO #1947: support negotiating other formats. let relay_cell_format = RelayCellFormat::V0; - // Set the client extensions. - // allow 'unused_mut' because of the combinations of `cfg` conditions below - #[allow(unused_mut)] - let mut client_extensions = Vec::new(); - - if params.ccontrol.is_enabled() { - cfg_if::cfg_if! { - if #[cfg(feature = "flowctl-cc")] { - // TODO(arti#88): We have an `if false` in `exit_circparams_from_netparams` - // which should prevent the above `is_enabled()` from ever being true, - // even with the "flowctl-cc" feature enabled: - // https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/2932#note_3191196 - // The panic here is so that CI tests will hopefully catch if congestion - // control is unexpectedly enabled. - // We should remove this panic once xon/xoff flow is supported. - #[cfg(not(test))] - panic!("Congestion control is enabled on this circuit, but we don't yet support congestion control"); - - #[allow(unreachable_code)] - client_extensions.push(CircRequestExt::CcRequest(CcRequest::default())); - } else { - return Err( - tor_error::internal!( - "Congestion control is enabled on this circuit, but 'flowctl-cc' feature is not enabled" - ) - .into() - ); - } - } - } + let client_extensions = circ_extensions_from_params(¶ms)?; let (extender, cell) = CircuitExtender::<NtorV3Client, Tor1RelayCrypto, _, _>::begin( |
