From 7ac362eba7b51e9631d265f6280c12c2b99b8866 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 28 Jun 2023 07:10:37 -0400 Subject: [PATCH] netdir: Conditionally expose some by_rsa APIs as experimental. Network-health wants these to see whether a given relay is listed in the consensus. cc @juga --- Cargo.lock | 1 + crates/tor-netdir/Cargo.toml | 3 ++- crates/tor-netdir/src/lib.rs | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f1e2e669..97e0edd0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4590,6 +4590,7 @@ dependencies = [ "tor-units", "tracing", "typed-index-collections", + "visibility", ] [[package]] diff --git a/crates/tor-netdir/Cargo.toml b/crates/tor-netdir/Cargo.toml index 348d4cdb7..d2e38431f 100644 --- a/crates/tor-netdir/Cargo.toml +++ b/crates/tor-netdir/Cargo.toml @@ -20,7 +20,7 @@ experimental = ["experimental-api", "hs-service", "hs-client", "testing"] # # These APIs are not covered by semantic versioning. Using this # feature voids your "semver warrantee". -experimental-api = ["__is_experimental"] +experimental-api = ["visibility", "__is_experimental"] hs-client = ["hs-common", "__is_experimental"] hs-service = ["hs-common", "__is_experimental"] hs-common = ["digest", "hex", "time", "tor-hscrypto"] @@ -72,6 +72,7 @@ tor-protover = { path = "../tor-protover", version = "0.5.1" } tor-units = { path = "../tor-units", version = "0.6.1" } tracing = "0.1.36" typed-index-collections = "3.1" +visibility = { version = "0.0.1", optional = true } [dev-dependencies] float_eq = "1.0.0" diff --git a/crates/tor-netdir/src/lib.rs b/crates/tor-netdir/src/lib.rs index 9b0c2e18b..3ed557975 100644 --- a/crates/tor-netdir/src/lib.rs +++ b/crates/tor-netdir/src/lib.rs @@ -1051,7 +1051,13 @@ impl NetDir { } /// Return a (possibly unusable) relay with a given RSA identity. + /// + /// This API can be used to find information about a relay that is listed in + /// the current consensus, even if we don't yet have enough information + /// (like a microdescriptor) about the relay to use it. #[allow(clippy::missing_panics_doc)] // Can't panic on valid object. + #[cfg_attr(feature = "experimental-api", visibility::make(pub))] + #[cfg_attr(docsrs, doc(cfg(feature = "experimental-api")))] fn by_rsa_id_unchecked(&self, rsa_id: &RsaIdentity) -> Option> { let rsidx = *self.rsidx_by_rsa.get(rsa_id)?; let rs = self.c_relays().get(rsidx).expect("Corrupt index"); @@ -1063,8 +1069,13 @@ impl NetDir { fn by_rsa_id(&self, rsa_id: &RsaIdentity) -> Option> { self.by_rsa_id_unchecked(rsa_id)?.into_relay() } - /// Return true if `rsa_id` is listed in this directory, even if it - /// isn't currently usable. + /// Return true if `rsa_id` is listed in this directory, even if it isn't + /// currently usable. + /// + /// (An "unusable" relay in this context is one for which we don't have full + /// directory information.) + #[cfg_attr(feature = "experimental-api", visibility::make(pub))] + #[cfg_attr(docsrs, doc(cfg(feature = "experimental-api")))] fn rsa_id_is_listed(&self, rsa_id: &RsaIdentity) -> bool { self.by_rsa_id_unchecked(rsa_id).is_some() }