diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-04-27 08:51:34 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-05-03 14:00:37 -0300 |
| commit | 9f2adbe2baa2d7a0e1cefab77091cf68b485e944 (patch) | |
| tree | 27f7597c22ef15bf1bb0232f079f1ee2a0c0e4d7 | |
| parent | aaba78aa2ea2360a801a28be7451ddda8b8008ff (diff) | |
| download | mullvadvpn-9f2adbe2baa2d7a0e1cefab77091cf68b485e944.tar.xz mullvadvpn-9f2adbe2baa2d7a0e1cefab77091cf68b485e944.zip | |
Use `DaemonRpcClient` to check for other daemon
| -rw-r--r-- | mullvad-daemon/Cargo.toml | 2 | ||||
| -rw-r--r-- | mullvad-daemon/src/main.rs | 1 | ||||
| -rw-r--r-- | mullvad-daemon/src/rpc_address_file.rs | 11 | ||||
| -rw-r--r-- | mullvad-daemon/src/rpc_uniqueness_check.rs | 39 |
4 files changed, 19 insertions, 34 deletions
diff --git a/mullvad-daemon/Cargo.toml b/mullvad-daemon/Cargo.toml index 21a54429a8..4eae21a271 100644 --- a/mullvad-daemon/Cargo.toml +++ b/mullvad-daemon/Cargo.toml @@ -27,6 +27,7 @@ tokio-core = "0.1" tokio-timer = "0.1" regex = "0.2" +mullvad-ipc-client = { path = "../mullvad-ipc-client" } mullvad-types = { path = "../mullvad-types" } mullvad-rpc = { path = "../mullvad-rpc" } talpid-core = { path = "../talpid-core" } @@ -45,4 +46,3 @@ windows-service = { path = "../windows-service" } assert_matches = "1.0" duct = "0.10" os_pipe = "0.6" -mullvad-ipc-client = { path = "../mullvad-ipc-client" } diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index 897a920737..e0059b2091 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -35,6 +35,7 @@ extern crate tokio_core; extern crate tokio_timer; extern crate uuid; +extern crate mullvad_ipc_client; extern crate mullvad_rpc; extern crate mullvad_types; extern crate talpid_core; diff --git a/mullvad-daemon/src/rpc_address_file.rs b/mullvad-daemon/src/rpc_address_file.rs index fc3bc1cf1e..84ec176f85 100644 --- a/mullvad-daemon/src/rpc_address_file.rs +++ b/mullvad-daemon/src/rpc_address_file.rs @@ -1,5 +1,5 @@ use std::fs::{self, File, OpenOptions}; -use std::io::{self, BufRead, BufReader, Write}; +use std::io::{self, Write}; use std::path::{Path, PathBuf}; error_chain! { @@ -31,15 +31,6 @@ lazy_static! { } -/// Reads the address of the RPC connection from the RPC info file. -pub fn read() -> io::Result<String> { - let file = File::open(RPC_ADDRESS_FILE_PATH.as_path())?; - let mut reader = BufReader::new(file); - let mut address = String::new(); - reader.read_line(&mut address)?; - Ok(address) -} - /// Writes down the RPC connection info to some API to a file. pub fn write(rpc_address: &str, shared_secret: &str) -> Result<()> { // Avoids opening an existing file owned by another user and writing sensitive data to it. diff --git a/mullvad-daemon/src/rpc_uniqueness_check.rs b/mullvad-daemon/src/rpc_uniqueness_check.rs index e2479a27d3..fd889cdddf 100644 --- a/mullvad-daemon/src/rpc_uniqueness_check.rs +++ b/mullvad-daemon/src/rpc_uniqueness_check.rs @@ -1,9 +1,6 @@ -use std::result; +use error_chain::ChainedError; -use mullvad_types::states::DaemonState; -use talpid_ipc::WsIpcClient; - -use rpc_address_file; +use mullvad_ipc_client::DaemonRpcClient; /// Checks if there is another instance of the daemon running. @@ -11,27 +8,23 @@ use rpc_address_file; /// Tries to connect to another daemon and perform a simple RPC call. If it fails, assumes the /// other daemon has stopped. pub fn is_another_instance_running() -> bool { - if let Ok(address) = rpc_address_file::read() { - match call_other_instance(address) { + match DaemonRpcClient::new() { + Ok(client) => match client.get_state() { Ok(_) => true, - Err(message) => { - info!("{}; assuming it has stopped", message); + Err(error) => { + let chained_error = error.chain_err(|| { + "Failed to communicate with another daemon instance, assuming it has stopped" + }); + info!("{}", chained_error.display_chain()); false } + }, + Err(error) => { + let chained_error = error.chain_err(|| { + "Failed to load RPC address for another daemon instance, assuming there isn't one" + }); + debug!("{}", chained_error.display_chain()); + false } - } else { - false } } - -fn call_other_instance(address: String) -> result::Result<(), String> { - let method = "get_state"; - let args: [u8; 0] = []; - // TODO: Authenticate with server - let mut rpc_client = - WsIpcClient::new(address).map_err(|_| "Failed to connect to other daemon")?; - let _: DaemonState = rpc_client - .call(method, &args) - .map_err(|_| "Failed to execute RPC call to other daemon")?; - Ok(()) -} |
