diff options
| -rw-r--r-- | mullvad-daemon/src/migrations/v9.rs | 59 |
1 files changed, 3 insertions, 56 deletions
diff --git a/mullvad-daemon/src/migrations/v9.rs b/mullvad-daemon/src/migrations/v9.rs index 36ac89ed6d..91aac7e53b 100644 --- a/mullvad-daemon/src/migrations/v9.rs +++ b/mullvad-daemon/src/migrations/v9.rs @@ -84,64 +84,11 @@ pub fn migrate( } } - migrate_tunnel_type(settings)?; + json_blob["settings_version"] = serde_json::json!(SettingsVersion::V10); - // TODO: Uncomment this when closing the migration: - // json_blob["settings_version"] = serde_json::json!(SettingsVersion::V10); - - Ok(()) -} - -fn migrate_tunnel_type(settings: &mut serde_json::Value) -> Result<()> { - let Some(ref mut normal) = relay_settings(settings) else { - return Ok(()); - }; - match normal.get_mut("tunnel_protocol") { - // Already migrated - Some(serde_json::Value::String(s)) if s == "any" => { - // If openvpn is selected, migrate to openvpn tunnel type - // Otherwise, select wireguard - let hostname = normal - .get_mut("location") - .and_then(|location| location.get_mut("only")) - .and_then(|only| only.get_mut("location")) - .and_then(|only| only.get_mut("hostname").cloned()); - - let protocol = if let Some(serde_json::Value::String(s)) = hostname { - if s.split('-').any(|token| token == "ovpn") { - TunnelType::OpenVpn - } else { - TunnelType::Wireguard - } - } else { - TunnelType::Wireguard - }; - - normal["tunnel_protocol"] = serde_json::json!(protocol); - } - // Migrate - Some(serde_json::Value::Object(ref mut constraint)) => { - if let Some(tunnel_type) = constraint.get("only") { - let tunnel_type: TunnelType = serde_json::from_value(tunnel_type.clone()) - .map_err(|_| Error::InvalidSettingsContent)?; - normal["tunnel_protocol"] = serde_json::json!(tunnel_type); - } else { - return Err(Error::InvalidSettingsContent); - } - } - Some(_) => { - return Err(Error::InvalidSettingsContent); - } - // Unexpected result. Do nothing. - None => (), - } Ok(()) } -fn relay_settings(settings: &mut serde_json::Value) -> Option<&mut serde_json::Value> { - settings.get_mut("relay_settings")?.get_mut("normal") -} - fn version_matches(settings: &serde_json::Value) -> bool { settings .get("settings_version") @@ -644,7 +591,7 @@ mod test { }, "providers": "any", "ownership": "any", - "tunnel_protocol": "openvpn", + "tunnel_protocol": "any", "wireguard_constraints": { "port": "any", "ip_version": "any", @@ -732,7 +679,7 @@ mod test { }, "relay_overrides": [], "show_beta_releases": true, - "settings_version": 9 + "settings_version": 10 } "#; } |
