diff options
| author | Emīls Piņķis <pinkisemils@gmail.com> | 2018-03-22 09:43:23 +0000 |
|---|---|---|
| committer | Emīls Piņķis <pinkisemils@gmail.com> | 2018-03-26 15:24:43 +0100 |
| commit | 88079a228309a7cc9abe20aaaab762f9900f4ba1 (patch) | |
| tree | f51a611f8cc8c1d00f89228a23364747828ccef2 | |
| parent | f2dc9ed5596d5040e3690ed8aa2daff0bc99cec6 (diff) | |
| download | mullvadvpn-88079a228309a7cc9abe20aaaab762f9900f4ba1.tar.xz mullvadvpn-88079a228309a7cc9abe20aaaab762f9900f4ba1.zip | |
Add 'get_current_version' and 'get_version_info' RPCs to daemon
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | mullvad-daemon/src/main.rs | 38 | ||||
| -rw-r--r-- | mullvad-daemon/src/management_interface.rs | 40 | ||||
| -rw-r--r-- | mullvad-daemon/src/version.rs | 9 |
4 files changed, 84 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 4908520313..a8519dbebf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Warn if daemon is running as a non-root user. - Include the last two OpenVPN logs in problem reports instead of only the last. - Prevent two instances of the daemon to run at the same time. +- Daemon now fetches latest app versions and verifies whether the current + version is supported. ### Fixed - Fix a bug in account input field that advanced the cursor to the end regardless its prior diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index c998672897..b1d5b641b9 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -51,7 +51,7 @@ mod rpc_address_file; mod rpc_uniqueness_check; mod settings; mod shutdown; - +mod version; use app_dirs::AppInfo; use error_chain::ChainedError; @@ -59,13 +59,14 @@ use futures::Future; use jsonrpc_core::futures::sync::oneshot::Sender as OneshotSender; use management_interface::{BoxFuture, ManagementInterfaceServer, TunnelCommand}; -use mullvad_rpc::{AccountsProxy, HttpHandle}; +use mullvad_rpc::{AccountsProxy, AppVersionProxy, HttpHandle}; use mullvad_types::account::{AccountData, AccountToken}; use mullvad_types::location::GeoIpLocation; use mullvad_types::relay_constraints::{RelaySettings, RelaySettingsUpdate}; use mullvad_types::relay_list::{Relay, RelayList}; use mullvad_types::states::{DaemonState, SecurityState, TargetState}; +use mullvad_types::version::{AppVersion, AppVersionInfo}; use std::env; use std::io; @@ -194,6 +195,7 @@ struct Daemon { management_interface_broadcaster: management_interface::EventBroadcaster, settings: settings::Settings, accounts_proxy: AccountsProxy<HttpHandle>, + version_proxy: AppVersionProxy<HttpHandle>, http_handle: mullvad_rpc::rest::RequestSender, tokio_remote: tokio_core::reactor::Remote, relay_selector: relays::RelaySelector, @@ -247,7 +249,8 @@ impl Daemon { tx, management_interface_broadcaster, settings: settings::Settings::load().chain_err(|| "Unable to read settings")?, - accounts_proxy: AccountsProxy::new(rpc_handle), + accounts_proxy: AccountsProxy::new(rpc_handle.clone()), + version_proxy: AppVersionProxy::new(rpc_handle), http_handle, tokio_remote, relay_selector, @@ -397,6 +400,8 @@ impl Daemon { SetOpenVpnMssfix(tx, mssfix_arg) => self.on_set_openvpn_mssfix(tx, mssfix_arg), GetTunnelOptions(tx) => self.on_get_tunnel_options(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)), Shutdown => self.handle_trigger_shutdown_event(), } } @@ -480,6 +485,29 @@ impl Daemon { Ok(()) } + fn on_get_version_info( + &mut self, + tx: OneshotSender<BoxFuture<AppVersionInfo, mullvad_rpc::Error>>, + ) { + let current_version = version::current().to_owned(); + let fut = self.version_proxy + .latest_app_version() + .join( + self.version_proxy + .is_app_version_supported(¤t_version), + ) + .map(|(latest_versions, is_supported)| AppVersionInfo { + current_is_supported: is_supported, + latest: latest_versions, + }); + Self::oneshot_send(tx, Box::new(fut), "get_version_info response"); + } + + fn on_get_current_version(&mut self, tx: OneshotSender<AppVersion>) { + let current_version = version::current().to_owned(); + Self::oneshot_send(tx, current_version, "get_current_version response"); + } + fn on_get_account(&self, tx: OneshotSender<Option<String>>) { Self::oneshot_send(tx, self.settings.get_account_token(), "current account") } @@ -843,8 +871,8 @@ fn log_version() { info!( "Starting {} - {} {}", env!("CARGO_PKG_NAME"), - include_str!(concat!(env!("OUT_DIR"), "/git-commit-desc.txt")), - include_str!(concat!(env!("OUT_DIR"), "/git-commit-date.txt")) + version::current(), + version::commit_date(), ) } diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index 6d44528e56..234bfd3d59 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -14,6 +14,7 @@ use mullvad_types::location::GeoIpLocation; use mullvad_types::relay_constraints::{RelaySettings, RelaySettingsUpdate}; use mullvad_types::relay_list::RelayList; use mullvad_types::states::{DaemonState, TargetState}; +use mullvad_types::version; use serde; @@ -124,6 +125,14 @@ build_rpc_trait! { #[rpc(meta, name = "get_tunnel_options")] fn get_tunnel_options(&self, Self::Metadata) -> BoxFuture<TunnelOptions, Error>; + /// Retreive version of the app + #[rpc(meta, name = "get_current_version")] + fn get_current_version(&self, Self::Metadata) -> BoxFuture<String, Error>; + + /// Retrieve information about the currently running and latest versions of the app + #[rpc(meta, name = "get_version_info")] + fn get_version_info(&self, Self::Metadata) -> BoxFuture<version::AppVersionInfo, Error>; + #[pubsub(name = "new_state")] { /// Subscribes to the `new_state` event notifications. #[rpc(name = "new_state_subscribe")] @@ -178,6 +187,10 @@ pub enum TunnelCommand { SetOpenVpnMssfix(OneshotSender<()>, Option<u16>), /// Get the mssfix argument for OpenVPN GetTunnelOptions(OneshotSender<TunnelOptions>), + /// Get information about the currently running and latest app versions + GetVersionInfo(OneshotSender<BoxFuture<version::AppVersionInfo, mullvad_rpc::Error>>), + /// Get current version of the app + GetCurrentVersion(OneshotSender<version::AppVersion>), /// Makes the daemon exit the main loop and quit. Shutdown, } @@ -591,6 +604,33 @@ impl<T: From<TunnelCommand> + 'static + Send> ManagementInterfaceApi for Managem Box::new(future) } + fn get_current_version(&self, meta: Self::Metadata) -> BoxFuture<String, Error> { + try_future!(self.check_auth(&meta)); + let (tx, rx) = sync::oneshot::channel(); + let future = self.send_command_to_daemon(TunnelCommand::GetCurrentVersion(tx)) + .and_then(|_| rx.map_err(|_| Error::internal_error())); + + Box::new(future) + } + + fn get_version_info(&self, meta: Self::Metadata) -> BoxFuture<version::AppVersionInfo, Error> { + try_future!(self.check_auth(&meta)); + let (tx, rx) = sync::oneshot::channel(); + let future = self.send_command_to_daemon(TunnelCommand::GetVersionInfo(tx)) + .and_then(|_| rx.map_err(|_| Error::internal_error())) + .and_then(|version_future| { + version_future.map_err(|error| { + error!( + "Unable to get version data from master: {}", + error.display_chain() + ); + Self::map_rpc_error(error) + }) + }); + + Box::new(future) + } + fn new_state_subscribe( &self, meta: Self::Metadata, diff --git a/mullvad-daemon/src/version.rs b/mullvad-daemon/src/version.rs new file mode 100644 index 0000000000..2252406e5f --- /dev/null +++ b/mullvad-daemon/src/version.rs @@ -0,0 +1,9 @@ +/// Returns a string that identifies the current version of the application +pub fn current() -> &'static str { + include_str!(concat!(env!("OUT_DIR"), "/git-commit-desc.txt")) +} + +/// Current description returns the current build date +pub fn commit_date() -> &'static str { + include_str!(concat!(env!("OUT_DIR"), "/git-commit-date.txt")) +} |
