summaryrefslogtreecommitdiffhomepage
path: root/talpid-core/src
diff options
context:
space:
mode:
authorEmīls Piņķis <emils@mullvad.net>2020-07-14 11:01:53 +0100
committerEmīls <emils@mullvad.net>2020-07-16 16:07:34 +0100
commit16bdc6871d696facf495525f5b5745b572f2efca (patch)
tree54119eb8be67d2092442cf6d6e86ded3a732ace2 /talpid-core/src
parent1cb6a6e6aeb555d253142ad78fda57d4a95934af (diff)
downloadmullvadvpn-16bdc6871d696facf495525f5b5745b572f2efca.tar.xz
mullvadvpn-16bdc6871d696facf495525f5b5745b572f2efca.zip
Stop the connectivity monitor after ping times out
Diffstat (limited to 'talpid-core/src')
-rw-r--r--talpid-core/src/tunnel/wireguard/connectivity_check.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/talpid-core/src/tunnel/wireguard/connectivity_check.rs b/talpid-core/src/tunnel/wireguard/connectivity_check.rs
index 7426e674d7..d6d56b29bb 100644
--- a/talpid-core/src/tunnel/wireguard/connectivity_check.rs
+++ b/talpid-core/src/tunnel/wireguard/connectivity_check.rs
@@ -100,13 +100,15 @@ impl ConnectivityMonitor {
}
let start = Instant::now();
+ let mut now = start;
while start.elapsed() < PING_TIMEOUT {
- if self.check_connectivity()? {
+ if self.check_connectivity(now)? {
return Ok(true);
}
if self.should_shut_down(DELAY_ON_INITIAL_SETUP) {
return Ok(false);
}
+ now = Instant::now();
}
Ok(false)
}
@@ -129,7 +131,10 @@ impl ConnectivityMonitor {
let mut current_iteration = Instant::now();
let time_slept = current_iteration - last_iteration;
if time_slept < (iter_delay * 2) {
- self.check_connectivity()?;
+ if !self.check_connectivity(current_iteration)? {
+ return Ok(());
+ }
+
let end = Instant::now();
if end - current_iteration > Duration::from_secs(1) {
current_iteration = end;
@@ -146,8 +151,7 @@ impl ConnectivityMonitor {
}
/// Returns true if connection is established
- fn check_connectivity(&mut self) -> Result<bool, Error> {
- let now = Instant::now();
+ fn check_connectivity(&mut self, now: Instant) -> Result<bool, Error> {
match self.get_stats() {
None => Ok(false),
Some(new_stats) => {