summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-05-14 09:37:04 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-05-14 09:37:04 -0300
commitfca08e280d9c636c7444e413bd8911336a390044 (patch)
treeec7507a4ee0b7d441407c9d9ace2af23e81a8449
parent692f0c810a3fbb869ac556606384312ac8e60eec (diff)
parent3ed0cfc9d4916050d111ea97846839f2b9daee3d (diff)
downloadmullvadvpn-fca08e280d9c636c7444e413bd8911336a390044.tar.xz
mullvadvpn-fca08e280d9c636c7444e413bd8911336a390044.zip
Merge branch 'rpc-info-file-path-on-windows'
-rw-r--r--Cargo.lock9
-rw-r--r--Cargo.toml1
-rw-r--r--app/main.js45
-rw-r--r--mullvad-daemon/Cargo.toml1
-rw-r--r--mullvad-daemon/src/main.rs13
-rw-r--r--mullvad-daemon/src/system_service.rs3
-rw-r--r--mullvad-ipc-client/Cargo.toml3
-rw-r--r--mullvad-ipc-client/src/lib.rs12
-rw-r--r--mullvad-metadata/Cargo.toml9
-rw-r--r--mullvad-metadata/src/lib.rs10
10 files changed, 78 insertions, 28 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 1a7c361918..fe0cd000f6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -767,6 +767,7 @@ dependencies = [
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"mullvad-ipc-client 0.1.0",
+ "mullvad-metadata 0.1.0",
"mullvad-rpc 0.1.0",
"mullvad-types 0.1.0",
"os_pipe 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -789,6 +790,7 @@ name = "mullvad-ipc-client"
version = "0.1.0"
dependencies = [
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "mullvad-metadata 0.1.0",
"mullvad-types 0.1.0",
"serde 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)",
"talpid-ipc 0.1.0",
@@ -796,6 +798,13 @@ dependencies = [
]
[[package]]
+name = "mullvad-metadata"
+version = "0.1.0"
+dependencies = [
+ "app_dirs 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "mullvad-rpc"
version = "0.1.0"
dependencies = [
diff --git a/Cargo.toml b/Cargo.toml
index 7d3ca3e2e9..8bcae5cce6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,6 +4,7 @@ members = [
"windows-service",
"mullvad-cli",
"mullvad-ipc-client",
+ "mullvad-metadata",
"mullvad-types",
"mullvad-rpc",
"talpid-openvpn-plugin",
diff --git a/app/main.js b/app/main.js
index ffc9016799..ea85de8b36 100644
--- a/app/main.js
+++ b/app/main.js
@@ -22,7 +22,6 @@ const isDevelopment = (process.env.NODE_ENV === 'development');
// The name for application directory used for
// scoping logs and user data in platform special folders
const appDirectoryName = 'Mullvad VPN';
-const rpcAddressFile = path.join(getSystemTemporaryDirectory(), '.mullvad_rpc_address');
let browserWindowReady = false;
@@ -81,18 +80,28 @@ const appDelegate = {
case 'darwin':
// macOS: ~/Library/Logs/{appname}
return path.join(app.getPath('home'), 'Library/Logs', appDirectoryName);
+ case 'win32':
+ // Windows: %ALLUSERSPROFILE%\{appname}
+ return appDelegate._getSharedDataDirectory();
+ default:
+ // Linux: ~/.config/{appname}/logs
+ return path.join(app.getPath('userData'), 'logs');
+ }
+ },
+
+ _getSharedDataDirectory: () => {
+ switch(process.platform) {
case 'win32': {
// Windows: %ALLUSERSPROFILE%\{appname}
- let appDataDir = process.env.ALLUSERSPROFILE;
- if (appDataDir) {
- return path.join(appDataDir, appDirectoryName);
- } else {
+ let programDataDirectory = process.env.ALLUSERSPROFILE;
+ if (typeof programDataDirectory === 'undefined' || programDataDirectory === null) {
throw new Error('Missing %ALLUSERSPROFILE% environment variable');
+ } else {
+ return path.join(programDataDirectory, appDirectoryName);
}
}
default:
- // Linux: ~/.config/{appname}/logs
- return path.join(app.getPath('userData'), 'logs');
+ throw new Error(`No shared data directory on platform: ${process.platform}`);
}
},
@@ -181,7 +190,8 @@ const appDelegate = {
},
_startBackend: () => {
- const backendIsRunning = appDelegate._rpcAddressFileExists();
+ const rpcAddressFile = appDelegate._getRpcAddressFilePath();
+ const backendIsRunning = fs.existsSync(rpcAddressFile);
if (backendIsRunning) {
log.info('Not starting the backend as it appears to already be running');
return;
@@ -205,8 +215,15 @@ const appDelegate = {
return p;
});
},
- _rpcAddressFileExists: () => {
- return fs.existsSync(rpcAddressFile);
+ _getRpcAddressFilePath: () => {
+ const rpcAddressFileName = '.mullvad_rpc_address';
+
+ switch(process.platform) {
+ case 'win32':
+ return path.join(appDelegate._getSharedDataDirectory(), rpcAddressFileName);
+ default:
+ return path.join(getSystemTemporaryDirectory(), rpcAddressFileName);
+ }
},
_setupBackendProcessListeners: (p) => {
// electron-sudo writes all output to some buffers in memory.
@@ -239,22 +256,24 @@ const appDelegate = {
return;
}
+ const rpcAddressFile = appDelegate._getRpcAddressFilePath();
+
const pollIntervalMs = 200;
appDelegate.connectionFilePollInterval = setInterval(() => {
- if (browserWindowReady && appDelegate._rpcAddressFileExists()) {
+ if (browserWindowReady && fs.existsSync(rpcAddressFile)) {
if (appDelegate.connectionFilePollInterval) {
clearInterval(appDelegate.connectionFilePollInterval);
appDelegate.connectionFilePollInterval = null;
}
- appDelegate._sendBackendInfo();
+ appDelegate._sendBackendInfo(rpcAddressFile);
}
}, pollIntervalMs);
},
- _sendBackendInfo: () => {
+ _sendBackendInfo: (rpcAddressFile: string) => {
const window = appDelegate._window;
if (!window) {
log.error('Attempted to send backend rpc address before the window was ready');
diff --git a/mullvad-daemon/Cargo.toml b/mullvad-daemon/Cargo.toml
index 4eae21a271..919494c69d 100644
--- a/mullvad-daemon/Cargo.toml
+++ b/mullvad-daemon/Cargo.toml
@@ -28,6 +28,7 @@ tokio-timer = "0.1"
regex = "0.2"
mullvad-ipc-client = { path = "../mullvad-ipc-client" }
+mullvad-metadata = { path = "../mullvad-metadata" }
mullvad-types = { path = "../mullvad-types" }
mullvad-rpc = { path = "../mullvad-rpc" }
talpid-core = { path = "../talpid-core" }
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs
index a4c2eb1466..12136d0f29 100644
--- a/mullvad-daemon/src/main.rs
+++ b/mullvad-daemon/src/main.rs
@@ -36,6 +36,7 @@ extern crate tokio_timer;
extern crate uuid;
extern crate mullvad_ipc_client;
+extern crate mullvad_metadata;
extern crate mullvad_rpc;
extern crate mullvad_types;
extern crate talpid_core;
@@ -59,7 +60,6 @@ mod shutdown;
mod system_service;
mod version;
-use app_dirs::AppInfo;
use error_chain::ChainedError;
use futures::Future;
use jsonrpc_core::futures::sync::oneshot::Sender as OneshotSender;
@@ -67,6 +67,7 @@ use jsonrpc_core::futures::sync::oneshot::Sender as OneshotSender;
use management_interface::{BoxFuture, ManagementInterfaceServer, TunnelCommand};
use mullvad_rpc::{AccountsProxy, AppVersionProxy, HttpHandle};
+use mullvad_metadata::APP_INFO;
use mullvad_types::account::{AccountData, AccountToken};
use mullvad_types::location::GeoIpLocation;
use mullvad_types::relay_constraints::{RelaySettings, RelaySettingsUpdate};
@@ -134,14 +135,6 @@ lazy_static! {
static ref RELAY_CACHE_UPDATE_TIMEOUT: Duration = Duration::from_millis(3000);
}
-static APP_INFO: AppInfo = AppInfo {
- name: crate_name!(),
- author: "Mullvad",
-};
-
-#[cfg(windows)]
-static PRODUCT_NAME: &str = "Mullvad VPN";
-
/// All events that can happen in the daemon. Sent from various threads and exposed interfaces.
pub enum DaemonEvent {
@@ -940,7 +933,7 @@ fn get_resource_dir() -> PathBuf {
}
fn get_cache_dir() -> Result<PathBuf> {
- app_dirs::app_root(app_dirs::AppDataType::UserCache, &::APP_INFO)
+ app_dirs::app_root(app_dirs::AppDataType::UserCache, &APP_INFO)
.chain_err(|| ErrorKind::NoCacheDir)
}
diff --git a/mullvad-daemon/src/system_service.rs b/mullvad-daemon/src/system_service.rs
index a141b2a191..28b8172203 100644
--- a/mullvad-daemon/src/system_service.rs
+++ b/mullvad-daemon/src/system_service.rs
@@ -10,6 +10,7 @@ use std::{env, io, thread};
use cli;
use error_chain::ChainedError;
+use mullvad_metadata::PRODUCT_NAME;
use windows_service::service::{
ServiceAccess, ServiceControl, ServiceControlAccept, ServiceErrorControl, ServiceExitCode,
ServiceInfo, ServiceStartType, ServiceState, ServiceStatus, ServiceType,
@@ -226,7 +227,7 @@ fn get_service_info() -> Result<ServiceInfo> {
let program_data_directory_string =
::std::env::var_os("ALLUSERSPROFILE").ok_or_else(|| ErrorKind::NoLogDir)?;
let program_data_directory = Path::new(&program_data_directory_string);
- let log_directory = program_data_directory.join(::PRODUCT_NAME);
+ let log_directory = program_data_directory.join(PRODUCT_NAME);
let service_log_file = log_directory.join("backend.log");
let tunnel_log_file = log_directory.join("openvpn.log");
diff --git a/mullvad-ipc-client/Cargo.toml b/mullvad-ipc-client/Cargo.toml
index 25cb704c17..f2d3639d07 100644
--- a/mullvad-ipc-client/Cargo.toml
+++ b/mullvad-ipc-client/Cargo.toml
@@ -11,3 +11,6 @@ mullvad-types = { path = "../mullvad-types" }
serde = "1.0"
talpid-ipc = { path = "../talpid-ipc" }
talpid-types = { path = "../talpid-types" }
+
+[target.'cfg(windows)'.dependencies]
+mullvad-metadata = { path = "../mullvad-metadata" }
diff --git a/mullvad-ipc-client/src/lib.rs b/mullvad-ipc-client/src/lib.rs
index 0105176fb6..1488e094c6 100644
--- a/mullvad-ipc-client/src/lib.rs
+++ b/mullvad-ipc-client/src/lib.rs
@@ -225,14 +225,18 @@ mod platform_specific {
#[cfg(windows)]
mod platform_specific {
+ extern crate mullvad_metadata;
+
use super::*;
+ use self::mullvad_metadata::PRODUCT_NAME;
+
pub fn rpc_file_path() -> Result<PathBuf> {
- let windows_directory =
- ::std::env::var_os("WINDIR").ok_or_else(|| ErrorKind::UnknownRpcFilePath)?;
+ let shared_data_directory =
+ ::std::env::var_os("ALLUSERSPROFILE").ok_or_else(|| ErrorKind::UnknownRpcFilePath)?;
- Ok(PathBuf::from(windows_directory)
- .join("Temp")
+ Ok(PathBuf::from(shared_data_directory)
+ .join(PRODUCT_NAME)
.join(".mullvad_rpc_address"))
}
diff --git a/mullvad-metadata/Cargo.toml b/mullvad-metadata/Cargo.toml
new file mode 100644
index 0000000000..0de4ca3d26
--- /dev/null
+++ b/mullvad-metadata/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "mullvad-metadata"
+version = "0.1.0"
+authors = ["Mullvad VPN <admin@mullvad.net>", "Janito Vaqueiro Ferreira Filho <janito@mullvad.net>"]
+description = "Mullvad VPN application metadata"
+license = "GPL-3.0"
+
+[dependencies]
+app_dirs = "1.2"
diff --git a/mullvad-metadata/src/lib.rs b/mullvad-metadata/src/lib.rs
new file mode 100644
index 0000000000..f9c59b9274
--- /dev/null
+++ b/mullvad-metadata/src/lib.rs
@@ -0,0 +1,10 @@
+extern crate app_dirs;
+
+use app_dirs::AppInfo;
+
+pub const PRODUCT_NAME: &str = "Mullvad VPN";
+
+pub const APP_INFO: AppInfo = AppInfo {
+ name: PRODUCT_NAME,
+ author: "Mullvad",
+};