diff options
author | Roopesh Chander <roop@roopc.net> | 2019-04-05 13:43:05 +0530 |
---|---|---|
committer | Roopesh Chander <roop@roopc.net> | 2019-04-05 13:43:08 +0530 |
commit | 4c1b2e125897c5ff9f0abc66b67ade272bd4244d (patch) | |
tree | 7ab5d83cc5d9596a063923e95b850c2ba05b9e92 /WireGuard/WireGuard/Tunnel/TunnelsManager.swift | |
parent | TunnelsManager: Cache isTunnelConfigurationAvailableInKeychain (diff) | |
download | wireguard-apple-4c1b2e125897c5ff9f0abc66b67ade272bd4244d.tar.xz wireguard-apple-4c1b2e125897c5ff9f0abc66b67ade272bd4244d.zip |
TunnelsManager: Fix comparing tunnels with tunnelProviders in reload()
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r-- | WireGuard/WireGuard/Tunnel/TunnelsManager.swift | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift index 19aeaef..b1def4c 100644 --- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift +++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift @@ -78,14 +78,14 @@ class TunnelsManager { let loadedTunnelProviders = managers ?? [] for (index, currentTunnel) in self.tunnels.enumerated().reversed() { - if !loadedTunnelProviders.contains(where: { $0.tunnelConfiguration == currentTunnel.tunnelConfiguration }) { + if !loadedTunnelProviders.contains(where: { $0.isEquivalentTo(currentTunnel) }) { // Tunnel was deleted outside the app self.tunnels.remove(at: index) self.tunnelsListDelegate?.tunnelRemoved(at: index, tunnel: currentTunnel) } } for loadedTunnelProvider in loadedTunnelProviders { - if let matchingTunnel = self.tunnels.first(where: { $0.tunnelConfiguration == loadedTunnelProvider.tunnelConfiguration }) { + if let matchingTunnel = self.tunnels.first(where: { loadedTunnelProvider.isEquivalentTo($0) }) { matchingTunnel.tunnelProvider = loadedTunnelProvider matchingTunnel.refreshStatus() } else { @@ -608,4 +608,15 @@ extension NETunnelProviderManager { localizedDescription = tunnelConfiguration.name objc_setAssociatedObject(self, &NETunnelProviderManager.cachedConfigKey, tunnelConfiguration, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) } + + func isEquivalentTo(_ tunnel: TunnelContainer) -> Bool { + switch (isTunnelConfigurationAvailableInKeychain, tunnel.isTunnelConfigurationAvailableInKeychain) { + case (true, true): + return tunnelConfiguration == tunnel.tunnelConfiguration + case (false, false): + return localizedDescription == tunnel.name + default: + return false + } + } } |