summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorEmīls <Emīls>2024-09-28 01:42:50 +0200
committerMarkus Pettersson <markus.pettersson@mullvad.net>2024-10-01 12:31:08 +0200
commit8c8ce4ed143581433119f671f18e012dbe100a1a (patch)
tree9abc5b8d6d5890847ae32434b6d2950da53f360e
parent238bda7f5c621c6094d5f3feabc92c39a02132f7 (diff)
downloadmullvadvpn-8c8ce4ed143581433119f671f18e012dbe100a1a.tar.xz
mullvadvpn-8c8ce4ed143581433119f671f18e012dbe100a1a.zip
Simplify configuration selection for encrypted dns
-rw-r--r--mullvad-ios/src/encrypted_dns_proxy.rs29
1 files changed, 13 insertions, 16 deletions
diff --git a/mullvad-ios/src/encrypted_dns_proxy.rs b/mullvad-ios/src/encrypted_dns_proxy.rs
index a761df4cd9..d0380c189e 100644
--- a/mullvad-ios/src/encrypted_dns_proxy.rs
+++ b/mullvad-ios/src/encrypted_dns_proxy.rs
@@ -82,29 +82,26 @@ impl EncryptedDnsProxyState {
if self.should_reset() {
self.reset();
}
+
// TODO: currently, the randomized order of proxy config retrieval depends on the random
// iteration order of a given HashSet instance. Since for now, there will be only 2
// different configurations, it barely matters. In the future, we should use `rand`
// instead, so that the behavior is explicit and clear.
+ let selected_config = {
+ // First, create an iterator for the difference between all configs and tried configs.
+ let mut difference = self.configurations.difference(&self.tried_configurations);
+ // Pick the first configuration if there are any. If there are none, one can only assume
+ // that the configuration set is empty, so an early return is fine.
+ let first_config = difference.next()?;
+ // See if there are any unused obfuscated configurations in the rest of the set.
+ let obfuscated_config = difference.find(|config| config.obfuscation.is_some());
- // First, try getting an obfuscated configuration, if there exist any.
- let config = if let Some(obfuscated_config) = self
- .configurations
- .difference(&self.tried_configurations)
- .find(|config| config.obfuscation.is_some())
- .cloned()
- {
- obfuscated_config
- } else {
- // If no obfuscated configurations exist, try the next untried configuration.
- self.configurations
- .difference(&self.tried_configurations)
- .next()
- .cloned()?
+ // If there is an obfuscated configuration, use that. Otherwise, use the first one.
+ obfuscated_config.unwrap_or(first_config).clone()
};
- self.tried_configurations.insert(config.clone());
- Some(config)
+ self.tried_configurations.insert(selected_config.clone());
+ Some(selected_config)
}
/// Fetch a config, but error out only when no existing configuration was there.