Skip to content

Commit

Permalink
Resetting all state for the VPN will cancel the tunnel and stop the m…
Browse files Browse the repository at this point in the history
…onitors (#900)

Task/Issue URL: https://app.asana.com/0/1207603085593419/1207832283330964/f
iOS PR: duckduckgo/iOS#3099
macOS PR: duckduckgo/macos-browser#2991

What kind of version bump will this require?: Patch

**Optional**:

Tech Design URL:
CC:

## Description:

Fix the VPN configuration removal handling in the extension to stop the tunnel.
  • Loading branch information
diegoreymendez authored Jul 19, 2024
1 parent f8e3817 commit 3274feb
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Sources/NetworkProtection/PacketTunnelProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
// Subscription Errors - 100+
case vpnAccessRevoked

// State Reset - 200+
case appRequestedCancellation

public var errorDescription: String? {
switch self {
case .startingTunnelWithoutAuthToken:
Expand All @@ -93,6 +96,8 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
return "Failed to generate a tunnel configuration: \(internalError.localizedDescription)"
case .simulateTunnelFailureError:
return "Simulated a tunnel error as requested"
case .appRequestedCancellation:
return nil
}
}

Expand All @@ -104,14 +109,17 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
case .simulateTunnelFailureError: return 2
// Subscription Errors - 100+
case .vpnAccessRevoked: return 100
// State Reset - 200+
case .appRequestedCancellation: return 200
}
}

public var errorUserInfo: [String: Any] {
switch self {
case .startingTunnelWithoutAuthToken,
.simulateTunnelFailureError,
.vpnAccessRevoked:
.vpnAccessRevoked,
.appRequestedCancellation:
return [:]
case .couldNotGenerateTunnelConfiguration(let underlyingError):
return [NSUnderlyingErrorKey: underlyingError]
Expand Down Expand Up @@ -1147,9 +1155,10 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
try? tokenStore.deleteToken()
#endif

// This is not really an error, we received a command to reset the connection
cancelTunnelWithError(nil)
completionHandler?(nil)
Task {
completionHandler?(nil)
await cancelTunnel(with: TunnelError.appRequestedCancellation)
}
}

private func handleGetLastErrorMessage(completionHandler: ((Data?) -> Void)? = nil) {
Expand Down

0 comments on commit 3274feb

Please sign in to comment.