diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2018-10-24 23:33:49 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2018-10-24 23:33:49 +0200 |
| commit | 7db6d2c0c67156a604bbeb87b21da89249d72b62 (patch) | |
| tree | b7c7664dd060f3e06c2cf2403bd6a9a0bdaed80c /mullvad-daemon/src | |
| parent | 8426b8a87ed8948a22ee79c75c8f0418ac43ae94 (diff) | |
| parent | fdc40fd824c9140edf3c5045378deed5feda0241 (diff) | |
| download | mullvadvpn-7db6d2c0c67156a604bbeb87b21da89249d72b62.tar.xz mullvadvpn-7db6d2c0c67156a604bbeb87b21da89249d72b62.zip | |
Merge branch 'fix-clippy-warnings'
Diffstat (limited to 'mullvad-daemon/src')
| -rw-r--r-- | mullvad-daemon/src/account_history.rs | 4 | ||||
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 36 | ||||
| -rw-r--r-- | mullvad-daemon/src/main.rs | 14 | ||||
| -rw-r--r-- | mullvad-daemon/src/management_interface.rs | 18 | ||||
| -rw-r--r-- | mullvad-daemon/src/relays.rs | 2 | ||||
| -rw-r--r-- | mullvad-daemon/src/system_service.rs | 2 |
6 files changed, 36 insertions, 40 deletions
diff --git a/mullvad-daemon/src/account_history.rs b/mullvad-daemon/src/account_history.rs index ab6797a6fa..486c258177 100644 --- a/mullvad-daemon/src/account_history.rs +++ b/mullvad-daemon/src/account_history.rs @@ -85,9 +85,9 @@ impl AccountHistory { } /// Remove account token from the account history - pub fn remove_account_token(&mut self, account_token: AccountToken) -> Result<()> { + pub fn remove_account_token(&mut self, account_token: &AccountToken) -> Result<()> { self.accounts - .retain(|existing_token| existing_token != &account_token); + .retain(|existing_token| existing_token != account_token); self.save() } diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index e88c4cd0e1..541d904875 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -147,7 +147,7 @@ impl DaemonExecutionState { }; } - pub fn is_running(&mut self) -> bool { + pub fn is_running(&self) -> bool { use self::DaemonExecutionState::*; match self { @@ -180,7 +180,7 @@ pub struct Daemon { } impl Daemon { - pub fn new( + pub fn start( log_dir: Option<PathBuf>, resource_dir: PathBuf, cache_dir: PathBuf, @@ -307,16 +307,17 @@ impl Daemon { fn handle_event(&mut self, event: DaemonEvent) -> Result<()> { use DaemonEvent::*; match event { - TunnelStateTransition(transition) => { - Ok(self.handle_tunnel_state_transition(transition)) - } + TunnelStateTransition(transition) => self.handle_tunnel_state_transition(transition), GenerateTunnelParameters(tunnel_parameters_tx, retry_attempt) => { - Ok(self.handle_generate_tunnel_parameters(tunnel_parameters_tx, retry_attempt)) + self.handle_generate_tunnel_parameters(&tunnel_parameters_tx, retry_attempt) + } + ManagementInterfaceEvent(event) => self.handle_management_interface_event(event), + ManagementInterfaceExited => { + return Err(ErrorKind::ManagementInterfaceError("Server exited unexpectedly").into()) } - ManagementInterfaceEvent(event) => Ok(self.handle_management_interface_event(event)), - ManagementInterfaceExited => self.handle_management_interface_exited(), - TriggerShutdown => Ok(self.handle_trigger_shutdown_event()), + TriggerShutdown => self.handle_trigger_shutdown_event(), } + Ok(()) } fn handle_tunnel_state_transition(&mut self, tunnel_state: TunnelStateTransition) { @@ -330,9 +331,8 @@ impl Daemon { Blocked(ref reason) => { info!("Blocking all network connections, reason: {}", reason); - match reason { - BlockReason::AuthFailed(_) => self.schedule_reconnect(Duration::from_secs(60)), - _ => {} + if let BlockReason::AuthFailed(_) = reason { + self.schedule_reconnect(Duration::from_secs(60)) } } _ => {} @@ -345,13 +345,13 @@ impl Daemon { fn handle_generate_tunnel_parameters( &mut self, - tunnel_parameters_tx: mpsc::Sender<TunnelParameters>, + tunnel_parameters_tx: &mpsc::Sender<TunnelParameters>, retry_attempt: u32, ) { let result = self .settings .get_account_token() - .ok_or(Error::from("No account token configured")) + .ok_or_else(|| Error::from("No account token configured")) .map(|account_token| { match self.settings.get_relay_settings() { RelaySettings::CustomTunnelEndpoint(custom_relay) => custom_relay @@ -370,7 +370,7 @@ impl Daemon { tunnel_parameters_tx .send(TunnelParameters { endpoint, - options: self.settings.get_tunnel_options().clone(), + options: self.settings.get_tunnel_options(), username: account_token, }) .map_err(|_| Error::from("Tunnel parameters receiver stopped listening")) @@ -641,15 +641,11 @@ impl Daemon { } fn oneshot_send<T>(tx: oneshot::Sender<T>, t: T, msg: &'static str) { - if let Err(_) = tx.send(t) { + if tx.send(t).is_err() { warn!("Unable to send {} to management interface client", msg); } } - fn handle_management_interface_exited(&self) -> Result<()> { - Err(ErrorKind::ManagementInterfaceError("Server exited unexpectedly").into()) - } - fn handle_trigger_shutdown_event(&mut self) { self.state.shutdown(&self.tunnel_state); self.disconnect_tunnel(); diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index 60f3b9a878..d06f0101e1 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -53,7 +53,7 @@ fn main() { let exit_code = match run() { Ok(_) => 0, Err(error) => { - if let &ErrorKind::LogError(_) = error.kind() { + if let ErrorKind::LogError(_) = error.kind() { eprintln!("{}", error.display_chain()); } else { error!("{}", error.display_chain()); @@ -89,11 +89,11 @@ fn run() -> Result<()> { info!("Logging to {}", log_dir.display()); } - run_platform(config) + run_platform(&config) } #[cfg(windows)] -fn run_platform(config: cli::Config) -> Result<()> { +fn run_platform(config: &cli::Config) -> Result<()> { if config.run_as_service { system_service::run() } else { @@ -111,11 +111,11 @@ fn run_platform(config: cli::Config) -> Result<()> { } #[cfg(not(windows))] -fn run_platform(config: cli::Config) -> Result<()> { +fn run_platform(config: &cli::Config) -> Result<()> { run_standalone(config) } -fn run_standalone(config: cli::Config) -> Result<()> { +fn run_standalone(config: &cli::Config) -> Result<()> { if !running_as_admin() { warn!("Running daemon as a non-administrator user, clients might refuse to connect"); } @@ -133,7 +133,7 @@ fn run_standalone(config: cli::Config) -> Result<()> { Ok(()) } -fn create_daemon(config: cli::Config) -> Result<Daemon> { +fn create_daemon(config: &cli::Config) -> Result<Daemon> { let log_dir = if config.log_to_file { Some(mullvad_paths::log_dir().chain_err(|| "Unable to get log directory")?) } else { @@ -142,7 +142,7 @@ fn create_daemon(config: cli::Config) -> Result<Daemon> { let resource_dir = mullvad_paths::get_resource_dir(); let cache_dir = mullvad_paths::cache_dir().chain_err(|| "Unable to get cache dir")?; - Daemon::new( + Daemon::start( log_dir, resource_dir, cache_dir, diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index 318d0a6210..43d3ebca83 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -212,7 +212,7 @@ impl ManagementInterfaceServer { let server = talpid_ipc::IpcServer::start_with_metadata( meta_io, meta_extractor, - path.to_string_lossy().to_string(), + &path.to_string_lossy(), )?; Ok(ManagementInterfaceServer { server, @@ -301,7 +301,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterface<T> { } fn unsubscribe<V>( - id: SubscriptionId, + id: &SubscriptionId, subscriptions_lock: &RwLock<HashMap<SubscriptionId, pubsub::Sink<V>>>, ) -> BoxFuture<(), Error> { let was_removed = subscriptions_lock.write().unwrap().remove(&id).is_some(); @@ -329,9 +329,9 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterface<T> { /// Converts the given error to an error that can be given to the caller of the API. /// Will let any actual RPC error through as is, any other error is changed to an internal /// error. - fn map_rpc_error(error: mullvad_rpc::Error) -> Error { + fn map_rpc_error(error: &mullvad_rpc::Error) -> Error { match error.kind() { - &mullvad_rpc::ErrorKind::JsonRpcError(ref rpc_error) => { + mullvad_rpc::ErrorKind::JsonRpcError(ref rpc_error) => { // We have to manually copy the error since we have different // versions of the jsonrpc_core library at the moment. Error { @@ -372,7 +372,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi "Unable to get account data from API: {}", error.display_chain() ); - Self::map_rpc_error(error) + Self::map_rpc_error(&error) }) }); Box::new(future) @@ -517,7 +517,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi debug!("remove_account_from_history"); Box::new(future::result( self.load_history() - .and_then(|mut history| history.remove_account_token(account_token)) + .and_then(|mut history| history.remove_account_token(&account_token)) .map_err(|error| { error!( "Unable to remove account from history: {}", @@ -579,7 +579,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi "Unable to get version data from API: {}", error.display_chain() ); - Self::map_rpc_error(error) + Self::map_rpc_error(&error) }) }); @@ -597,7 +597,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi fn new_state_unsubscribe(&self, id: SubscriptionId) -> BoxFuture<(), Error> { debug!("new_state_unsubscribe"); - Self::unsubscribe(id, &self.subscriptions.new_state_subscriptions) + Self::unsubscribe(&id, &self.subscriptions.new_state_subscriptions) } fn settings_subscribe(&self, _: Self::Metadata, subscriber: pubsub::Subscriber<Settings>) { @@ -607,7 +607,7 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi fn settings_unsubscribe(&self, id: SubscriptionId) -> BoxFuture<(), Error> { debug!("settings_unsubscribe"); - Self::unsubscribe(id, &self.subscriptions.settings_subscriptions) + Self::unsubscribe(&id, &self.subscriptions.settings_subscriptions) } } diff --git a/mullvad-daemon/src/relays.rs b/mullvad-daemon/src/relays.rs index a36ded1628..c3c1a967ed 100644 --- a/mullvad-daemon/src/relays.rs +++ b/mullvad-daemon/src/relays.rs @@ -368,7 +368,7 @@ impl RelaySelector { self.rng .choose(&tunnels.openvpn) .cloned() - .map(|openvpn_endpoint| TunnelEndpointData::OpenVpn(openvpn_endpoint)) + .map(TunnelEndpointData::OpenVpn) } /// Try to read the relays, first from cache and if that fails from the resources. diff --git a/mullvad-daemon/src/system_service.rs b/mullvad-daemon/src/system_service.rs index ee08cae841..6a2d54b326 100644 --- a/mullvad-daemon/src/system_service.rs +++ b/mullvad-daemon/src/system_service.rs @@ -67,7 +67,7 @@ fn run_service() -> Result<()> { .unwrap(); let config = cli::get_config(); - let result = ::create_daemon(config).and_then(|daemon| { + let result = ::create_daemon(&config).and_then(|daemon| { let shutdown_handle = daemon.shutdown_handle(); // Register monitor that translates `ServiceControl` to Daemon events |
