VPN: Reload the tunnel before starting it up

To avoid errors like this: https://stackoverflow.com/q/47550706

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2018-10-29 05:02:57 +05:30
parent 0baca8bf58
commit e80e8b06c5
1 changed files with 12 additions and 9 deletions

View File

@ -272,15 +272,18 @@ class TunnelContainer: NSObject {
s.status = .inactive
return
}
s.startObservingTunnelStatus()
let session = (s.tunnelProvider.connection as! NETunnelProviderSession)
do {
let tunnelOptions = PacketTunnelOptionsGenerator.generateOptions(
from: tunnelConfiguration, withResolvedEndpoints: endpoints)
try session.startTunnel(options: tunnelOptions)
} catch (let error) {
os_log("Failed to activate tunnel: %{public}@", log: OSLog.default, type: .debug, "\(error)")
completionHandler(error)
s.tunnelProvider.loadFromPreferences { [weak s] (error) in
guard let s = s else { return }
s.startObservingTunnelStatus()
let session = (s.tunnelProvider.connection as! NETunnelProviderSession)
do {
let tunnelOptions = PacketTunnelOptionsGenerator.generateOptions(
from: tunnelConfiguration, withResolvedEndpoints: endpoints)
try session.startTunnel(options: tunnelOptions)
} catch (let error) {
os_log("Failed to activate tunnel: %{public}@", log: OSLog.default, type: .debug, "\(error)")
completionHandler(error)
}
}
}
}