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
|
||||||
|
@ -137,13 +140,15 @@ class TunnelsManager {
|
||||||
self.tunnelsListDelegate?.tunnelMoved(from: oldIndex, to: newIndex)
|
self.tunnelsListDelegate?.tunnelMoved(from: oldIndex, to: newIndex)
|
||||||
}
|
}
|
||||||
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 {
|
||||||
// Reload tunnel after saving.
|
// Reload tunnel after saving.
|
||||||
// Without this, the tunnel stopes getting updates on the tunnel status from iOS.
|
// Without this, the tunnel stopes getting updates on the tunnel status from iOS.
|
||||||
|
|
Loading…
Reference in New Issue