summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/tor-guardmgr/src/lib.rs19
-rw-r--r--crates/tor-netdir/src/params.rs70
2 files changed, 89 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)] //
diff --git a/crates/tor-netdir/src/params.rs b/crates/tor-netdir/src/params.rs
index d79398e38..910376304 100644
--- a/crates/tor-netdir/src/params.rs
+++ b/crates/tor-netdir/src/params.rs
@@ -413,6 +413,76 @@ pub struct NetParameters {
/// <https://spec.torproject.org/param-spec.md#HiddenServiceEnableIntroDoSRatePerSec>
pub hs_intro_dos_rate: BoundedInt32<0, {i32::MAX}> = (25)
from "HiddenServiceEnableIntroDoSRatePerSec",
+
+ /// The type of vanguards to use by default when building onion service circuits:
+ ///
+ /// ```text
+ /// 0: No vanguards.
+ /// 1: Lite vanguards.
+ /// 2: Full vanguards.
+ /// ```
+ ///
+ /// See
+ /// <https://spec.torproject.org/param-spec.html#vanguards>
+ pub vanguards_enabled: BoundedInt32<0, 2> = (1)
+ from "vanguards-enabled",
+
+ /// If higher than `vanguards-enabled`,
+ /// and we are running an onion service,
+ /// we use this level for all our onion service circuits:
+ ///
+ /// ```text
+ /// 0: No vanguards.
+ /// 1: Lite vanguards.
+ /// 2: Full vanguards.
+ /// ```
+ ///
+ /// See
+ /// <https://spec.torproject.org/param-spec.html#vanguards>
+ pub vanguards_hs_service: BoundedInt32<0, 2> = (2)
+ from "vanguards-hs-service",
+
+ /// The number of vanguards in the L2 vanguard set.
+ ///
+ /// See
+ /// <https://spec.torproject.org/param-spec.html#vanguards>
+ pub guard_hs_l2_number: BoundedInt32<1, {i32::MAX}> = (4)
+ from "guard-hs-l2-number",
+
+ /// The minimum lifetime of L2 vanguards.
+ ///
+ /// See
+ /// <https://spec.torproject.org/param-spec.html#vanguards>
+ pub guard_hs_l2_lifetime_min: IntegerSeconds<BoundedInt32<1, {i32::MAX}>> = (86400)
+ from "guard-hs-l2-lifetime-min",
+
+ /// The maximum lifetime of L2 vanguards.
+ ///
+ /// See
+ /// <https://spec.torproject.org/param-spec.html#vanguards>
+ pub guard_hs_l2_lifetime_max: IntegerSeconds<BoundedInt32<1, {i32::MAX}>> = (1036800)
+ from "guard-hs-l2-lifetime-max",
+
+ /// The number of vanguards in the L3 vanguard set.
+ ///
+ /// See
+ /// <https://spec.torproject.org/param-spec.html#vanguards>
+ pub guard_hs_l3_number: BoundedInt32<1, {i32::MAX}> = (8)
+ from "guard-hs-l3-number",
+
+ /// The minimum lifetime of L3 vanguards.
+ ///
+ /// See
+ /// <https://spec.torproject.org/param-spec.html#vanguards>
+ pub guard_hs_l3_lifetime_min: IntegerSeconds<BoundedInt32<1, {i32::MAX}>> = (3600)
+ from "guard-hs-l3-lifetime-min",
+
+ /// The maximum lifetime of L3 vanguards.
+ ///
+ /// See
+ /// <https://spec.torproject.org/param-spec.html#vanguards>
+ pub guard_hs_l3_lifetime_max: IntegerSeconds<BoundedInt32<1, {i32::MAX}>> = (172800)
+ from "guard-hs-l3-lifetime-max",
}
}