summaryrefslogtreecommitdiffhomepage
path: root/mullvad_daemon/src
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2017-06-14 10:54:13 +0200
committerLinus Färnstrand <linus@mullvad.net>2017-06-16 16:28:08 +0200
commit82d6d77e1760247fedde1f788bf307935cfcdf0c (patch)
treeb9fc807b8c08cff8de64a5539d89e8460dbcd120 /mullvad_daemon/src
parent29de1387c9cdcd2a06bbb6ee1c4c9f36734f6107 (diff)
downloadmullvadvpn-82d6d77e1760247fedde1f788bf307935cfcdf0c.tar.xz
mullvadvpn-82d6d77e1760247fedde1f788bf307935cfcdf0c.zip
Move and refactor connection_info module
Diffstat (limited to 'mullvad_daemon/src')
-rw-r--r--mullvad_daemon/src/main.rs3
-rw-r--r--mullvad_daemon/src/rpc_info.rs38
2 files changed, 41 insertions, 0 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)
+}