diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2018-07-09 13:29:00 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2018-07-10 14:44:23 +0200 |
| commit | b64175fe5f8aaaa371ae91cbf082594e872c6a85 (patch) | |
| tree | 49a6197ee692e660ad19c85d20a89e15f26b0eb7 | |
| parent | 2a3eef5c14a6d13670ebc503b5b0eda4e2e51df3 (diff) | |
| download | mullvadvpn-b64175fe5f8aaaa371ae91cbf082594e872c6a85.tar.xz mullvadvpn-b64175fe5f8aaaa371ae91cbf082594e872c6a85.zip | |
Add autoconnect setting
| -rw-r--r-- | mullvad-daemon/src/main.rs | 4 | ||||
| -rw-r--r-- | mullvad-daemon/src/settings.rs | 18 |
2 files changed, 21 insertions, 1 deletions
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index abfc83b764..d306aaf747 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -334,6 +334,10 @@ impl Daemon { /// Consume the `Daemon` and run the main event loop. Blocks until an error happens or a /// shutdown event is received. pub fn run(mut self) -> Result<()> { + if self.settings.get_autoconnect() { + info!("Automatically connecting since autoconnect is turned on"); + self.set_target_state(TargetState::Secured)?; + } while let Ok(event) = self.rx.recv() { self.handle_event(event)?; if self.shutdown && self.state == TunnelState::NotRunning { diff --git a/mullvad-daemon/src/settings.rs b/mullvad-daemon/src/settings.rs index 4622db15ce..b11b80017a 100644 --- a/mullvad-daemon/src/settings.rs +++ b/mullvad-daemon/src/settings.rs @@ -35,8 +35,10 @@ static SETTINGS_FILE: &str = "settings.json"; pub struct Settings { account_token: Option<String>, relay_settings: RelaySettings, - /// If the app should allow communication with private (LAN) networks. + /// If the daemon should allow communication with private (LAN) networks. allow_lan: bool, + /// If the daemon should connect the VPN tunnel directly on start or not. + auto_connect: bool, /// Options that should be applied to tunnels of a specific type regardless of where the relays /// might be located. tunnel_options: TunnelOptions, @@ -51,6 +53,7 @@ impl Default for Settings { tunnel: Constraint::Any, }), allow_lan: false, + auto_connect: false, tunnel_options: TunnelOptions::default(), } } @@ -155,6 +158,19 @@ impl Settings { } } + pub fn get_auto_connect(&self) -> bool { + self.auto_connect + } + + pub fn set_auto_connect(&mut self, auto_connect: bool) -> Result<bool> { + if auto_connect != self.auto_connect { + self.auto_connect = auto_connect; + self.save().map(|_| true) + } else { + Ok(false) + } + } + pub fn set_openvpn_mssfix(&mut self, openvpn_mssfix: Option<u16>) -> Result<bool> { if self.tunnel_options.openvpn.mssfix != openvpn_mssfix { self.tunnel_options.openvpn.mssfix = openvpn_mssfix; |
