Add a GuardMgr member to CircuitBuilder
This commit is contained in:
parent
99effeb532
commit
c41dd01a14
|
@ -2496,6 +2496,7 @@ dependencies = [
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tor-chanmgr",
|
"tor-chanmgr",
|
||||||
|
"tor-guardmgr",
|
||||||
"tor-linkspec",
|
"tor-linkspec",
|
||||||
"tor-llcrypto",
|
"tor-llcrypto",
|
||||||
"tor-netdir",
|
"tor-netdir",
|
||||||
|
|
|
@ -15,6 +15,7 @@ experimental-api = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tor-chanmgr = { path="../tor-chanmgr", version="0.0.0" }
|
tor-chanmgr = { path="../tor-chanmgr", version="0.0.0" }
|
||||||
|
tor-guardmgr = { path="../tor-guardmgr", version="0.0.0" }
|
||||||
tor-netdir = { path="../tor-netdir", version="0.0.0" }
|
tor-netdir = { path="../tor-netdir", version="0.0.0" }
|
||||||
tor-netdoc = { path="../tor-netdoc", version="0.0.0" }
|
tor-netdoc = { path="../tor-netdoc", version="0.0.0" }
|
||||||
tor-proto = { path="../tor-proto", version="0.0.0" }
|
tor-proto = { path="../tor-proto", version="0.0.0" }
|
||||||
|
|
|
@ -251,8 +251,11 @@ pub struct CircuitBuilder<R: Runtime> {
|
||||||
/// Configuration for how to choose paths for circuits.
|
/// Configuration for how to choose paths for circuits.
|
||||||
path_config: crate::PathConfig,
|
path_config: crate::PathConfig,
|
||||||
/// State-manager object to use in storing current state.
|
/// State-manager object to use in storing current state.
|
||||||
#[allow(dead_code)]
|
|
||||||
storage: crate::TimeoutStateHandle,
|
storage: crate::TimeoutStateHandle,
|
||||||
|
/// Guard manager to tell us which guards nodes to use for the circuits
|
||||||
|
/// we build.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
guardmgr: tor_guardmgr::GuardMgr<R>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R: Runtime> CircuitBuilder<R> {
|
impl<R: Runtime> CircuitBuilder<R> {
|
||||||
|
@ -264,6 +267,7 @@ impl<R: Runtime> CircuitBuilder<R> {
|
||||||
chanmgr: Arc<ChanMgr<R>>,
|
chanmgr: Arc<ChanMgr<R>>,
|
||||||
path_config: crate::PathConfig,
|
path_config: crate::PathConfig,
|
||||||
storage: crate::TimeoutStateHandle,
|
storage: crate::TimeoutStateHandle,
|
||||||
|
guardmgr: tor_guardmgr::GuardMgr<R>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let timeouts = match storage.load() {
|
let timeouts = match storage.load() {
|
||||||
Ok(Some(v)) => ParetoTimeoutEstimator::from_state(v),
|
Ok(Some(v)) => ParetoTimeoutEstimator::from_state(v),
|
||||||
|
@ -278,6 +282,7 @@ impl<R: Runtime> CircuitBuilder<R> {
|
||||||
builder: Arc::new(Builder::new(runtime, chanmgr, timeouts)),
|
builder: Arc::new(Builder::new(runtime, chanmgr, timeouts)),
|
||||||
path_config,
|
path_config,
|
||||||
storage,
|
storage,
|
||||||
|
guardmgr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,10 @@ pub enum Error {
|
||||||
/// Problem loading or storing persistent state.
|
/// Problem loading or storing persistent state.
|
||||||
#[error("Problem loading or storing state: {0}")]
|
#[error("Problem loading or storing state: {0}")]
|
||||||
State(#[from] tor_persist::Error),
|
State(#[from] tor_persist::Error),
|
||||||
|
|
||||||
|
/// Problem creating or updating a guard manager.
|
||||||
|
#[error("Problem creating or updating guards list: {0}")]
|
||||||
|
GuardMgr(#[from] tor_guardmgr::GuardMgrError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<futures::channel::oneshot::Canceled> for Error {
|
impl From<futures::channel::oneshot::Canceled> for Error {
|
||||||
|
|
|
@ -175,10 +175,17 @@ impl<R: Runtime> CircMgr<R> {
|
||||||
circuit_timing,
|
circuit_timing,
|
||||||
} = config;
|
} = config;
|
||||||
|
|
||||||
|
let guardmgr = tor_guardmgr::GuardMgr::new(runtime.clone(), storage.clone())?;
|
||||||
|
|
||||||
let storage = storage.create_handle(PARETO_TIMEOUT_DATA_KEY);
|
let storage = storage.create_handle(PARETO_TIMEOUT_DATA_KEY);
|
||||||
|
|
||||||
let builder =
|
let builder = build::CircuitBuilder::new(
|
||||||
build::CircuitBuilder::new(runtime.clone(), chanmgr, path_config, Arc::clone(&storage));
|
runtime.clone(),
|
||||||
|
chanmgr,
|
||||||
|
path_config,
|
||||||
|
Arc::clone(&storage),
|
||||||
|
guardmgr,
|
||||||
|
);
|
||||||
let mgr =
|
let mgr =
|
||||||
mgr::AbstractCircMgr::new(builder, runtime.clone(), request_timing, circuit_timing);
|
mgr::AbstractCircMgr::new(builder, runtime.clone(), request_timing, circuit_timing);
|
||||||
let circmgr = Arc::new(CircMgr {
|
let circmgr = Arc::new(CircMgr {
|
||||||
|
|
|
@ -65,7 +65,7 @@ pub use testing::TestingStateMgr;
|
||||||
/// Current implementations may place additional limits on the types
|
/// Current implementations may place additional limits on the types
|
||||||
/// of objects that can be stored. This is not a great example of OO
|
/// of objects that can be stored. This is not a great example of OO
|
||||||
/// design: eventually we should probably clarify that more.
|
/// design: eventually we should probably clarify that more.
|
||||||
pub trait StateMgr {
|
pub trait StateMgr: Clone {
|
||||||
/// Try to load the object with key `key` from the store.
|
/// Try to load the object with key `key` from the store.
|
||||||
///
|
///
|
||||||
/// Return None if no such object exists.
|
/// Return None if no such object exists.
|
||||||
|
|
Loading…
Reference in New Issue