tor-circmgr: Provide estimate_timeout as a method on HsCircPool

This commit is contained in:
Ian Jackson 2023-06-29 14:46:43 +01:00
parent 9ad64792da
commit a7d1efe2ce
1 changed files with 21 additions and 1 deletions

View File

@ -8,7 +8,7 @@ use std::{
time::Duration,
};
use crate::{CircMgr, Error, Result};
use crate::{timeouts, CircMgr, Error, Result};
use futures::{task::SpawnExt, StreamExt, TryFutureExt};
use once_cell::sync::OnceCell;
use tor_error::{bad_api_usage, internal, ErrorReport};
@ -281,6 +281,26 @@ impl<R: Runtime> HsCircPool<R> {
.pool
.retain(|circ| circuit_still_useable(netdir, circ, |_relay| true));
}
/// Return an estimate-based delay for how long a given
/// [`Action`](timeouts::Action) should be allowed to complete.
///
/// This function has the same semantics as
/// [`CircMgr::estimate_timeout`].
/// See the notes there.
///
/// In particular **you do not need to use this function** in order to get
/// reasonable timeouts for the circuit-building operations provided by `HsCircPool`.
//
// In principle we could have made this available by making `HsCircPool` `Deref`
// to `CircMgr`, but we don't want to do that because `CircMgr` has methods that
// operate on *its* pool which is separate from the pool maintained by `HsCircPool`.
//
// We *might* want to provide a method to access the underlying `CircMgr`
// but that has the same issues, albeit less severely.
pub fn estimate_timeout(&self, timeout_action: &timeouts::Action) -> std::time::Duration {
self.circmgr.estimate_timeout(timeout_action)
}
}
/// Wrapper around a target final hop, and any information about that target we