diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2019-04-23 16:28:26 +0200 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2019-05-27 15:42:41 +0100 |
| commit | aa87c0817d15d3b146d37157ba7ec559f63736e7 (patch) | |
| tree | 6a56687953abc128271fd5af091d19d516ed90c1 | |
| parent | 595ab0a33b0e962a9948dc85b0c3b101b976bed8 (diff) | |
| download | mullvadvpn-aa87c0817d15d3b146d37157ba7ec559f63736e7.tar.xz mullvadvpn-aa87c0817d15d3b146d37157ba7ec559f63736e7.zip | |
Add BridgeSettings and default value
| -rw-r--r-- | mullvad-types/src/relay_constraints.rs | 33 | ||||
| -rw-r--r-- | mullvad-types/src/settings.rs | 35 |
2 files changed, 64 insertions, 4 deletions
diff --git a/mullvad-types/src/relay_constraints.rs b/mullvad-types/src/relay_constraints.rs index ba40243718..47170adfef 100644 --- a/mullvad-types/src/relay_constraints.rs +++ b/mullvad-types/src/relay_constraints.rs @@ -5,7 +5,7 @@ use crate::{ }; use serde::{Deserialize, Serialize}; use std::fmt; -use talpid_types::net::TransportProtocol; +use talpid_types::net::{openvpn::ProxySettings, TransportProtocol}; pub trait Match<T> { @@ -87,7 +87,6 @@ impl RelaySettings { } #[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)] -#[serde(rename_all = "snake_case")] pub struct RelayConstraints { pub location: Constraint<LocationConstraint>, pub tunnel: Constraint<TunnelConstraints>, @@ -140,7 +139,6 @@ impl fmt::Display for LocationConstraint { } } - #[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)] pub enum TunnelConstraints { #[serde(rename = "openvpn")] @@ -235,6 +233,35 @@ impl Match<WireguardEndpointData> for WireguardConstraints { } +#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)] +#[serde(rename_all = "snake_case")] +pub enum BridgeSettings { + /// Let the relay selection algorithm decide on bridges, based on the relay list. + Normal(BridgeConstraints), + Custom(ProxySettings), +} + + +#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)] +#[serde(rename_all = "snake_case")] +pub struct BridgeConstraints { + pub location: Constraint<LocationConstraint>, +} + +#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)] +#[serde(rename_all = "snake_case")] +pub enum BridgeState { + Auto, + On, + Off, +} + +#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)] +pub struct InternalBridgeConstraints { + pub location: Constraint<LocationConstraint>, + pub transport_protocol: Constraint<TransportProtocol>, +} + #[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "snake_case")] pub enum RelaySettingsUpdate { diff --git a/mullvad-types/src/settings.rs b/mullvad-types/src/settings.rs index 6a2d678db4..32047d31be 100644 --- a/mullvad-types/src/settings.rs +++ b/mullvad-types/src/settings.rs @@ -1,5 +1,6 @@ use crate::relay_constraints::{ - Constraint, LocationConstraint, RelayConstraints, RelaySettings, RelaySettingsUpdate, + BridgeConstraints, BridgeSettings, BridgeState, Constraint, LocationConstraint, + RelayConstraints, RelaySettings, RelaySettingsUpdate, }; use log::{debug, info}; use serde::{Deserialize, Serialize}; @@ -40,6 +41,8 @@ static SETTINGS_FILE: &str = "settings.json"; pub struct Settings { account_token: Option<String>, relay_settings: RelaySettings, + bridge_settings: BridgeSettings, + bridge_state: BridgeState, /// If the daemon should allow communication with private (LAN) networks. allow_lan: bool, /// Extra level of kill switch. When this setting is on, the disconnected state will block @@ -60,6 +63,10 @@ impl Default for Settings { location: Constraint::Only(LocationConstraint::Country("se".to_owned())), tunnel: Constraint::Any, }), + bridge_settings: BridgeSettings::Normal(BridgeConstraints { + location: Constraint::Any, + }), + bridge_state: BridgeState::Auto, allow_lan: false, block_when_disconnected: false, auto_connect: false, @@ -234,6 +241,32 @@ impl Settings { pub fn get_tunnel_options(&self) -> &TunnelOptions { &self.tunnel_options } + + pub fn get_bridge_settings(&self) -> &BridgeSettings { + &self.bridge_settings + } + + pub fn set_bridge_settings(&mut self, bridge_settings: BridgeSettings) -> Result<bool> { + if self.bridge_settings != bridge_settings { + self.bridge_settings = bridge_settings; + self.save().map(|_| true) + } else { + Ok(false) + } + } + + pub fn get_bridge_state(&self) -> &BridgeState { + &self.bridge_state + } + + pub fn set_bridge_state(&mut self, bridge_state: BridgeState) -> Result<bool> { + if self.bridge_state != bridge_state { + self.bridge_state = bridge_state; + self.save().map(|_| true) + } else { + Ok(false) + } + } } /// TunnelOptions holds configuration data that applies to all kinds of tunnels. |
