guardmgr config: Provide bridge information to new and reconfigure
This commit is contained in:
parent
5bc3934fb4
commit
7d6f5d5eab
|
@ -20,7 +20,9 @@ pub use tor_config::{CfgPath, CfgPathError, ConfigBuildError, ConfigurationSourc
|
|||
|
||||
#[cfg(feature = "bridge-client")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "bridge-client")))]
|
||||
pub use tor_guardmgr::bridge::{BridgeConfig, BridgeParseError};
|
||||
pub use tor_guardmgr::bridge::BridgeParseError;
|
||||
|
||||
use tor_guardmgr::bridge::BridgeConfig;
|
||||
|
||||
/// Types for configuring how Tor circuits are built.
|
||||
pub mod circ {
|
||||
|
@ -266,6 +268,21 @@ fn validate_bridges_config(bridges: &BridgesConfigBuilder) -> Result<(), ConfigB
|
|||
Ok(())
|
||||
}
|
||||
|
||||
impl BridgesConfig {
|
||||
/// Should the bridges be used?
|
||||
fn bridges_enabled(&self) -> bool {
|
||||
#[cfg(feature = "bridge-client")]
|
||||
{
|
||||
self.enabled.as_bool().unwrap_or(!self.bridges.is_empty())
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "bridge-client"))]
|
||||
{
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// List of configured bridges, as found in the built configuration
|
||||
//
|
||||
// This type alias arranges that we can put `BridgeList` in `BridgesConfig`
|
||||
|
@ -429,7 +446,24 @@ impl AsRef<tor_guardmgr::fallback::FallbackList> for TorClientConfig {
|
|||
self.tor_network.fallback_caches()
|
||||
}
|
||||
}
|
||||
impl tor_guardmgr::GuardMgrConfig for TorClientConfig {}
|
||||
impl AsRef<[BridgeConfig]> for TorClientConfig {
|
||||
fn as_ref(&self) -> &[BridgeConfig] {
|
||||
#[cfg(feature = "bridge-client")]
|
||||
{
|
||||
&self.bridges.bridges
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "bridge-client"))]
|
||||
{
|
||||
&[]
|
||||
}
|
||||
}
|
||||
}
|
||||
impl tor_guardmgr::GuardMgrConfig for TorClientConfig {
|
||||
fn bridges_enabled(&self) -> bool {
|
||||
self.bridges.bridges_enabled()
|
||||
}
|
||||
}
|
||||
|
||||
impl TorClientConfig {
|
||||
/// Try to create a DirMgrConfig corresponding to this object.
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use tor_basic_utils::define_accessor_trait;
|
||||
|
||||
use crate::bridge::BridgeConfig;
|
||||
use crate::fallback::FallbackList;
|
||||
|
||||
define_accessor_trait! {
|
||||
|
@ -13,6 +14,12 @@ define_accessor_trait! {
|
|||
/// Prefer to use `TorClientConfig`, which will always implement this trait.
|
||||
pub trait GuardMgrConfig {
|
||||
fallbacks: FallbackList,
|
||||
bridges: [BridgeConfig],
|
||||
+
|
||||
/// Should the bridges be used?
|
||||
///
|
||||
/// This is only allowed to return true if `bridges()` is nonempty.
|
||||
fn bridges_enabled(&self) -> bool;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,6 +46,18 @@ pub(crate) mod testing {
|
|||
///
|
||||
#[as_ref]
|
||||
pub fallbacks: FallbackList,
|
||||
|
||||
///
|
||||
pub bridges: Vec<BridgeConfig>,
|
||||
}
|
||||
impl AsRef<[BridgeConfig]> for TestConfig {
|
||||
fn as_ref(&self) -> &[BridgeConfig] {
|
||||
&self.bridges
|
||||
}
|
||||
}
|
||||
impl GuardMgrConfig for TestConfig {
|
||||
fn bridges_enabled(&self) -> bool {
|
||||
!self.bridges.is_empty()
|
||||
}
|
||||
}
|
||||
impl GuardMgrConfig for TestConfig {}
|
||||
}
|
||||
|
|
|
@ -289,6 +289,9 @@ impl<R: Runtime> GuardMgr<R> {
|
|||
let (send_skew, recv_skew) = postage::watch::channel();
|
||||
let recv_skew = ClockSkewEvents { inner: recv_skew };
|
||||
|
||||
// TODO pt-client do something with the bridge information
|
||||
// should probably share code with reconfigure() as much as possible
|
||||
|
||||
let inner = Arc::new(Mutex::new(GuardMgrInner {
|
||||
guards: state,
|
||||
filter: GuardFilter::unfiltered(),
|
||||
|
@ -439,6 +442,8 @@ impl<R: Runtime> GuardMgr<R> {
|
|||
|
||||
/// Reconfigure
|
||||
pub fn reconfigure(&self, config: &impl GuardMgrConfig) -> Result<(), ReconfigureError> {
|
||||
// TODO pt-client: do something with config.bridges and config.bridges_enabled
|
||||
// should probably share code with new() as much as possible
|
||||
self.replace_fallback_list(config.fallbacks());
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue