1
//! Configuration elements for the guard manager
2

            
3
use tor_basic_utils::define_accessor_trait;
4
use tor_dircommon::fallback::FallbackList;
5

            
6
use crate::bridge::BridgeConfig;
7

            
8
define_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"))]
35
pub(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_time_subtraction)]
46
    #![allow(clippy::useless_vec)]
47
    #![allow(clippy::needless_pass_by_value)]
48
    #![allow(clippy::string_slice)] // See arti#2571
49
    //! <!-- @@ end test lint list maintained by maint/add_warning @@ -->
50

            
51
    use super::*;
52
    use derive_more::AsRef;
53

            
54
    /// A dummy test configuration, with transparent fields for testing
55
    #[derive(Default, Debug, AsRef)]
56
    #[allow(clippy::exhaustive_structs)]
57
    #[allow(missing_docs)]
58
    pub struct TestConfig {
59
        #[as_ref]
60
        pub fallbacks: FallbackList,
61
        pub bridges: Vec<BridgeConfig>,
62
    }
63
    impl AsRef<[BridgeConfig]> for TestConfig {
64
        fn as_ref(&self) -> &[BridgeConfig] {
65
            &self.bridges
66
        }
67
    }
68
    impl GuardMgrConfig for TestConfig {
69
        fn bridges_enabled(&self) -> bool {
70
            !self.bridges.is_empty()
71
        }
72
    }
73
}