aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriela Moldovan <gabi@torproject.org>2024-05-09 12:27:58 +0100
committerGabriela Moldovan <gabi@torproject.org>2024-05-09 17:37:39 +0100
commitc209876c3247c9137d19c166b17e0bea811e1ba7 (patch)
tree77e3e234ff40566eeebd4df6dbd44f4bee708d02
parent1342c029cdb9ea2cba4765ef700e0df7eb7f0fe4 (diff)
downloadarti-c209876c3247c9137d19c166b17e0bea811e1ba7.tar.gz
arti-c209876c3247c9137d19c166b17e0bea811e1ba7.zip
tor-guardmgr: Add an error variant for when the vanguard mode is unsuitable.
-rw-r--r--crates/tor-guardmgr/src/vanguards.rs21
-rw-r--r--crates/tor-guardmgr/src/vanguards/err.rs12
2 files changed, 25 insertions, 8 deletions
diff --git a/crates/tor-guardmgr/src/vanguards.rs b/crates/tor-guardmgr/src/vanguards.rs
index e4c1b7445..ad1cd3c15 100644
--- a/crates/tor-guardmgr/src/vanguards.rs
+++ b/crates/tor-guardmgr/src/vanguards.rs
@@ -291,13 +291,11 @@ impl<R: Runtime> VanguardMgr<R> {
.l3()
.pick_relay(rng, netdir, neighbor_exclusion)
}
- // TODO HS-VANGUARDS: perhaps we need a dedicated error variant for this
_ => {
- return Err(internal!(
- "vanguards for layer {layer} are not supported in mode {})",
- inner.mode
- )
- .into());
+ return Err(VanguardMgrError::LayerNotSupported {
+ layer,
+ mode: inner.mode,
+ });
}
};
@@ -750,7 +748,16 @@ mod test {
let err = vanguardmgr
.select_vanguard(&mut rng, &netdir, Layer3, &exclusion)
.unwrap_err();
- assert!(matches!(err, VanguardMgrError::Bug(_)), "{err:?}");
+ assert!(
+ matches!(
+ err,
+ VanguardMgrError::LayerNotSupported {
+ layer: Layer::Layer3,
+ mode: VanguardMode::Lite
+ }
+ ),
+ "{err}"
+ );
});
}
diff --git a/crates/tor-guardmgr/src/vanguards/err.rs b/crates/tor-guardmgr/src/vanguards/err.rs
index b89b1311d..6563d479f 100644
--- a/crates/tor-guardmgr/src/vanguards/err.rs
+++ b/crates/tor-guardmgr/src/vanguards/err.rs
@@ -5,7 +5,7 @@ use std::sync::Arc;
use futures::task::SpawnError;
use tor_error::{ErrorKind, HasKind};
-use crate::vanguards::Layer;
+use crate::vanguards::{Layer, VanguardMode};
/// An error coming from the vanguards subsystem.
#[derive(Clone, Debug, thiserror::Error)]
@@ -19,6 +19,15 @@ pub enum VanguardMgrError {
action: &'static str,
},
+ /// Attempted to select a vanguard layer that is not supported in the current [`VanguardMode`],
+ #[error("{layer} vanguards are not supported in {mode} mode")]
+ LayerNotSupported {
+ /// The layer we tried to select a vanguard for.
+ layer: Layer,
+ /// The [`VanguardMode`] we are in.
+ mode: VanguardMode,
+ },
+
/// Could not find a suitable relay to use for the specifier layer.
#[error("No suitable relays")]
NoSuitableRelay(Layer),
@@ -44,6 +53,7 @@ impl HasKind for VanguardMgrError {
fn kind(&self) -> ErrorKind {
match self {
VanguardMgrError::BootstrapRequired { .. } => ErrorKind::BootstrapRequired,
+ VanguardMgrError::LayerNotSupported { .. } => ErrorKind::BadApiUsage,
// TODO HS-VANGUARDS: this is not right
VanguardMgrError::NoSuitableRelay(_) => ErrorKind::Other,
VanguardMgrError::NetDir(e) => e.kind(),