aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-02-07 18:18:04 +0530
committerRoopesh Chander <roop@roopc.net>2019-02-07 18:18:04 +0530
commit868fee04779e25ae59a6a1bc98a6e9b7ade75fba (patch)
treebecf39bdb9ea0907a50b55345a20faa320d793bb
parentmacOS: prohibit multiple instances of app (diff)
downloadwireguard-apple-868fee04779e25ae59a6a1bc98a6e9b7ade75fba.tar.xz
wireguard-apple-868fee04779e25ae59a6a1bc98a6e9b7ade75fba.zip
TunnelsManager: When creating/modifying a tunnel, update the associated object
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/Tunnel/TunnelsManager.swift12
1 files changed, 7 insertions, 5 deletions
diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
index e10ba770..a2fc00b9 100644
--- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
+++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
@@ -105,8 +105,7 @@ class TunnelsManager {
}
let tunnelProviderManager = NETunnelProviderManager()
- tunnelProviderManager.protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration)
- tunnelProviderManager.localizedDescription = tunnelConfiguration.name
+ tunnelProviderManager.setTunnelConfiguration(tunnelConfiguration)
tunnelProviderManager.isEnabled = true
activateOnDemandSetting.apply(on: tunnelProviderManager)
@@ -163,8 +162,7 @@ class TunnelsManager {
tunnel.name = tunnelName
}
- tunnelProviderManager.protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration, previouslyFrom: tunnelProviderManager.protocolConfiguration)
- tunnelProviderManager.localizedDescription = tunnelConfiguration.name
+ tunnelProviderManager.setTunnelConfiguration(tunnelConfiguration)
tunnelProviderManager.isEnabled = true
let isActivatingOnDemand = !tunnelProviderManager.isOnDemandEnabled && activateOnDemandSetting.isActivateOnDemandEnabled
@@ -178,7 +176,6 @@ class TunnelsManager {
return
}
guard let self = self else { return }
-
if isNameChanged {
let oldIndex = self.tunnels.firstIndex(of: tunnel)!
self.tunnels.sort { $0.name < $1.name }
@@ -549,4 +546,9 @@ extension NETunnelProviderManager {
}
return config
}
+ func setTunnelConfiguration(_ tunnelConfiguration: TunnelConfiguration) {
+ protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration, previouslyFrom: protocolConfiguration)
+ localizedDescription = tunnelConfiguration.name
+ objc_setAssociatedObject(self, &NETunnelProviderManager.cachedConfigKey, tunnelConfiguration, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
+ }
}