summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <faern@faern.net>2022-01-11 09:50:10 +0100
committerLinus Färnstrand <linus@mullvad.net>2022-01-11 13:24:02 +0100
commit94df8f8311dd6d801ff4d6950164520cde14a212 (patch)
tree9f36bc654dff04e88fca20df19850bc6b8a8b949
parent23253a25e6130bbf888624406d02e4fdfdfdf637 (diff)
downloadmullvadvpn-94df8f8311dd6d801ff4d6950164520cde14a212.tar.xz
mullvadvpn-94df8f8311dd6d801ff4d6950164520cde14a212.zip
Make settings migrations not depend on types that can change
-rw-r--r--mullvad-daemon/src/migrations/mod.rs21
-rw-r--r--mullvad-daemon/src/migrations/v1.rs17
-rw-r--r--mullvad-daemon/src/migrations/v2.rs10
-rw-r--r--mullvad-daemon/src/migrations/v3.rs50
-rw-r--r--mullvad-daemon/src/migrations/v4.rs30
5 files changed, 118 insertions, 10 deletions
diff --git a/mullvad-daemon/src/migrations/mod.rs b/mullvad-daemon/src/migrations/mod.rs
index 2e20e3cc36..04d23e457d 100644
--- a/mullvad-daemon/src/migrations/mod.rs
+++ b/mullvad-daemon/src/migrations/mod.rs
@@ -1,3 +1,24 @@
+//! Code for migrating between different versions of the settings.
+//! Migration only supports migrating forward, to newer formats.
+//!
+//! A settings migration module is responsible for converting
+//! from its own version to the next version. So `v3::migrate`
+//! migrates from settings version `V3` to `V4` etc.
+//!
+//! Migration modules may NOT import and use structs that may
+//! change. Because then a later change to the current code can break
+//! old migrations. The only items a settings migration module may import
+//! are anything from `std` plus the following:
+//!
+//! ```ignore
+//! use super::{Error, Result};
+//! use mullvad_types::relay_constraints::Constraint;
+//! use mullvad_types::settings::SettingsVersion;
+//! ```
+//!
+//! Any other type must be vendored into the migration module so the format
+//! it has is locked over time.
+
use std::path::Path;
use tokio::{
fs,
diff --git a/mullvad-daemon/src/migrations/v1.rs b/mullvad-daemon/src/migrations/v1.rs
index 82b6df3935..7f2a656c04 100644
--- a/mullvad-daemon/src/migrations/v1.rs
+++ b/mullvad-daemon/src/migrations/v1.rs
@@ -1,6 +1,21 @@
use super::Result;
use mullvad_types::{relay_constraints::Constraint, settings::SettingsVersion};
-use talpid_types::net::TunnelType;
+
+// ======================================================
+// Section for vendoring types and values that
+// this settings version depend on. See `mod.rs`.
+
+/// The tunnel protocol used by a [`TunnelEndpoint`].
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
+#[serde(rename = "tunnel_type")]
+pub enum TunnelType {
+ #[serde(rename = "openvpn")]
+ OpenVpn,
+ #[serde(rename = "wireguard")]
+ Wireguard,
+}
+
+// ======================================================
pub fn migrate(settings: &mut serde_json::Value) -> Result<()> {
if !version_matches(settings) {
diff --git a/mullvad-daemon/src/migrations/v2.rs b/mullvad-daemon/src/migrations/v2.rs
index 46973f06b7..585bc16cc1 100644
--- a/mullvad-daemon/src/migrations/v2.rs
+++ b/mullvad-daemon/src/migrations/v2.rs
@@ -1,8 +1,16 @@
use super::{Error, Result};
-use crate::wireguard::{MAX_ROTATION_INTERVAL, MIN_ROTATION_INTERVAL};
use mullvad_types::settings::SettingsVersion;
use std::time::Duration;
+// ======================================================
+// Section for vendoring types and values that
+// this settings version depend on. See `mod.rs`.
+
+pub const MIN_ROTATION_INTERVAL: Duration = Duration::from_secs(1 * 24 * 60 * 60);
+pub const MAX_ROTATION_INTERVAL: Duration = Duration::from_secs(7 * 24 * 60 * 60);
+
+// ======================================================
+
pub fn migrate(settings: &mut serde_json::Value) -> Result<()> {
if !version_matches(settings) {
return Ok(());
diff --git a/mullvad-daemon/src/migrations/v3.rs b/mullvad-daemon/src/migrations/v3.rs
index b7f12f6714..6baa255538 100644
--- a/mullvad-daemon/src/migrations/v3.rs
+++ b/mullvad-daemon/src/migrations/v3.rs
@@ -1,7 +1,51 @@
use super::{Error, Result};
-use mullvad_types::settings::{
- CustomDnsOptions, DefaultDnsOptions, DnsOptions, DnsState, SettingsVersion,
-};
+use mullvad_types::settings::SettingsVersion;
+use std::net::IpAddr;
+
+// ======================================================
+// Section for vendoring types and values that
+// this settings version depend on. See `mod.rs`.
+
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
+#[serde(rename_all = "snake_case")]
+pub enum DnsState {
+ Default,
+ Custom,
+}
+
+impl Default for DnsState {
+ fn default() -> Self {
+ Self::Default
+ }
+}
+
+/// DNS config
+#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
+#[cfg_attr(target_os = "android", derive(IntoJava))]
+#[cfg_attr(target_os = "android", jnix(package = "net.mullvad.mullvadvpn.model"))]
+pub struct DnsOptions {
+ #[cfg_attr(target_os = "android", jnix(map = "|state| state == DnsState::Custom"))]
+ pub state: DnsState,
+ #[cfg_attr(target_os = "android", jnix(skip))]
+ pub default_options: DefaultDnsOptions,
+ #[cfg_attr(target_os = "android", jnix(map = "|opts| opts.addresses"))]
+ pub custom_options: CustomDnsOptions,
+}
+
+/// Default DNS config
+#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
+pub struct DefaultDnsOptions {
+ pub block_ads: bool,
+ pub block_trackers: bool,
+}
+
+/// Custom DNS config
+#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
+pub struct CustomDnsOptions {
+ pub addresses: Vec<IpAddr>,
+}
+
+// ======================================================
pub fn migrate(settings: &mut serde_json::Value) -> Result<()> {
if !version_matches(settings) {
diff --git a/mullvad-daemon/src/migrations/v4.rs b/mullvad-daemon/src/migrations/v4.rs
index 865b4bbfa6..f6f6a9e0de 100644
--- a/mullvad-daemon/src/migrations/v4.rs
+++ b/mullvad-daemon/src/migrations/v4.rs
@@ -1,13 +1,33 @@
use super::{Error, Result};
-use mullvad_types::{
- relay_constraints::{Constraint, TransportPort},
- settings::SettingsVersion,
-};
-use talpid_types::net::TransportProtocol;
+use mullvad_types::{relay_constraints::Constraint, settings::SettingsVersion};
+
+// ======================================================
+// Section for vendoring types and values that
+// this settings version depend on. See `mod.rs`.
const WIREGUARD_TCP_PORTS: [u16; 3] = [80, 443, 5001];
const OPENVPN_TCP_PORTS: [u16; 2] = [80, 443];
+/// Representation of a transport protocol, either UDP or TCP.
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+#[cfg_attr(target_os = "android", derive(IntoJava))]
+#[cfg_attr(target_os = "android", jnix(package = "net.mullvad.talpid.net"))]
+pub enum TransportProtocol {
+ /// Represents the UDP transport protocol.
+ Udp,
+ /// Represents the TCP transport protocol.
+ Tcp,
+}
+
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Deserialize, Serialize)]
+pub struct TransportPort {
+ pub protocol: TransportProtocol,
+ pub port: Constraint<u16>,
+}
+
+// ======================================================
+
pub fn migrate(settings: &mut serde_json::Value) -> Result<()> {
if !version_matches(settings) {
return Ok(());