summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-09-14 11:29:46 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2018-09-17 10:44:20 -0300
commitbc1c20c9cf794ee3cbce5b8c81030741706bc735 (patch)
treeb0a830ee8e07bbbe0bc681713ca4979bac9716aa
parent0772073fe5bfb0f17a50899686eaab30d3d6459e (diff)
downloadmullvadvpn-bc1c20c9cf794ee3cbce5b8c81030741706bc735.tar.xz
mullvadvpn-bc1c20c9cf794ee3cbce5b8c81030741706bc735.zip
Try to reconnect if authentication fails
-rw-r--r--mullvad-daemon/src/main.rs25
1 files changed, 23 insertions, 2 deletions
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs
index 8f03a78170..661da885dc 100644
--- a/mullvad-daemon/src/main.rs
+++ b/mullvad-daemon/src/main.rs
@@ -58,7 +58,7 @@ mod version;
use error_chain::ChainedError;
use futures::sync::mpsc::UnboundedSender;
use futures::{Future, Sink};
-use jsonrpc_core::futures::sync::oneshot::Sender as OneshotSender;
+use jsonrpc_core::futures::sync::oneshot::{self, Sender as OneshotSender};
use management_interface::{BoxFuture, ManagementCommand, ManagementInterfaceServer};
use mullvad_rpc::{AccountsProxy, AppVersionProxy, HttpHandle};
@@ -332,7 +332,14 @@ impl Daemon {
self.state.disconnected();
self.current_relay = None;
}
- Blocked(ref reason) => info!("Blocking all network connections, reason: {}", reason),
+ Blocked(ref reason) => {
+ info!("Blocking all network connections, reason: {}", reason);
+
+ match reason {
+ BlockReason::AuthFailed(_) => self.schedule_reconnect(Duration::from_secs(60)),
+ _ => {}
+ }
+ }
_ => {}
}
@@ -341,6 +348,20 @@ impl Daemon {
.notify_new_state(tunnel_state);
}
+ fn schedule_reconnect(&mut self, delay: Duration) {
+ let command_tx = self.tx.clone();
+
+ thread::spawn(move || {
+ let (result_tx, _result_rx) = oneshot::channel();
+
+ thread::sleep(delay);
+ debug!("Attempting to reconnect");
+ let _ = command_tx.send(DaemonEvent::ManagementInterfaceEvent(
+ ManagementCommand::SetTargetState(result_tx, TargetState::Secured),
+ ));
+ });
+ }
+
fn handle_management_interface_event(&mut self, event: ManagementCommand) {
use ManagementCommand::*;
match event {