Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix geoswitching + environment selection bugs #576

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions Sources/NetworkProtection/PacketTunnelProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
}

do {
try await updateTunnelConfiguration(serverSelectionMethod: serverSelectionMethod)
try await updateTunnelConfiguration(environment: settings.selectedEnvironment, serverSelectionMethod: serverSelectionMethod)
} catch {
return
}
Expand All @@ -655,21 +655,12 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
// MARK: - Tunnel Configuration

@MainActor
public func updateTunnelConfiguration(environment: TunnelSettings.SelectedEnvironment = .default, reassert: Bool = true) async throws {
let serverSelectionMethod: NetworkProtectionServerSelectionMethod

switch settings.selectedServer {
case .automatic:
serverSelectionMethod = .automatic
case .endpoint(let serverName):
serverSelectionMethod = .preferredServer(serverName: serverName)
}

try await updateTunnelConfiguration(environment: environment, serverSelectionMethod: serverSelectionMethod, reassert: reassert)
public func updateTunnelConfiguration(reassert: Bool = true) async throws {
try await updateTunnelConfiguration(environment: settings.selectedEnvironment, serverSelectionMethod: currentServerSelectionMethod, reassert: reassert)
}

@MainActor
public func updateTunnelConfiguration(environment: TunnelSettings.SelectedEnvironment = .default, serverSelectionMethod: NetworkProtectionServerSelectionMethod, reassert: Bool = true) async throws {
public func updateTunnelConfiguration(environment: TunnelSettings.SelectedEnvironment, serverSelectionMethod: NetworkProtectionServerSelectionMethod, reassert: Bool = true) async throws {

let tunnelConfiguration = try await generateTunnelConfiguration(environment: environment,
serverSelectionMethod: serverSelectionMethod,
Expand Down Expand Up @@ -705,7 +696,7 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
}

@MainActor
private func generateTunnelConfiguration(environment: TunnelSettings.SelectedEnvironment = .default, serverSelectionMethod: NetworkProtectionServerSelectionMethod, includedRoutes: [IPAddressRange], excludedRoutes: [IPAddressRange]) async throws -> TunnelConfiguration {
private func generateTunnelConfiguration(environment: TunnelSettings.SelectedEnvironment, serverSelectionMethod: NetworkProtectionServerSelectionMethod, includedRoutes: [IPAddressRange], excludedRoutes: [IPAddressRange]) async throws -> TunnelConfiguration {

let configurationResult: (TunnelConfiguration, NetworkProtectionServerInfo)

Expand Down Expand Up @@ -827,7 +818,7 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {

Task {
if case .connected = connectionStatus {
try? await updateTunnelConfiguration(serverSelectionMethod: serverSelectionMethod)
try? await updateTunnelConfiguration(environment: settings.selectedEnvironment, serverSelectionMethod: serverSelectionMethod)
}
completionHandler?(nil)
}
Expand Down Expand Up @@ -902,7 +893,7 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {
settings.selectedServer = .automatic

if case .connected = connectionStatus {
try? await updateTunnelConfiguration(serverSelectionMethod: .automatic)
try? await updateTunnelConfiguration()
}
}
completionHandler?(nil)
Expand All @@ -916,7 +907,7 @@ open class PacketTunnelProvider: NEPacketTunnelProvider {

settings.selectedServer = .endpoint(serverName)
if case .connected = connectionStatus {
try? await updateTunnelConfiguration(serverSelectionMethod: .preferredServer(serverName: serverName))
try? await updateTunnelConfiguration(environment: settings.selectedEnvironment, serverSelectionMethod: .preferredServer(serverName: serverName))
}
completionHandler?(nil)
}
Expand Down
Loading