Skip to content

Commit

Permalink
Remove unused VPN session utilities (#898)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/72649045549333/1207151621945908/f
iOS PR: duckduckgo/iOS#3097
macOS PR: duckduckgo/macos-browser#2989
What kind of version bump will this require?: Major

Description:

This PR removes connection utilities that haven't been used on macOS for a while, but were still used on iOS. These are now unused on iOS as well, so they're being removed.
  • Loading branch information
samsymons authored Jul 19, 2024
1 parent 16686ec commit 6db80af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,60 +23,6 @@ import NetworkExtension
///
public class ConnectionSessionUtilities {

/// Ideally we should remove these for iOS too.
///
/// This has been deprecated in macOS to avoid making multiple calls to
/// `NEPacketTunnelProviderManager.loadAllFromPreferences` since it causes notification
/// degradation issues over time. Also, I tried removing this for both platforms, but iOS doesn't have
/// good ways to pass the tunnel controller where we need the session.
///
/// Ref: https://app.asana.com/0/1203137811378537/1206513608690551/f
///
@available(macOS, deprecated: 10.0, message: "Use NetworkProtectionTunnelController.activeSession instead.")
public static func activeSession(networkExtensionBundleID: String) async throws -> NETunnelProviderSession? {
let managers = try await NETunnelProviderManager.loadAllFromPreferences()

guard let manager = managers.first(where: {
($0.protocolConfiguration as? NETunnelProviderProtocol)?.providerBundleIdentifier == networkExtensionBundleID
}) else {
// No active connection, this is acceptable
return nil
}

guard let session = manager.connection as? NETunnelProviderSession else {
// The active connection is not running, so there's no session, this is acceptable
return nil
}

return session
}

/// Ideally we should remove these for iOS too.
///
/// This has been deprecated in macOS to avoid making multiple calls to
/// `NEPacketTunnelProviderManager.loadAllFromPreferences` since it causes notification
/// degradation issues over time. Also, I tried removing this for both platforms, but iOS doesn't have
/// good ways to pass the tunnel controller where we need the session.
///
/// Ref: https://app.asana.com/0/1203137811378537/1206513608690551/f
///
@available(macOS, deprecated: 10.0, message: "Use NetworkProtectionTunnelController.activeSession instead.")
public static func activeSession() async throws -> NETunnelProviderSession? {
let managers = try await NETunnelProviderManager.loadAllFromPreferences()

guard let manager = managers.first else {
// No active connection, this is acceptable
return nil
}

guard let session = manager.connection as? NETunnelProviderSession else {
// The active connection is not running, so there's no session, this is acceptable
return nil
}

return session
}

/// Retrieves a session from a `NEVPNStatusDidChange` notification.
///
public static func session(from notification: Notification) -> NETunnelProviderSession? {
Expand All @@ -87,6 +33,7 @@ public class ConnectionSessionUtilities {

return session
}

}

public extension NETunnelProviderSession {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
//

import Foundation
import NetworkExtension
import NetworkProtection

public final class MockTunnelController: TunnelController {
public final class MockTunnelController: TunnelController, TunnelSessionProvider {

public init() {}

public var didCallStart = false
Expand All @@ -35,4 +37,9 @@ public final class MockTunnelController: TunnelController {
public var isConnected: Bool {
true
}

public func activeSession() async -> NETunnelProviderSession? {
return nil
}

}

0 comments on commit 6db80af

Please sign in to comment.