Skip to content

Commit

Permalink
Increase the tunnel monitor check interval to 1 minute (#660)
Browse files Browse the repository at this point in the history
Required:

Task/Issue URL: https://app.asana.com/0/1199333091098016/1206567515074116/f
iOS PR: duckduckgo/iOS#2467
macOS PR: duckduckgo/macos-browser#2190
What kind of version bump will this require?: Patch

Description:

This PR increases the tunnel monitor check interval from 10 seconds to 1 minute.
  • Loading branch information
samsymons authored Feb 13, 2024
1 parent f9cf9ae commit 3f5e33e
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public actor NetworkProtectionTunnelFailureMonitor {
}
}

private static let monitoringInterval: TimeInterval = .seconds(10)
private static let monitoringInterval: TimeInterval = .minutes(1)

private var task: Task<Never, Error>? {
willSet {
Expand All @@ -57,6 +57,7 @@ public actor NetworkProtectionTunnelFailureMonitor {
private let networkMonitor = NWPathMonitor()

private var failureReported = false
private var firstCheckSkipped = false

// MARK: - Init & deinit

Expand All @@ -80,6 +81,7 @@ public actor NetworkProtectionTunnelFailureMonitor {
os_log("⚫️ Starting tunnel failure monitor", log: .networkProtectionTunnelFailureMonitorLog)

failureReported = false
firstCheckSkipped = false

networkMonitor.pathUpdateHandler = { path in
callback(.networkPathChanged(path.debugDescription))
Expand All @@ -100,6 +102,14 @@ public actor NetworkProtectionTunnelFailureMonitor {
// MARK: - Handshake monitor

private func monitorHandshakes(callback: @escaping (Result) -> Void) async {
guard firstCheckSkipped else {
// Avoid running the first tunnel failure check after startup to avoid reading the first handshake after sleep, which will almost always
// be out of date. In normal operation, the first check will frequently be 0 as WireGuard hasn't had the chance to handshake yet.
os_log("⚫️ Skipping first tunnel failure check", log: .networkProtectionTunnelFailureMonitorLog, type: .debug)
firstCheckSkipped = true
return
}

let mostRecentHandshake = await tunnelProvider?.mostRecentHandshake() ?? 0

guard mostRecentHandshake > 0 else {
Expand All @@ -114,10 +124,12 @@ public actor NetworkProtectionTunnelFailureMonitor {
if failureReported {
os_log("⚫️ Tunnel failure already reported", log: .networkProtectionTunnelFailureMonitorLog, type: .debug)
} else {
os_log("⚫️ Tunnel failure reported", log: .networkProtectionTunnelFailureMonitorLog, type: .debug)
callback(.failureDetected)
failureReported = true
}
} else if difference <= Result.failureRecovered.threshold, failureReported {
os_log("⚫️ Tunnel failure recovery", log: .networkProtectionTunnelFailureMonitorLog, type: .debug)
callback(.failureRecovered)
failureReported = false
}
Expand Down

0 comments on commit 3f5e33e

Please sign in to comment.