diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2018-09-07 13:57:11 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2018-09-08 09:39:17 +0200 |
| commit | 681c37c3752508ed208af1ded1fac575f8e8e20b (patch) | |
| tree | 333d3ebca0ae8b91dbf416222deaea67a74d884c | |
| parent | 7cbaf720cb4f44ac575d07d3c6e124824d003817 (diff) | |
| download | mullvadvpn-681c37c3752508ed208af1ded1fac575f8e8e20b.tar.xz mullvadvpn-681c37c3752508ed208af1ded1fac575f8e8e20b.zip | |
Make management interface and some other stuff infallible
| -rw-r--r-- | mullvad-daemon/src/main.rs | 88 |
1 files changed, 29 insertions, 59 deletions
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index 5610d63e98..1b1297bdc0 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -314,21 +314,19 @@ impl Daemon { fn handle_event(&mut self, event: DaemonEvent) -> Result<()> { use DaemonEvent::*; match event { - TunnelStateTransition(transition) => self.handle_tunnel_state_transition(transition), - ManagementInterfaceEvent(event) => self.handle_management_interface_event(event), + TunnelStateTransition(transition) => { + Ok(self.handle_tunnel_state_transition(transition)) + } + ManagementInterfaceEvent(event) => Ok(self.handle_management_interface_event(event)), ManagementInterfaceExited => self.handle_management_interface_exited(), - TriggerShutdown => self.handle_trigger_shutdown_event(), + TriggerShutdown => Ok(self.handle_trigger_shutdown_event()), } } - fn handle_tunnel_state_transition( - &mut self, - tunnel_state: TunnelStateTransition, - ) -> Result<()> { + fn handle_tunnel_state_transition(&mut self, tunnel_state: TunnelStateTransition) { use self::TunnelStateTransition::*; debug!("New tunnel state: {:?}", tunnel_state); - match tunnel_state { Disconnected => { self.state.disconnected(); @@ -339,35 +337,32 @@ impl Daemon { } self.tunnel_state = tunnel_state; - self.management_interface_broadcaster .notify_new_state(self.tunnel_state); - - Ok(()) } - fn handle_management_interface_event(&mut self, event: ManagementCommand) -> Result<()> { + fn handle_management_interface_event(&mut self, event: ManagementCommand) { use ManagementCommand::*; match event { - SetTargetState(tx, state) => Ok(self.on_set_target_state(tx, state)), - GetState(tx) => Ok(self.on_get_state(tx)), - GetCurrentLocation(tx) => Ok(self.on_get_current_location(tx)), - GetAccountData(tx, account_token) => Ok(self.on_get_account_data(tx, account_token)), - GetRelayLocations(tx) => Ok(self.on_get_relay_locations(tx)), + SetTargetState(tx, state) => self.on_set_target_state(tx, state), + GetState(tx) => self.on_get_state(tx), + GetCurrentLocation(tx) => self.on_get_current_location(tx), + GetAccountData(tx, account_token) => self.on_get_account_data(tx, account_token), + GetRelayLocations(tx) => self.on_get_relay_locations(tx), SetAccount(tx, account_token) => self.on_set_account(tx, account_token), - GetAccount(tx) => Ok(self.on_get_account(tx)), + GetAccount(tx) => self.on_get_account(tx), UpdateRelaySettings(tx, update) => self.on_update_relay_settings(tx, update), SetAllowLan(tx, allow_lan) => self.on_set_allow_lan(tx, allow_lan), - GetAllowLan(tx) => Ok(self.on_get_allow_lan(tx)), + GetAllowLan(tx) => self.on_get_allow_lan(tx), SetAutoConnect(tx, auto_connect) => self.on_set_auto_connect(tx, auto_connect), - GetAutoConnect(tx) => Ok(self.on_get_auto_connect(tx)), + GetAutoConnect(tx) => self.on_get_auto_connect(tx), SetOpenVpnMssfix(tx, mssfix_arg) => self.on_set_openvpn_mssfix(tx, mssfix_arg), SetEnableIpv6(tx, enable_ipv6) => self.on_set_enable_ipv6(tx, enable_ipv6), GetTunnelOptions(tx) => self.on_get_tunnel_options(tx), - GetSettings(tx) => Ok(self.on_get_settings(tx)), - GetRelaySettings(tx) => Ok(self.on_get_relay_settings(tx)), - GetVersionInfo(tx) => Ok(self.on_get_version_info(tx)), - GetCurrentVersion(tx) => Ok(self.on_get_current_version(tx)), + GetSettings(tx) => self.on_get_settings(tx), + GetRelaySettings(tx) => self.on_get_relay_settings(tx), + GetVersionInfo(tx) => self.on_get_version_info(tx), + GetCurrentVersion(tx) => self.on_get_current_version(tx), Shutdown => self.handle_trigger_shutdown_event(), } } @@ -430,11 +425,7 @@ impl Daemon { } - fn on_set_account( - &mut self, - tx: OneshotSender<()>, - account_token: Option<String>, - ) -> Result<()> { + fn on_set_account(&mut self, tx: OneshotSender<()>, account_token: Option<String>) { let account_token_cleared = account_token.is_none(); let save_result = self.settings.set_account_token(account_token); @@ -455,7 +446,6 @@ impl Daemon { } Err(e) => error!("{}", e.display_chain()), } - Ok(()) } fn on_get_version_info( @@ -485,13 +475,8 @@ impl Daemon { Self::oneshot_send(tx, self.settings.get_account_token(), "current account") } - fn on_update_relay_settings( - &mut self, - tx: OneshotSender<()>, - update: RelaySettingsUpdate, - ) -> Result<()> { + fn on_update_relay_settings(&mut self, tx: OneshotSender<()>, update: RelaySettingsUpdate) { let save_result = self.settings.update_relay_settings(update); - match save_result.chain_err(|| "Unable to save settings") { Ok(changed) => { Self::oneshot_send(tx, (), "update_relay_settings response"); @@ -503,15 +488,13 @@ impl Daemon { } Err(e) => error!("{}", e.display_chain()), } - - Ok(()) } fn on_get_relay_settings(&self, tx: OneshotSender<RelaySettings>) { Self::oneshot_send(tx, self.settings.get_relay_settings(), "relay settings") } - fn on_set_allow_lan(&mut self, tx: OneshotSender<()>, allow_lan: bool) -> Result<()> { + fn on_set_allow_lan(&mut self, tx: OneshotSender<()>, allow_lan: bool) { let save_result = self.settings.set_allow_lan(allow_lan); match save_result.chain_err(|| "Unable to save settings") { Ok(settings_changed) => { @@ -524,14 +507,13 @@ impl Daemon { } Err(e) => error!("{}", e.display_chain()), } - Ok(()) } fn on_get_allow_lan(&self, tx: OneshotSender<bool>) { Self::oneshot_send(tx, self.settings.get_allow_lan(), "allow lan") } - fn on_set_auto_connect(&mut self, tx: OneshotSender<()>, auto_connect: bool) -> Result<()> { + fn on_set_auto_connect(&mut self, tx: OneshotSender<()>, auto_connect: bool) { let save_result = self.settings.set_auto_connect(auto_connect); match save_result.chain_err(|| "Unable to save settings") { Ok(settings_changed) => { @@ -543,7 +525,6 @@ impl Daemon { } Err(e) => error!("{}", e.display_chain()), } - Ok(()) } fn on_get_auto_connect(&self, tx: OneshotSender<bool>) { @@ -554,11 +535,7 @@ impl Daemon { ) } - fn on_set_openvpn_mssfix( - &mut self, - tx: OneshotSender<()>, - mssfix_arg: Option<u16>, - ) -> Result<()> { + fn on_set_openvpn_mssfix(&mut self, tx: OneshotSender<()>, mssfix_arg: Option<u16>) { let save_result = self.settings.set_openvpn_mssfix(mssfix_arg); match save_result.chain_err(|| "Unable to save settings") { Ok(settings_changed) => { @@ -569,13 +546,11 @@ impl Daemon { } } Err(e) => error!("{}", e.display_chain()), - }; - Ok(()) + } } - fn on_set_enable_ipv6(&mut self, tx: OneshotSender<()>, enable_ipv6: bool) -> Result<()> { + fn on_set_enable_ipv6(&mut self, tx: OneshotSender<()>, enable_ipv6: bool) { let save_result = self.settings.set_enable_ipv6(enable_ipv6); - match save_result.chain_err(|| "Unable to save settings") { Ok(settings_changed) => { Self::oneshot_send(tx, (), "set_enable_ipv6 response"); @@ -587,15 +562,12 @@ impl Daemon { } } Err(e) => error!("{}", e.display_chain()), - }; - - Ok(()) + } } - fn on_get_tunnel_options(&self, tx: OneshotSender<TunnelOptions>) -> Result<()> { + fn on_get_tunnel_options(&self, tx: OneshotSender<TunnelOptions>) { let tunnel_options = self.settings.get_tunnel_options().clone(); Self::oneshot_send(tx, tunnel_options, "get_tunnel_options response"); - Ok(()) } fn on_get_settings(&self, tx: OneshotSender<settings::Settings>) { @@ -612,11 +584,9 @@ impl Daemon { Err(ErrorKind::ManagementInterfaceError("Server exited unexpectedly").into()) } - fn handle_trigger_shutdown_event(&mut self) -> Result<()> { + fn handle_trigger_shutdown_event(&mut self) { self.state.shutdown(self.tunnel_state); self.disconnect_tunnel(); - - Ok(()) } /// Set the target state of the client. If it changed trigger the operations needed to |
