diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-03-04 15:25:34 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-03-16 12:54:27 +0100 |
| commit | 8bbe10c47e8b87dbcb3b13de3aeb8e03c1546531 (patch) | |
| tree | ba8a07936980fb512ec752a0e582f6a875ae5fa4 | |
| parent | 0633365278f47bc65bceb2331204c321e9d2dce1 (diff) | |
| download | mullvadvpn-8bbe10c47e8b87dbcb3b13de3aeb8e03c1546531.tar.xz mullvadvpn-8bbe10c47e8b87dbcb3b13de3aeb8e03c1546531.zip | |
Dump target state to cache file
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index ba6864db7b..efe2890df3 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -45,6 +45,7 @@ use settings::Settings; #[cfg(not(target_os = "android"))] use std::path::Path; use std::{ + fs::File, io, marker::PhantomData, mem, @@ -68,6 +69,8 @@ use talpid_types::{ #[path = "wireguard.rs"] mod wireguard; +const TARGET_START_STATE_FILE: &str = "target-start-state.json"; + /// FIXME(linus): This is here just because the futures crate has deprecated it and jsonrpc_core /// did not introduce their own yet (https://github.com/paritytech/jsonrpc/pull/196). /// Remove this and use the one in jsonrpc_core when that is released. @@ -1665,7 +1668,21 @@ where } fn on_temporary_shutdown(&mut self) { - // TODO: dump the target state to a file + // Cache the current target state + let cache_file = self.cache_dir.join(TARGET_START_STATE_FILE); + log::debug!("Saving tunnel target state to {}", cache_file.display()); + match File::create(&cache_file) { + Ok(handle) => { + if let Err(e) = + serde_json::to_writer(io::BufWriter::new(handle), &self.target_state) + { + log::error!("Failed to serialize target start state: {}", e); + } + } + Err(e) => { + log::error!("Failed to save target start state: {}", e); + } + } if self.target_state == TargetState::Secured { self.send_tunnel_command(TunnelCommand::BlockWhenDisconnected(true)); |
