Load site from existing preferences when starting
This commit is contained in:
parent
0c70c794cb
commit
0fde99a34f
|
@ -28,20 +28,34 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func start(completionHandler: @escaping (Error?) -> Void) {
|
private func start(completionHandler: @escaping (Error?) -> Void) {
|
||||||
let proto = self.protocolConfiguration as! NETunnelProviderProtocol
|
// Load vpn configs from system, and find the manager matching the one being started
|
||||||
|
NETunnelProviderManager.loadAllFromPreferences() { managers, error in
|
||||||
|
let targetProtoConfig = self.protocolConfiguration as? NETunnelProviderProtocol;
|
||||||
|
let targetID = targetProtoConfig?.providerConfiguration!["id"] as? String;
|
||||||
|
|
||||||
|
guard let managers = managers else {
|
||||||
|
self.log.error("No managers were loaded")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for manager in managers {
|
||||||
var config: Data
|
var config: Data
|
||||||
var key: String
|
var key: String
|
||||||
|
|
||||||
|
let mgr = manager.protocolConfiguration as? NETunnelProviderProtocol;
|
||||||
|
let id = mgr?.providerConfiguration!["id"] as? String;
|
||||||
|
|
||||||
|
if (id == targetID) {
|
||||||
do {
|
do {
|
||||||
site = try Site(proto: proto)
|
self.site = try Site(manager: manager)
|
||||||
config = try site!.getConfig()
|
config = try self.site!.getConfig()
|
||||||
} catch {
|
} catch {
|
||||||
//TODO: need a way to notify the app
|
//TODO: need a way to notify the app
|
||||||
log.error("Failed to render config from vpn object")
|
self.log.error("Failed to render config from vpn object")
|
||||||
return completionHandler(error)
|
return completionHandler(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
let _site = site!
|
let _site = self.site!
|
||||||
|
|
||||||
do {
|
do {
|
||||||
key = try _site.getKey()
|
key = try _site.getKey()
|
||||||
|
@ -49,7 +63,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
return completionHandler(error)
|
return completionHandler(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
let fileDescriptor = tunnelFileDescriptor
|
let fileDescriptor = self.tunnelFileDescriptor
|
||||||
if fileDescriptor == nil {
|
if fileDescriptor == nil {
|
||||||
return completionHandler("Unable to locate the tun file descriptor")
|
return completionHandler("Unable to locate the tun file descriptor")
|
||||||
}
|
}
|
||||||
|
@ -98,6 +112,12 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
|
||||||
|
|
||||||
completionHandler(nil)
|
completionHandler(nil)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// We're done looking through managers
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func handleDNUpdate(newSite: Site) {
|
private func handleDNUpdate(newSite: Site) {
|
||||||
|
|
Loading…
Reference in New Issue