From 04bcf69749fbc0c1b228700ac4534949f2acfbb5 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 3 Nov 2022 10:55:29 -0400 Subject: [PATCH] GuardMgr: Clarify intent with update_active_set. Also fix its behavior when using bridges. --- crates/tor-guardmgr/src/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/tor-guardmgr/src/lib.rs b/crates/tor-guardmgr/src/lib.rs index 2cf816b6f..525c01434 100644 --- a/crates/tor-guardmgr/src/lib.rs +++ b/crates/tor-guardmgr/src/lib.rs @@ -762,7 +762,7 @@ impl GuardMgrInner { Err(e) => warn!("Unusable guard parameters from consensus: {}", e), } - self.select_guard_set(netdir); + self.select_guard_set_based_on_filter(netdir); } // Change the filter, if it doesn't match what the guards have. @@ -819,8 +819,7 @@ impl GuardMgrInner { /// /// After calling this function, the new guard set's filter may be /// out-of-date: be sure to call `set_filter` as appropriate. - fn select_guard_set(&mut self, netdir: &NetDir) { - let frac_permitted = self.filter.frac_bw_permitted(netdir); + fn select_guard_set_based_on_filter(&mut self, netdir: &NetDir) { // In general, we'd like to use the restricted set if we're under the // threshold, and the default set if we're over the threshold. But if // we're sitting close to the threshold, we want to avoid flapping back @@ -831,9 +830,11 @@ impl GuardMgrInner { let offset = match self.guards.active_set { GuardSetSelector::Default => -0.05, GuardSetSelector::Restricted => 0.05, + // If we're using bridges, then we don't switch between the other guard sets based on on the filter at all. #[cfg(feature = "bridge-client")] - GuardSetSelector::Bridges => todo!(), // TODO pt-client + GuardSetSelector::Bridges => return, }; + let frac_permitted = self.filter.frac_bw_permitted(netdir); let threshold = self.params.filter_threshold + offset; let new_choice = if frac_permitted < threshold { GuardSetSelector::Restricted