diff options
author | Roopesh Chander <roop@roopc.net> | 2018-12-19 16:02:48 +0530 |
---|---|---|
committer | Roopesh Chander <roop@roopc.net> | 2018-12-19 18:35:53 +0530 |
commit | bba6d2f9195214d79621159fc1e323206a611845 (patch) | |
tree | ebafa19507c91f7b4a7aed97ab89000bd253bb7c /WireGuard/WireGuard/Tunnel | |
parent | NE: Handle bad domain names and Activate On Demand (diff) | |
download | wireguard-apple-bba6d2f9195214d79621159fc1e323206a611845.tar.xz wireguard-apple-bba6d2f9195214d79621159fc1e323206a611845.zip |
TunnelsManager: If only Activate On Demand has changed, don't restart tunnel
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/Tunnel')
-rw-r--r-- | WireGuard/WireGuard/Tunnel/TunnelsManager.swift | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift index 10ef1ef..8382361 100644 --- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift +++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift @@ -115,6 +115,9 @@ class TunnelsManager { } tunnel.name = tunnelName } + + let shouldRestartIfActive = !((tunnelProviderManager.protocolConfiguration as? NETunnelProviderProtocol)?.hasTunnelConfiguration(tunnelConfiguration: tunnelConfiguration) ?? false) + tunnelProviderManager.protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration, isActivateOnDemandEnabled: activateOnDemandSetting.isActivateOnDemandEnabled) tunnelProviderManager.localizedDescription = tunnelName tunnelProviderManager.isEnabled = true @@ -137,13 +140,15 @@ class TunnelsManager { self.tunnelsListDelegate?.tunnelMoved(from: oldIndex, to: newIndex) } self.tunnelsListDelegate?.tunnelModified(at: self.tunnels.firstIndex(of: tunnel)!) - - if tunnel.status == .active || tunnel.status == .activating || tunnel.status == .reasserting { - // Turn off the tunnel, and then turn it back on, so the changes are made effective - tunnel.status = .restarting - (tunnel.tunnelProvider.connection as? NETunnelProviderSession)?.stopTunnel() + + if shouldRestartIfActive { + if tunnel.status == .active || tunnel.status == .activating || tunnel.status == .reasserting { + // Turn off the tunnel, and then turn it back on, so the changes are made effective + tunnel.status = .restarting + (tunnel.tunnelProvider.connection as? NETunnelProviderSession)?.stopTunnel() + } } - + if isActivatingOnDemand { // Reload tunnel after saving. // Without this, the tunnel stopes getting updates on the tunnel status from iOS. |