tor_guardmgr/config.rs
1//! Configuration elements for the guard manager
2
3use tor_basic_utils::define_accessor_trait;
4
5use crate::bridge::BridgeConfig;
6use crate::fallback::FallbackList;
7
8define_accessor_trait! {
9 /// Configuration for a guard manager
10 ///
11 /// If the guard manager gains new configurabilities, this trait will gain additional
12 /// supertraits, as an API break.
13 ///
14 /// Prefer to use `TorClientConfig`, which will always implement this trait.
15 pub trait GuardMgrConfig {
16 fallbacks: FallbackList,
17 bridges: [BridgeConfig],
18 +
19 /// Should the bridges be used?
20 ///
21 /// This is only allowed to return true if `bridges()` is nonempty.
22 ///
23 /// Therefore, it also requires `tor-guardmgr` cargo feature `bridge-client`,
24 /// since without that feature `BridgeConfig` is uninhabited and therefore
25 /// `bridges` is necessarily empty.
26 //
27 // Therefore, it is safe (from a "reject unsupported config" point of view)
28 // to ctest this only in code which is #[cfg(feature = "bridge-client")].
29 fn bridges_enabled(&self) -> bool;
30 }
31}
32
33/// Helpers for testing configuration
34#[cfg(any(test, feature = "testing"))]
35pub(crate) mod testing {
36 // @@ begin test lint list maintained by maint/add_warning @@
37 #![allow(clippy::bool_assert_comparison)]
38 #![allow(clippy::clone_on_copy)]
39 #![allow(clippy::dbg_macro)]
40 #![allow(clippy::mixed_attributes_style)]
41 #![allow(clippy::print_stderr)]
42 #![allow(clippy::print_stdout)]
43 #![allow(clippy::single_char_pattern)]
44 #![allow(clippy::unwrap_used)]
45 #![allow(clippy::unchecked_duration_subtraction)]
46 #![allow(clippy::useless_vec)]
47 #![allow(clippy::needless_pass_by_value)]
48 //! <!-- @@ end test lint list maintained by maint/add_warning @@ -->
49
50 use super::*;
51 use derive_more::AsRef;
52
53 /// A dummy test configuration, with transparent fields for testing
54 #[derive(Default, Debug, AsRef)]
55 #[allow(clippy::exhaustive_structs)]
56 #[allow(missing_docs)]
57 pub struct TestConfig {
58 #[as_ref]
59 pub fallbacks: FallbackList,
60 pub bridges: Vec<BridgeConfig>,
61 }
62 impl AsRef<[BridgeConfig]> for TestConfig {
63 fn as_ref(&self) -> &[BridgeConfig] {
64 &self.bridges
65 }
66 }
67 impl GuardMgrConfig for TestConfig {
68 fn bridges_enabled(&self) -> bool {
69 !self.bridges.is_empty()
70 }
71 }
72}