diff options
Diffstat (limited to 'crates/tor-guardmgr')
| -rw-r--r-- | crates/tor-guardmgr/src/lib.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/crates/tor-guardmgr/src/lib.rs b/crates/tor-guardmgr/src/lib.rs index 17d547a33..eacf75767 100644 --- a/crates/tor-guardmgr/src/lib.rs +++ b/crates/tor-guardmgr/src/lib.rs @@ -59,6 +59,7 @@ use tor_error::internal; use tor_linkspec::{OwnedChanTarget, OwnedCircTarget, RelayId, RelayIdSet}; use tor_netdir::NetDirProvider; use tor_proto::ClockSkew; +use tor_units::BoundedInt32; use tracing::{debug, info, trace, warn}; use tor_config::impl_standard_builder; @@ -1861,6 +1862,24 @@ pub enum VanguardMode { Disabled, } +#[cfg(feature = "vanguards")] +impl VanguardMode { + /// Build a `VanguardMode` from a [`NetParameters`] parameter. + /// + /// Used for converting [`vanguards_enabled`](NetParameters::vanguards_enabled) + /// or [`vanguards_hs_service`](NetParameters::vanguards_hs_service) + /// to the corresponding `VanguardMode`. + #[allow(dead_code)] // TODO HS-VANGUARDS + pub(crate) fn from_net_parameter(val: BoundedInt32<0, 2>) -> Self { + match val.get() { + 0 => VanguardMode::Disabled, + 1 => VanguardMode::Lite, + 2 => VanguardMode::Full, + _ => unreachable!("BoundedInt32 was not bounded?!"), + } + } +} + /// The kind of vanguards to use. #[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)] // #[derive(derive_more::Display)] // |
