Skip to content

Commit

Permalink
Ensure environment & location setting always used (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
graeme authored Nov 27, 2023
1 parent 88935a6 commit 8202035
Showing 1 changed file with 8 additions and 17 deletions.
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

0 comments on commit 8202035

Please sign in to comment.