Skip to content

Commit

Permalink
Connection interruption simulation option (#1686)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1205601804599806/f
BSK PR: duckduckgo/BrowserServicesKit#516

**Description**:

This PR adds a `Connection Interruption` failure simulation option and
updates BSK to bring in the changes made to allow this.

I also added some changes to the PacketTunnelProvider in order to test
connection interruptions for the iOS NetP Notifications project. I found
that simply setting reasserting to true causes the ConnectionnTester to
trigger an interruption, then setting it to false recovers it. This has
the benefit of testing the result of the real callback, not needing to
mess with any of the connection tester’s callback handling, not needing
to add any new state and also mimicking an actual interruption (as the
VPN connection status also changes).

**Steps to test this PR**:
1. Build this branch through Xcode
2. Start Network Protection
3. If this is the first time launching, agree to any notifications
prompt.
4. Go to the Debug menu and simulate a connection interruption (Debug ->
Network Protection -> Simulate Failure -> Connection Interruption)
5. **Observe the interruption notification**
6. Go back to Network Protection Status View
7. **Observe the status is reconnecting**
8. Wait for the reconnected notification.

—
###### 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)

---------

Co-authored-by: Diego Rey Mendez <[email protected]>
  • Loading branch information
graeme and diegoreymendez authored Sep 28, 2023
1 parent ee02695 commit 1713fd4
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12295,7 +12295,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 80.2.1;
version = 80.3.0;
};
};
AA06B6B52672AF8100F541C5 /* XCRemoteSwiftPackageReference "Sparkle" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"state" : {
"revision" : "e955f958201a91ef353c55236361e095357e9505",
"version" : "80.2.1"
"revision" : "2bed3ed259ca7bde33f3d41424345acfeff8031d",
"version" : "80.3.0"
}
},
{
Expand Down Expand Up @@ -129,7 +129,7 @@
{
"identity" : "trackerradarkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/TrackerRadarKit.git",
"location" : "https://github.com/duckduckgo/TrackerRadarKit",
"state" : {
"revision" : "4684440d03304e7638a2c8086895367e90987463",
"version" : "1.2.1"
Expand Down
11 changes: 9 additions & 2 deletions DuckDuckGo/Menus/MainMenu.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="22154" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22154"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21701"/>
</dependencies>
<scenes>
<!--Application-->
Expand Down Expand Up @@ -1033,8 +1033,15 @@ CQ
<action selector="simulateTunnelCrash:" target="iLs-sj-2Gd" id="VH7-WB-2dD"/>
</connections>
</menuItem>
<menuItem title="Connection Interruption" id="EB1-Wd-0RU">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="simulateConnectionInterruption:" target="iLs-sj-2Gd" id="2aY-oD-Q2K"/>
</connections>
</menuItem>
</items>
<connections>
<outlet property="simulateConnectionInterruptionMenuItem" destination="EB1-Wd-0RU" id="ddO-Bf-ubT"/>
<outlet property="simulateControllerFailureMenuItem" destination="xyA-ob-gEy" id="1VV-xV-wsB"/>
<outlet property="simulateTunnelCrashMenuItem" destination="A5n-J7-hYk" id="gvK-di-vTP"/>
<outlet property="simulateTunnelFailureMenuItem" destination="kVa-n8-UNx" id="3Ie-Ed-VtG"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ final class NetworkProtectionSimulateFailureMenu: NSMenu {
@IBOutlet weak var simulateControllerFailureMenuItem: NSMenuItem!
@IBOutlet weak var simulateTunnelFailureMenuItem: NSMenuItem!
@IBOutlet weak var simulateTunnelCrashMenuItem: NSMenuItem!
@IBOutlet weak var simulateConnectionInterruptionMenuItem: NSMenuItem!

private var simulationOptions: NetworkProtectionSimulationOptions {
NetworkProtectionTunnelController.simulationOptions
Expand All @@ -63,6 +64,11 @@ final class NetworkProtectionSimulateFailureMenu: NSMenu {
simulateFailure(NetworkProtectionTunnelController().toggleShouldSimulateTunnelFatalError)
}

@IBAction
func simulateConnectionInterruption(_ menuItem: NSMenuItem) {
simulateFailure(NetworkProtectionTunnelController().toggleShouldSimulateConnectionInterruption)
}

private func simulateFailure(_ simulationFunction: @escaping () async throws -> Void) {
Task {
do {
Expand All @@ -77,6 +83,7 @@ final class NetworkProtectionSimulateFailureMenu: NSMenu {
simulateControllerFailureMenuItem.state = simulationOptions.isEnabled(.controllerFailure) ? .on : .off
simulateTunnelFailureMenuItem.state = simulationOptions.isEnabled(.tunnelFailure) ? .on : .off
simulateTunnelCrashMenuItem.state = simulationOptions.isEnabled(.crashFatalError) ? .on : .off
simulateConnectionInterruptionMenuItem.state = simulationOptions.isEnabled(.connectionInterruption) ? .on : .off
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,16 @@ final class NetworkProtectionTunnelController: NetworkProtection.TunnelControlle
}
}

@MainActor
func toggleShouldSimulateConnectionInterruption() async throws {
if Self.simulationOptions.isEnabled(.connectionInterruption) {
Self.simulationOptions.setEnabled(false, option: .connectionInterruption)
} else {
Self.simulationOptions.setEnabled(true, option: .connectionInterruption)
try await sendProviderMessageToActiveSession(.simulateConnectionInterruption)
}
}

@MainActor
private func sendProviderMessageToActiveSession(_ message: ExtensionMessage) async throws {
guard await isConnected,
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/DataBrokerProtection/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let package = Package(
targets: ["DataBrokerProtection"])
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "80.2.1"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "80.3.0"),
.package(path: "../SwiftUIExtensions")
],
targets: [
Expand Down
2 changes: 1 addition & 1 deletion LocalPackages/NetworkProtectionUI/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let package = Package(
targets: ["NetworkProtectionUI"])
],
dependencies: [
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "80.2.1"),
.package(url: "https://github.com/duckduckgo/BrowserServicesKit", exact: "80.3.0"),
.package(path: "../SwiftUIExtensions")
],
targets: [
Expand Down

0 comments on commit 1713fd4

Please sign in to comment.