diff --git a/Sources/NetworkProtection/PacketTunnelProvider.swift b/Sources/NetworkProtection/PacketTunnelProvider.swift index c18f90a46..937977f73 100644 --- a/Sources/NetworkProtection/PacketTunnelProvider.swift +++ b/Sources/NetworkProtection/PacketTunnelProvider.swift @@ -645,7 +645,7 @@ open class PacketTunnelProvider: NEPacketTunnelProvider { } do { - try await updateTunnelConfiguration(serverSelectionMethod: serverSelectionMethod) + try await updateTunnelConfiguration(environment: settings.selectedEnvironment, serverSelectionMethod: serverSelectionMethod) } catch { return } @@ -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, @@ -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) @@ -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) } @@ -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) @@ -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) }