diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-10-13 15:45:24 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-10-13 18:26:54 +0200 |
| commit | 3481d773bf33e5f668796b0735428d6e33279d8a (patch) | |
| tree | cc7c28cea273a92fe28671262db6e0e39ae0f2b0 | |
| parent | d2199c89e37cf89789f8f2fd9af0a4a9c72a407a (diff) | |
| download | mullvadvpn-3481d773bf33e5f668796b0735428d6e33279d8a.tar.xz mullvadvpn-3481d773bf33e5f668796b0735428d6e33279d8a.zip | |
Make sure there is at least 1000ms between each new tunnel spawn
| -rw-r--r-- | mullvad-daemon/src/main.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index 2525a39308..c427c252bb 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -60,6 +60,7 @@ use std::net::Ipv4Addr; use std::path::PathBuf; use std::sync::{mpsc, Arc, Mutex}; use std::thread; +use std::time::{Duration, Instant}; use talpid_core::firewall::{Firewall, FirewallProxy, SecurityPolicy}; use talpid_core::mpsc::IntoSender; @@ -104,6 +105,7 @@ lazy_static! { // se7.mullvad.net Endpoint::new(Ipv4Addr::new(185, 65, 132, 104), 1300, TransportProtocol::Udp), ]; + static ref MIN_TUNNEL_ALIVE_TIME_MS: Duration = Duration::from_millis(1000); } const CRATE_NAME: &str = "mullvadd"; @@ -544,7 +546,11 @@ impl Daemon { fn spawn_tunnel_monitor_wait_thread(&self, tunnel_monitor: TunnelMonitor) { let error_tx = self.tx.clone(); thread::spawn(move || { + let start = Instant::now(); let result = tunnel_monitor.wait(); + if let Some(sleep_dur) = MIN_TUNNEL_ALIVE_TIME_MS.checked_sub(start.elapsed()) { + thread::sleep(sleep_dur); + } let _ = error_tx.send(DaemonEvent::TunnelExited(result)); trace!("Tunnel monitor thread exit"); }); |
