summaryrefslogtreecommitdiff
path: root/crates/tor-circmgr/src/hspool.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/tor-circmgr/src/hspool.rs')
-rw-r--r--crates/tor-circmgr/src/hspool.rs49
1 files changed, 22 insertions, 27 deletions
diff --git a/crates/tor-circmgr/src/hspool.rs b/crates/tor-circmgr/src/hspool.rs
index d94841f4d..da69805c9 100644
--- a/crates/tor-circmgr/src/hspool.rs
+++ b/crates/tor-circmgr/src/hspool.rs
@@ -23,7 +23,7 @@ use tor_rtcompat::{
scheduler::{TaskHandle, TaskSchedule},
Runtime, SleepProviderExt,
};
-use tracing::warn;
+use tracing::{debug, trace, warn};
use std::result::Result as StdResult;
@@ -77,7 +77,6 @@ pub(crate) struct HsCircStub {
/// The circuit.
pub(crate) circ: Arc<ClientCirc>,
/// Whether the circuit is STUB or STUB+.
- #[allow(dead_code)] // TODO HS-VANGUARDS
pub(crate) kind: HsCircStubKind,
}
@@ -129,12 +128,13 @@ impl HsCircStub {
/// STUB = G -> L2 -> L3
/// STUB+ = G -> L2 -> L3 -> M
/// ```
-#[allow(dead_code)] // TODO HS-VANGUARDS
-#[derive(Copy, Clone, Debug, PartialEq)]
+#[derive(Copy, Clone, Debug, PartialEq, derive_more::Display)]
pub(crate) enum HsCircStubKind {
/// A stub circuit (STUB).
+ #[display(fmt = "STUB")]
Stub,
/// An extended stub circuit (STUB+).
+ #[display(fmt = "STUB+")]
Extended,
}
@@ -573,13 +573,22 @@ async fn launch_hs_circuits_as_needed<R: Runtime>(
};
let now = pool.circmgr.mgr.peek_runtime().now();
pool.remove_closed();
- let mut n_to_launch = {
+ let mut circs_to_launch = {
let mut inner = pool.inner.lock().expect("poisioned_lock");
inner.pool.update_target_size(now);
- inner.pool.n_to_launch()
+ inner.pool.circs_to_launch()
};
+ let n_to_launch = circs_to_launch.n_to_launch();
let mut max_attempts = n_to_launch * 2;
- 'inner: while n_to_launch > 0 {
+
+ debug!(
+ "launching {} STUB and {} STUB+ circuits",
+ circs_to_launch.stub(),
+ circs_to_launch.ext_stub()
+ );
+
+ // TODO: refactor this to launch the circuits in parallel
+ 'inner: while circs_to_launch.n_to_launch() > 0 {
max_attempts -= 1;
if max_attempts == 0 {
// We want to avoid retrying over and over in a tight loop if all our attempts
@@ -595,34 +604,20 @@ async fn launch_hs_circuits_as_needed<R: Runtime>(
// launching several of these in parallel. If we do, we should think about
// whether taking the fastest will expose us to any attacks.
let no_target: Option<&OwnedCircTarget> = None;
-
- // TODO HS-VANGUARDS: we will need to launch N STUB circuits and M STUB+
- // circuits, for some N, M.
- //
- // We will need Pool to have two different targets, one for STUB circuits and
- // another for STUB+. Otherwise, if we only know the overall circuit target, each
- // time the pool is low on circuits we'll have no choice but to spawn both kinds of
- // stub circuits (in a ratio of N/M), even if we don't necessarily need the deficit
- // to be replenished in the N/M ratio. IOW, if the pool's overall target number of
- // circuits is T = N + M, and the actual number of circuits in the pool is
- // L = T - D, we'll need to spawn D circuits that consist of X STUBs and Y
- // STUB+s, where X/Y is not necessarily N/M (but the overall STUB/STUB+ ratio
- // *is* N/M).
- let stub_kind = HsCircStubKind::Stub;
+ let for_launch = circs_to_launch.for_launch();
// TODO HS: We should catch panics, here or in launch_hs_unmanaged.
match pool
.circmgr
- .launch_hs_unmanaged(no_target, &netdir, stub_kind)
+ .launch_hs_unmanaged(no_target, &netdir, for_launch.kind())
.await
{
Ok(circ) => {
- let circ = HsCircStub {
- circ,
- kind: stub_kind,
- };
+ let kind = for_launch.kind();
+ let circ = HsCircStub { circ, kind };
pool.inner.lock().expect("poisoned lock").pool.insert(circ);
- n_to_launch -= 1;
+ trace!("successfully launched {kind} circuit");
+ for_launch.note_circ_launched();
}
Err(err) => {
debug_report!(err, "Unable to build preemptive circuit for onion services");