diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2022-03-21 15:56:00 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2022-03-24 14:00:24 +0100 |
| commit | e88949892b2c1e0c28b3527eb4a3ea1585b01eae (patch) | |
| tree | 4cf9909a258abfd17cea9e54a05807ad9f274b1f | |
| parent | 2ac5e451676489faa39b72b0de90873648ea6a2c (diff) | |
| download | mullvadvpn-e88949892b2c1e0c28b3527eb4a3ea1585b01eae.tar.xz mullvadvpn-e88949892b2c1e0c28b3527eb4a3ea1585b01eae.zip | |
Simulator: fix selector result unpacking
| -rw-r--r-- | ios/MullvadVPN/SimulatorTunnelProviderHost.swift | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/ios/MullvadVPN/SimulatorTunnelProviderHost.swift b/ios/MullvadVPN/SimulatorTunnelProviderHost.swift index 878d9460d1..9f6bf5fc78 100644 --- a/ios/MullvadVPN/SimulatorTunnelProviderHost.swift +++ b/ios/MullvadVPN/SimulatorTunnelProviderHost.swift @@ -20,22 +20,25 @@ class SimulatorTunnelProviderHost: SimulatorTunnelProviderDelegate { override func startTunnel(options: [String: NSObject]?, completionHandler: @escaping (Error?) -> Void) { stateQueue.async { - let tunnelOptions = PacketTunnelOptions(rawOptions: options ?? [:]) - let appSelectorResult = Result { try tunnelOptions.getSelectorResult() } + var selectorResult: RelaySelectorResult? - if let error = appSelectorResult.error { + do { + let tunnelOptions = PacketTunnelOptions(rawOptions: options ?? [:]) + + selectorResult = try tunnelOptions.getSelectorResult() + } catch { self.providerLogger.error( chainedError: AnyChainedError(error), message: "Failed to decode relay selector result passed from the app. Will continue by picking new relay." ) } - if let appSelectorResult = appSelectorResult.flattenValue { - self.tunnelStatus.tunnelRelay = appSelectorResult.packetTunnelRelay - } else { - self.tunnelStatus.tunnelRelay = self.pickRelay()?.packetTunnelRelay + if selectorResult == nil { + selectorResult = self.pickRelay() } + self.tunnelStatus.tunnelRelay = selectorResult?.packetTunnelRelay + completionHandler(nil) } } @@ -80,9 +83,7 @@ class SimulatorTunnelProviderHost: SimulatorTunnelProviderDelegate { } private func pickRelay() -> RelaySelectorResult? { - guard let result = RelayCache.Tracker.shared.read().await().unwrappedValue else { return nil } - - switch result { + switch RelayCache.Tracker.shared.readAndWait() { case .success(let cachedRelays): let keychainReference = self.protocolConfiguration.passwordReference! |
