diff --git a/crates/tor-guardmgr/src/filter.rs b/crates/tor-guardmgr/src/filter.rs index a3b1ae9b6..66b403ce4 100644 --- a/crates/tor-guardmgr/src/filter.rs +++ b/crates/tor-guardmgr/src/filter.rs @@ -1,5 +1,7 @@ //! Implement GuardFilter and related types. +use educe::Educe; + use tor_linkspec::ChanTarget; /// An object specifying which relays are eligible to be guards. @@ -15,11 +17,13 @@ use tor_linkspec::ChanTarget; /// Right now, only the `Unrestricted` filter is implemented or available. /// This enumeration is just a place-holder, however, to make sure we're /// checking our filter in the right places. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Educe)] +#[educe(Default)] #[non_exhaustive] pub enum GuardFilter { /// A filter representing no restrictions on the permissible guards /// at all. + #[educe(Default)] Unfiltered, /// Testing only: checks whether the first byte of the rsa key is 0 modulo 4. @@ -30,12 +34,6 @@ pub enum GuardFilter { TestingLimitKeys, } -impl Default for GuardFilter { - fn default() -> Self { - GuardFilter::Unfiltered - } -} - impl GuardFilter { /// Create a new [`GuardFilter`] that doesn't restrict the set of /// permissible guards at all. diff --git a/crates/tor-guardmgr/src/guard.rs b/crates/tor-guardmgr/src/guard.rs index bfafd8382..5c3f83a33 100644 --- a/crates/tor-guardmgr/src/guard.rs +++ b/crates/tor-guardmgr/src/guard.rs @@ -4,6 +4,7 @@ use tor_linkspec::ChanTarget; use tor_llcrypto::pk::{ed25519::Ed25519Identity, rsa::RsaIdentity}; use tor_netdir::{NetDir, Relay, RelayWeight}; +use educe::Educe; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::net::SocketAddr; @@ -15,7 +16,8 @@ use crate::{GuardId, GuardParams, GuardRestriction, GuardUsage}; use tor_persist::{Futureproof, JsonValue}; /// Tri-state to represent whether a guard is believed to be reachable or not. -#[derive(Debug, Clone, Copy, Eq, PartialEq)] +#[derive(Debug, Clone, Copy, Eq, PartialEq, Educe)] +#[educe(Default)] #[allow(clippy::enum_variant_names)] pub(crate) enum Reachable { /// A guard is believed to be reachable, since we have successfully @@ -30,15 +32,10 @@ pub(crate) enum Reachable { /// * We haven't tried to use the guard. /// * Attempts to use it have failed, but those attempts are far /// enough in the past that we're willing to retry them. + #[educe(Default)] Unknown, } -impl Default for Reachable { - fn default() -> Self { - Reachable::Unknown - } -} - /// The name and version of the crate that first picked a potential /// guard. /// diff --git a/crates/tor-guardmgr/src/lib.rs b/crates/tor-guardmgr/src/lib.rs index a1a60fa7e..e14bc57a1 100644 --- a/crates/tor-guardmgr/src/lib.rs +++ b/crates/tor-guardmgr/src/lib.rs @@ -130,6 +130,7 @@ // confirmed // filtered +use educe::Educe; use futures::channel::mpsc; use futures::task::{SpawnError, SpawnExt}; use serde::{Deserialize, Serialize}; @@ -959,12 +960,14 @@ impl tor_linkspec::ChanTarget for Guard { /// The purpose for which we plan to use a guard. /// /// This can affect the guard selection algorithm. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, Educe)] +#[educe(Default)] #[non_exhaustive] pub enum GuardUsageKind { /// We want to use this guard for a data circuit. /// /// (This encompasses everything except the `OneHopDirectory` case.) + #[educe(Default)] Data, /// We want to use this guard for a one-hop, non-anonymous /// directory request. @@ -974,12 +977,6 @@ pub enum GuardUsageKind { OneHopDirectory, } -impl Default for GuardUsageKind { - fn default() -> GuardUsageKind { - GuardUsageKind::Data - } -} - /// A set of parameters describing how a single guard should be selected. /// /// Used as an argument to [`GuardMgr::select_guard`].