-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Egress Server Failure Detection & Recovery (#2657)
Task/Issue URL: https://app.asana.com/0/72649045549333/1206669340827392/f BSK PR: duckduckgo/BrowserServicesKit#786 **Description**: - Use the WireGuard handshakes to determine when a connection fails by checking that the last handshake time is less than 300 seconds (just over two handshakes). - When a failure is detected the client will call /register with server set to the name of the current (failed) server and mode set to failureRecovery. If the server is not in the "active" status on the controller a new registration will be returned otherwise the previous data will be returned (this data should be checked against the current tunnel data including allowedIPs). **Steps to test this PR**: 1. Launch the VPN and connect 2. Block UDP traffic by following these instructions: https://app.asana.com/0/0/1207029295107667/f 3. Open the Console.app and filter by Category: `Network Protection`. The failure recovery logs are indicated with a 🟢 so you can also look for them. 4. After around 5 minutes you will see logs indicating that a register request has been made. 5. It will error with no recovery required as there is not a real problem. <!-- Tagging instructions If this PR isn't ready to be merged for whatever reason it should be marked with the `DO NOT MERGE` label (particularly if it's a draft) If it's pending Product Review/PFR, please add the `Pending Product Review` label. If at any point it isn't actively being worked on/ready for review/otherwise moving forward (besides the above PR/PFR exception) strongly consider closing it (or not opening it in the first place). If you decide not to close it, make sure it's labelled to make it clear the PRs state and comment with more information. --> --- ###### Internal references: [Pull Request Review Checklist](https://app.asana.com/0/1202500774821704/1203764234894239/f) [Software Engineering Expectations](https://app.asana.com/0/59792373528535/199064865822552) [Technical Design Template](https://app.asana.com/0/59792373528535/184709971311943) [Pull Request Documentation](https://app.asana.com/0/1202500774821704/1204012835277482/f)
- Loading branch information
Showing
7 changed files
with
119 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...tion/NetworkExtensionTargets/NetworkExtensionTargets/Pixels/VPNFailureRecoveryPixel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// VPNFailureRecoveryPixel.swift | ||
// | ||
// Copyright © 2024 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import PixelKit | ||
|
||
/// PrivacyPro pixels. | ||
/// | ||
/// Ref: https://app.asana.com/0/0/1206939413299475/f | ||
/// | ||
public enum VPNFailureRecoveryPixel: PixelKitEventV2 { | ||
|
||
/// This pixel is emitted when the last handshake diff is greater than n minutes and an attempt to recover is made (/register is called with failureRecovery) | ||
/// | ||
case vpnFailureRecoveryStarted | ||
|
||
/// This pixel is emitted when the recovery attempt failed due to any reason. | ||
/// | ||
case vpnFailureRecoveryFailed(Error) | ||
|
||
/// This pixel is emitted when the recovery attempt completed and the server was healthy and no further action needs to be taken. | ||
/// | ||
case vpnFailureRecoveryCompletedHealthy | ||
|
||
/// This pixel is emitted when the recovery attempt completed and the server was unhealthy resulting to reconnecting to a different server. | ||
/// | ||
case vpnFailureRecoveryCompletedUnhealthy | ||
|
||
public var name: String { | ||
switch self { | ||
case .vpnFailureRecoveryStarted: | ||
return "m_mac_netp_ev_failure_recovery_started" | ||
case .vpnFailureRecoveryFailed: | ||
return "m_mac_netp_ev_failure_recovery_failed" | ||
case .vpnFailureRecoveryCompletedHealthy: | ||
return "m_mac_netp_ev_failure_recovery_completed_server_healthy" | ||
case .vpnFailureRecoveryCompletedUnhealthy: | ||
return "m_mac_netp_ev_failure_recovery_completed_server_unhealthy" | ||
} | ||
} | ||
|
||
public var error: Error? { | ||
switch self { | ||
case .vpnFailureRecoveryStarted, .vpnFailureRecoveryCompletedHealthy, .vpnFailureRecoveryCompletedUnhealthy: return nil | ||
case .vpnFailureRecoveryFailed(let error): return error | ||
} | ||
} | ||
|
||
public var parameters: [String: String]? { | ||
nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters