circmgr: Functions to launch an unmanaged circuit.

We'll use this to implement the circuits used by onion circuits.
This commit is contained in:
Nick Mathewson 2023-03-15 09:56:34 -04:00
parent 4d2140641d
commit ec8c7eec4e
2 changed files with 26 additions and 3 deletions

View File

@ -441,17 +441,22 @@ impl<R: Runtime> CircMgr<R> {
///
/// Used to implement onion service clients and services.
#[cfg(feature = "hs-common")]
#[allow(unused_variables, clippy::missing_panics_doc)]
pub async fn launch_specific_isolated(
#[allow(unused_variables, clippy::missing_panics_doc, dead_code)] // TODO XXX
pub(crate) async fn launch_hs_unmanaged(
&self,
target: tor_linkspec::OwnedCircTarget,
dir: &NetDir,
// TODO hs: this should at least be an enum to define what kind of
// circuit we want, in case we have different rules for different types.
// It might also need to include a "anonymous?" flag for supporting
// single onion services.
preferences: (),
) -> Result<ClientCirc> {
todo!() // TODO hs implement.
let usage = TargetCircUsage::TimeoutTesting; // TODO HS: Wrong usage!
let (_supported_usage, client_circ) = self.mgr.launch_unmanaged(&usage, dir.into()).await?;
// XXX: Need to retain the supported_usage, maybe?
Ok(client_circ)
}
/// Launch circuits preemptively, using the preemptive circuit predictor's

View File

@ -1367,6 +1367,24 @@ impl<B: AbstractCircBuilder + 'static, R: Runtime> AbstractCircMgr<B, R> {
}
}
/// Plan and launch a new circuit to a given target, bypassing our managed
/// pool of circuits.
///
/// This method will always return a new circuit, and never return a circuit
/// that this CircMgr gives out for anything else.
///
/// The new circuit will participate in the guard and timeout apparatus as
/// appropriate, no retry attempt will be made if the circuit fails.
#[cfg(feature = "hs-common")]
pub(crate) async fn launch_unmanaged(
&self,
usage: &<B::Spec as AbstractSpec>::Usage,
dir: DirInfo<'_>,
) -> Result<(<B as AbstractCircBuilder>::Spec, B::Circ)> {
let (_, plan) = self.plan_by_usage(dir, usage)?;
self.builder.build_circuit(plan.plan).await
}
/// Remove the circuit with a given `id` from this manager.
///
/// After this function is called, that circuit will no longer be handed