diff options
| -rw-r--r-- | crates/arti-client/Cargo.toml | 3 | ||||
| -rw-r--r-- | crates/arti/Cargo.toml | 2 | ||||
| -rw-r--r-- | crates/tor-circmgr/Cargo.toml | 6 | ||||
| -rw-r--r-- | crates/tor-circmgr/src/hspool.rs | 12 | ||||
| -rw-r--r-- | crates/tor-guardmgr/Cargo.toml | 7 | ||||
| -rw-r--r-- | crates/tor-guardmgr/src/vanguards.rs | 10 | ||||
| -rw-r--r-- | crates/tor-guardmgr/src/vanguards/set.rs | 36 | ||||
| -rw-r--r-- | crates/tor-relay-selection/Cargo.toml | 14 |
8 files changed, 62 insertions, 28 deletions
diff --git a/crates/arti-client/Cargo.toml b/crates/arti-client/Cargo.toml index dcd237686..aaa70f20f 100644 --- a/crates/arti-client/Cargo.toml +++ b/crates/arti-client/Cargo.toml @@ -18,6 +18,7 @@ full = [ "keymgr", "onion-service-client", "onion-service-service", + "vanguards", "tokio", "async-std", "native-tls", @@ -77,6 +78,7 @@ accel-openssl = ["tor-llcrypto/with-openssl", "__is_nonadditive"] onion-service-client = ["tor-hsclient", "tor-hscrypto"] onion-service-service = ["tor-hsservice", "tor-hscrypto", "tor-persist/state-dir", "keymgr"] keymgr = ["tor-keymgr/keymgr", "tor-hsclient/keymgr"] +vanguards = ["tor-guardmgr/vanguards", "tor-circmgr/vanguards"] __is_nonadditive = [] @@ -107,7 +109,6 @@ error_detail = ["__is_experimental"] geoip = ["tor-circmgr/geoip", "tor-dirmgr/geoip", "tor-geoip", "__is_experimental"] rpc = ["tor-rpcbase", "__is_experimental"] __is_experimental = [] -vanguards = ["tor-guardmgr/vanguards", "tor-circmgr/vanguards", "__is_experimental"] [dependencies] anyhow = { version = "1.0.23", optional = true } diff --git a/crates/arti/Cargo.toml b/crates/arti/Cargo.toml index 5afc5368e..96b0cea74 100644 --- a/crates/arti/Cargo.toml +++ b/crates/arti/Cargo.toml @@ -21,11 +21,13 @@ default = [ "bridge-client", "pt-client", "onion-service-client", + "vanguards", ] full = [ "onion-service-client", "onion-service-service", + "vanguards", "async-std", "tokio", "native-tls", diff --git a/crates/tor-circmgr/Cargo.toml b/crates/tor-circmgr/Cargo.toml index 2348ed387..8849b9d0d 100644 --- a/crates/tor-circmgr/Cargo.toml +++ b/crates/tor-circmgr/Cargo.toml @@ -18,6 +18,7 @@ full = [ "hs-client", "hs-service", "specific-relay", + "vanguards", "retry-error/full", "safelog/full", "tor-basic-utils/full", @@ -36,18 +37,17 @@ full = [ "tor-protover/full", "tor-relay-selection/full", ] specific-relay = [] +vanguards = ["tor-guardmgr/vanguards"] # Enable testing-only APIs. APIs under this feature are not # covered by semver. testing = ["tor-guardmgr/testing", "__is_experimental"] -# Vanguards are experimental -vanguards = ["tor-guardmgr/vanguards", "__is_experimental"] # Enable experimental APIs that are not yet officially supported. # # These APIs are not covered by semantic versioning. Using this # feature voids your "semver warrantee". -experimental = ["experimental-api", "ntor_v3", "testing", "geoip", "vanguards"] +experimental = ["experimental-api", "ntor_v3", "testing", "geoip"] geoip = ["tor-geoip", "tor-netdir/geoip", "tor-relay-selection/geoip", "__is_experimental"] experimental-api = ["visibility", "__is_experimental"] ntor_v3 = ["tor-proto/ntor_v3", "__is_experimental"] diff --git a/crates/tor-circmgr/src/hspool.rs b/crates/tor-circmgr/src/hspool.rs index 5c6076d2a..ace838e22 100644 --- a/crates/tor-circmgr/src/hspool.rs +++ b/crates/tor-circmgr/src/hspool.rs @@ -599,11 +599,13 @@ async fn launch_hs_circuits_as_needed<R: Runtime>( let n_to_launch = circs_to_launch.n_to_launch(); let mut max_attempts = n_to_launch * 2; - debug!( - "launching {} STUB and {} STUB+ circuits", - circs_to_launch.stub(), - circs_to_launch.ext_stub() - ); + if n_to_launch > 0 { + debug!( + "launching {} STUB and {} STUB+ circuits", + circs_to_launch.stub(), + circs_to_launch.ext_stub() + ); + } // TODO: refactor this to launch the circuits in parallel 'inner: while circs_to_launch.n_to_launch() > 0 { diff --git a/crates/tor-guardmgr/Cargo.toml b/crates/tor-guardmgr/Cargo.toml index 683f792e2..573912145 100644 --- a/crates/tor-guardmgr/Cargo.toml +++ b/crates/tor-guardmgr/Cargo.toml @@ -16,6 +16,7 @@ default = [] full = [ "bridge-client", "pt-client", + "vanguards", "safelog/full", "tor-basic-utils/full", "tor-config/full", @@ -31,7 +32,7 @@ full = [ "tor-units/full", "tor-async-utils/full", "tor-relay-selection/full", ] -experimental = ["testing", "vanguards"] +experimental = ["testing"] # Support for using bridges as a client. Note that this is not the same as # the pt-client feature, since here we are not concerned with @@ -39,12 +40,12 @@ experimental = ["testing", "vanguards"] bridge-client = ["tor-netdoc/routerdesc", "tor-protover"] # Support for pluggable transports. pt-client = ["bridge-client", "tor-linkspec/pt-client"] +# Vanguards support +vanguards = ["tor-relay-selection/vanguards"] # Enable testing-only APIs. APIs under this feature are not # covered by semver. testing = ["tor-netdir/testing", "__is_experimental"] -# Vanguards support -vanguards = ["tor-relay-selection/vanguards", "__is_experimental"] __is_experimental = [] diff --git a/crates/tor-guardmgr/src/vanguards.rs b/crates/tor-guardmgr/src/vanguards.rs index 12925686f..5d8f5d401 100644 --- a/crates/tor-guardmgr/src/vanguards.rs +++ b/crates/tor-guardmgr/src/vanguards.rs @@ -460,13 +460,15 @@ impl<R: Runtime> VanguardMgr<R> { netdir_provider: &Arc<dyn NetDirProvider>, now: SystemTime, ) -> Result<Option<Duration>, VanguardMgrError> { - info!("Rotating vanguards"); - let mut inner = self.inner.write().expect("poisoned lock"); let inner = &mut *inner; let vanguard_sets = &mut inner.vanguard_sets; - vanguard_sets.remove_expired(now); + let expired_count = vanguard_sets.remove_expired(now); + + if expired_count > 0 { + info!("Rotating vanguards"); + } if let Some(netdir) = Self::timely_netdir(netdir_provider)? { // If we have a NetDir, replenish the vanguard sets that don't have enough vanguards. @@ -548,7 +550,7 @@ impl Inner { match self.mode { VanguardMode::Lite | VanguardMode::Disabled => Ok(()), VanguardMode::Full => { - debug!("The vanguards have changed; flushing vanguards to vanguard state file"); + debug!("The vanguards may have changed; flushing to vanguard state file"); Ok(storage.store(&self.vanguard_sets)?) } } diff --git a/crates/tor-guardmgr/src/vanguards/set.rs b/crates/tor-guardmgr/src/vanguards/set.rs index f650d70cf..8170f9b51 100644 --- a/crates/tor-guardmgr/src/vanguards/set.rs +++ b/crates/tor-guardmgr/src/vanguards/set.rs @@ -106,9 +106,13 @@ impl VanguardSets { } /// Remove the vanguards that are expired at the specified timestamp. - pub(super) fn remove_expired(&mut self, now: SystemTime) { - self.l2_vanguards.remove_expired(now); - self.l3_vanguards.remove_expired(now); + /// + /// Returns the number of vanguards that were removed. + pub(super) fn remove_expired(&mut self, now: SystemTime) -> usize { + let l2_expired = self.l2_vanguards.remove_expired(now); + let l3_expired = self.l3_vanguards.remove_expired(now); + + l2_expired + l3_expired } /// Remove the vanguards that are no longer listed in `netdir`. @@ -305,8 +309,10 @@ impl VanguardSet { } /// Remove the vanguards that are no longer listed in `netdir` - fn remove_unlisted(&mut self, netdir: &NetDir) { - self.vanguards.retain(|v| { + /// + /// Returns the number of vanguards that were unlisted. + fn remove_unlisted(&mut self, netdir: &NetDir) -> usize { + self.retain(|v| { let cond = netdir.ids_listed(&v.id) != Some(false); if !cond { @@ -314,12 +320,14 @@ impl VanguardSet { } cond - }); + }) } /// Remove the vanguards that are expired at the specified timestamp. - fn remove_expired(&mut self, now: SystemTime) { - self.vanguards.retain(|v| { + /// + /// Returns the number of vanguards that expired. + fn remove_expired(&mut self, now: SystemTime) -> usize { + self.retain(|v| { let cond = v.when > now; if !cond { @@ -327,7 +335,17 @@ impl VanguardSet { } cond - }); + }) + } + + /// A wrapper around [`Vec::retain`] that returns the number of discarded elements. + fn retain<F>(&mut self, f: F) -> usize + where + F: FnMut(&TimeBoundVanguard) -> bool, + { + let old_len = self.vanguards.len(); + self.vanguards.retain(f); + old_len - self.vanguards.len() } /// Find the timestamp of the vanguard that is due to expire next. diff --git a/crates/tor-relay-selection/Cargo.toml b/crates/tor-relay-selection/Cargo.toml index 200ac4b89..1970ae081 100644 --- a/crates/tor-relay-selection/Cargo.toml +++ b/crates/tor-relay-selection/Cargo.toml @@ -13,11 +13,19 @@ repository = "https://gitlab.torproject.org/tpo/core/arti.git/" [features] default = [] -full = ["tor-basic-utils/full", "tor-geoip?/full", "tor-linkspec/full", "tor-netdir/full", "tor-netdoc/full"] +full = [ + "vanguards", + "tor-basic-utils/full", + "tor-geoip?/full", + "tor-linkspec/full", + "tor-netdir/full", + "tor-netdoc/full", +] -experimental = ["geoip", "vanguards"] -geoip = ["tor-geoip", "tor-netdir/geoip", "__is_experimental"] vanguards = [] + +experimental = ["geoip"] +geoip = ["tor-geoip", "tor-netdir/geoip", "__is_experimental"] __is_experimental = [] [dependencies] |
