TunnelsManager: If only Activate On Demand has changed, don't restart tunnel
This commit is contained in:
parent
b8c331c72d
commit
4c1c1f013c
|
@ -37,4 +37,10 @@ extension NETunnelProviderProtocol {
|
||||||
var isActivateOnDemandEnabled: Bool {
|
var isActivateOnDemandEnabled: Bool {
|
||||||
return (providerConfiguration?["isActivateOnDemandEnabled"] as? Bool) ?? false
|
return (providerConfiguration?["isActivateOnDemandEnabled"] as? Bool) ?? false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hasTunnelConfiguration(tunnelConfiguration otherTunnelConfiguration: TunnelConfiguration) -> Bool {
|
||||||
|
guard let serializedThisTunnelConfiguration = providerConfiguration?["tunnelConfiguration"] as? Data else { return false }
|
||||||
|
guard let serializedOtherTunnelConfiguration = try? JSONEncoder().encode(otherTunnelConfiguration) else { return false }
|
||||||
|
return serializedThisTunnelConfiguration == serializedOtherTunnelConfiguration
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,9 @@ class TunnelsManager {
|
||||||
}
|
}
|
||||||
tunnel.name = tunnelName
|
tunnel.name = tunnelName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let shouldRestartIfActive = !((tunnelProviderManager.protocolConfiguration as? NETunnelProviderProtocol)?.hasTunnelConfiguration(tunnelConfiguration: tunnelConfiguration) ?? false)
|
||||||
|
|
||||||
tunnelProviderManager.protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration, isActivateOnDemandEnabled: activateOnDemandSetting.isActivateOnDemandEnabled)
|
tunnelProviderManager.protocolConfiguration = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration, isActivateOnDemandEnabled: activateOnDemandSetting.isActivateOnDemandEnabled)
|
||||||
tunnelProviderManager.localizedDescription = tunnelName
|
tunnelProviderManager.localizedDescription = tunnelName
|
||||||
tunnelProviderManager.isEnabled = true
|
tunnelProviderManager.isEnabled = true
|
||||||
|
@ -138,10 +141,12 @@ class TunnelsManager {
|
||||||
}
|
}
|
||||||
self.tunnelsListDelegate?.tunnelModified(at: self.tunnels.firstIndex(of: tunnel)!)
|
self.tunnelsListDelegate?.tunnelModified(at: self.tunnels.firstIndex(of: tunnel)!)
|
||||||
|
|
||||||
if tunnel.status == .active || tunnel.status == .activating || tunnel.status == .reasserting {
|
if shouldRestartIfActive {
|
||||||
// Turn off the tunnel, and then turn it back on, so the changes are made effective
|
if tunnel.status == .active || tunnel.status == .activating || tunnel.status == .reasserting {
|
||||||
tunnel.status = .restarting
|
// Turn off the tunnel, and then turn it back on, so the changes are made effective
|
||||||
(tunnel.tunnelProvider.connection as? NETunnelProviderSession)?.stopTunnel()
|
tunnel.status = .restarting
|
||||||
|
(tunnel.tunnelProvider.connection as? NETunnelProviderSession)?.stopTunnel()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if isActivatingOnDemand {
|
if isActivatingOnDemand {
|
||||||
|
|
Loading…
Reference in New Issue