diff options
author | Nick Mathewson <nickm@torproject.org> | 2024-03-06 12:12:52 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2024-03-12 09:43:14 -0400 |
commit | f4cd271879ae23361fa0e0c64b0fc8d016a77503 (patch) | |
tree | 173477e74a8007f0ac7601ee4010c3476b5dbba3 | |
parent | cfb2ec7b4eb1817625fb4ed0916673b4b84f27eb (diff) | |
download | arti-f4cd271879ae23361fa0e0c64b0fc8d016a77503.tar.gz arti-f4cd271879ae23361fa0e0c64b0fc8d016a77503.zip |
ipt_mgr: convert to use RelaySelector.
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | crates/tor-hsservice/Cargo.toml | 6 | ||||
-rw-r--r-- | crates/tor-hsservice/src/ipt_mgr.rs | 27 |
3 files changed, 23 insertions, 11 deletions
diff --git a/Cargo.lock b/Cargo.lock index 7e5d051e9..72c476e01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5501,6 +5501,7 @@ dependencies = [ "tor-persist", "tor-proto", "tor-protover", + "tor-relay-selection", "tor-rtcompat", "tor-rtmock", "tor-units", diff --git a/crates/tor-hsservice/Cargo.toml b/crates/tor-hsservice/Cargo.toml index c377520bb..c71f5a0b8 100644 --- a/crates/tor-hsservice/Cargo.toml +++ b/crates/tor-hsservice/Cargo.toml @@ -34,7 +34,10 @@ full = [ "tor-linkspec/full", "tor-netdoc/full", "tor-units/full", - "tor-persist/full", "tor-protover/full", "fs-mistrust/full", "tor-log-ratelim/full", + "tor-persist/full", + "tor-protover/full", + "fs-mistrust/full", + "tor-log-ratelim/full", ] [dependencies] @@ -86,6 +89,7 @@ tor-proto = { version = "0.16.1", path = "../tor-proto", features = [ "send-control-msg", ] } tor-protover = { version = "0.6.0", path = "../tor-protover" } +tor-relay-selection = { path = "../tor-relay-selection", version = "0.0.1" } tor-rtcompat = { version = "0.10.0", path = "../tor-rtcompat" } tor-units = { path = "../tor-units", version = "0.6.5" } tracing = "0.1.36" diff --git a/crates/tor-hsservice/src/ipt_mgr.rs b/crates/tor-hsservice/src/ipt_mgr.rs index e81c02e94..45cac77db 100644 --- a/crates/tor-hsservice/src/ipt_mgr.rs +++ b/crates/tor-hsservice/src/ipt_mgr.rs @@ -7,6 +7,7 @@ use crate::internal_prelude::*; +use tor_relay_selection::{RelayExclusion, RelaySelector, RelayUsage}; use IptStatusStatus as ISS; use TrackedStatus as TS; @@ -1609,16 +1610,22 @@ impl<R: Runtime, M: Mockable<R>> State<R, M> { let mut rng = self.mockable.thread_rng(); - let relay = netdir - // TODO #504 - .pick_relay(&mut rng, tor_netdir::WeightRole::HsIntro, |new| { - new.is_hs_intro_point() - && !self - .irelays - .iter() - .any(|existing| new.has_any_relay_id_from(&existing.relay)) - }) - .ok_or(ChooseIptError::TooFewUsableRelays)?; + let relay = { + let exclude_ids = self + .irelays + .iter() + .flat_map(|e| e.relay.identities()) + .map(|id| id.to_owned()) + .collect(); + let selector = RelaySelector::new( + RelayUsage::new_intro_point(), + RelayExclusion::exclude_identities(exclude_ids), + ); + selector + .select_relay(&mut rng, &netdir) + .0 // TODO: Someday we might want to report why we rejected everything on failure. + .ok_or(ChooseIptError::TooFewUsableRelays)? + }; let lifetime_low = netdir .params() |