summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mullvad_daemon/src/main.rs3
-rw-r--r--mullvad_daemon/src/rpc_info.rs38
-rw-r--r--talpid_ipc/src/http_ipc/connection_info.rs43
3 files changed, 41 insertions, 43 deletions
diff --git a/mullvad_daemon/src/main.rs b/mullvad_daemon/src/main.rs
index fa1db7765c..eb360b3e8c 100644
--- a/mullvad_daemon/src/main.rs
+++ b/mullvad_daemon/src/main.rs
@@ -22,6 +22,7 @@ extern crate talpid_ipc;
mod management_interface;
mod states;
+mod rpc_info;
use management_interface::{ManagementInterfaceServer, TunnelCommand};
use states::{SecurityState, TargetState};
@@ -151,6 +152,8 @@ impl Daemon {
"Mullvad management interface listening on {}",
server.address()
);
+ rpc_info::write(server.address()).chain_err(|| ErrorKind::ManagementInterfaceError(
+ "Failed to write RPC address to file"))?;
Ok(server)
}
diff --git a/mullvad_daemon/src/rpc_info.rs b/mullvad_daemon/src/rpc_info.rs
new file mode 100644
index 0000000000..302afbf719
--- /dev/null
+++ b/mullvad_daemon/src/rpc_info.rs
@@ -0,0 +1,38 @@
+use std::fs::{File, OpenOptions};
+use std::io::{self, Write};
+use std::path::{Path, PathBuf};
+
+error_chain! {
+ errors {
+ WriteFailed(path: PathBuf) {
+ description("Failed to write RCP address to file")
+ display("Failed to write RPC address to {}", path.to_string_lossy())
+ }
+ }
+}
+
+lazy_static! {
+ /// The path to the file where we write the RPC address
+ static ref RPC_ADDRESS_FILE_PATH: &'static Path = Path::new("./.rpc_address");
+}
+
+/// Writes down the RPC address to some API to a file.
+pub fn write(rpc_address: &str) -> Result<()> {
+ open_file(*RPC_ADDRESS_FILE_PATH)
+ .and_then(|mut file| file.write_all(rpc_address.as_bytes()))
+ .chain_err(|| ErrorKind::WriteFailed(RPC_ADDRESS_FILE_PATH.to_owned()))?;
+
+ debug!(
+ "Wrote RPC address to {}",
+ RPC_ADDRESS_FILE_PATH.to_string_lossy()
+ );
+ Ok(())
+}
+
+fn open_file(path: &Path) -> io::Result<File> {
+ OpenOptions::new()
+ .write(true)
+ .truncate(true)
+ .create(true)
+ .open(path)
+}
diff --git a/talpid_ipc/src/http_ipc/connection_info.rs b/talpid_ipc/src/http_ipc/connection_info.rs
deleted file mode 100644
index 1c4b3fac32..0000000000
--- a/talpid_ipc/src/http_ipc/connection_info.rs
+++ /dev/null
@@ -1,43 +0,0 @@
-use std::fs::{File, OpenOptions};
-use std::io::Write;
-use std::path::PathBuf;
-
-/// The path to the file where we write the connection infp
-const IPC_CONNECTION_INFO_FILE: &'static str = "./.ipc_connection_info";
-
-error_chain! {
- errors {
- OpenFileFailed(file_name: PathBuf) {
- description("Could not open file")
- display("Could not open {}", file_name.to_string_lossy())
- }
- WriteConnectionInfoFailed(file_name: PathBuf) {
- description("Could not write connection info file")
- display("Could not write to {}", file_name.to_string_lossy())
- }
- }
-}
-
-pub fn write(connection_info: &str) -> Result<()> {
- let file_location = PathBuf::from(IPC_CONNECTION_INFO_FILE);
- let mut file = open_file(&file_location)?;
- let res = file.write_all(connection_info.as_bytes())
- .chain_err(|| ErrorKind::WriteConnectionInfoFailed(file_location.clone()),);
-
- debug!(
- "Wrote IPC connection info ({}) to {}",
- connection_info,
- file_location.to_string_lossy()
- );
-
- res
-}
-
-fn open_file(file_name: &PathBuf) -> Result<File> {
- OpenOptions::new()
- .write(true)
- .truncate(true)
- .create(true)
- .open(file_name)
- .chain_err(|| ErrorKind::OpenFileFailed(file_name.to_owned()))
-}