From c41dd01a14ccb36b478fdb655096dda4159dfe09 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 10 Oct 2021 12:24:48 -0400 Subject: [PATCH] Add a GuardMgr member to CircuitBuilder --- Cargo.lock | 1 + crates/tor-circmgr/Cargo.toml | 1 + crates/tor-circmgr/src/build.rs | 7 ++++++- crates/tor-circmgr/src/err.rs | 4 ++++ crates/tor-circmgr/src/lib.rs | 11 +++++++++-- crates/tor-persist/src/lib.rs | 2 +- 6 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 12796b393..1f1749107 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2496,6 +2496,7 @@ dependencies = [ "static_assertions", "thiserror", "tor-chanmgr", + "tor-guardmgr", "tor-linkspec", "tor-llcrypto", "tor-netdir", diff --git a/crates/tor-circmgr/Cargo.toml b/crates/tor-circmgr/Cargo.toml index ad31eca5c..98ba30cb0 100644 --- a/crates/tor-circmgr/Cargo.toml +++ b/crates/tor-circmgr/Cargo.toml @@ -15,6 +15,7 @@ experimental-api = [] [dependencies] 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-netdoc = { path="../tor-netdoc", version="0.0.0" } tor-proto = { path="../tor-proto", version="0.0.0" } diff --git a/crates/tor-circmgr/src/build.rs b/crates/tor-circmgr/src/build.rs index 896630dc6..c391334a3 100644 --- a/crates/tor-circmgr/src/build.rs +++ b/crates/tor-circmgr/src/build.rs @@ -251,8 +251,11 @@ pub struct CircuitBuilder { /// Configuration for how to choose paths for circuits. path_config: crate::PathConfig, /// State-manager object to use in storing current state. - #[allow(dead_code)] 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, } impl CircuitBuilder { @@ -264,6 +267,7 @@ impl CircuitBuilder { chanmgr: Arc>, path_config: crate::PathConfig, storage: crate::TimeoutStateHandle, + guardmgr: tor_guardmgr::GuardMgr, ) -> Self { let timeouts = match storage.load() { Ok(Some(v)) => ParetoTimeoutEstimator::from_state(v), @@ -278,6 +282,7 @@ impl CircuitBuilder { builder: Arc::new(Builder::new(runtime, chanmgr, timeouts)), path_config, storage, + guardmgr, } } diff --git a/crates/tor-circmgr/src/err.rs b/crates/tor-circmgr/src/err.rs index 1cd8e4acb..a69bd9ac2 100644 --- a/crates/tor-circmgr/src/err.rs +++ b/crates/tor-circmgr/src/err.rs @@ -52,6 +52,10 @@ pub enum Error { /// Problem loading or storing persistent state. #[error("Problem loading or storing state: {0}")] 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 for Error { diff --git a/crates/tor-circmgr/src/lib.rs b/crates/tor-circmgr/src/lib.rs index 87f102d99..283fd3480 100644 --- a/crates/tor-circmgr/src/lib.rs +++ b/crates/tor-circmgr/src/lib.rs @@ -175,10 +175,17 @@ impl CircMgr { circuit_timing, } = config; + let guardmgr = tor_guardmgr::GuardMgr::new(runtime.clone(), storage.clone())?; + let storage = storage.create_handle(PARETO_TIMEOUT_DATA_KEY); - let builder = - build::CircuitBuilder::new(runtime.clone(), chanmgr, path_config, Arc::clone(&storage)); + let builder = build::CircuitBuilder::new( + runtime.clone(), + chanmgr, + path_config, + Arc::clone(&storage), + guardmgr, + ); let mgr = mgr::AbstractCircMgr::new(builder, runtime.clone(), request_timing, circuit_timing); let circmgr = Arc::new(CircMgr { diff --git a/crates/tor-persist/src/lib.rs b/crates/tor-persist/src/lib.rs index da0ca2944..06141391c 100644 --- a/crates/tor-persist/src/lib.rs +++ b/crates/tor-persist/src/lib.rs @@ -65,7 +65,7 @@ pub use testing::TestingStateMgr; /// Current implementations may place additional limits on the types /// of objects that can be stored. This is not a great example of OO /// 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. /// /// Return None if no such object exists.