Make wgContext lazy.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jeroen Leenarts 2018-08-28 14:02:59 +02:00
parent 2e9a12c63f
commit 88d84f702b
1 changed files with 3 additions and 2 deletions

View File

@ -19,7 +19,9 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
// MARK: Properties
var wgHandle: Int32?
var wgContext: WireGuardContext?
lazy var wgContext: WireGuardContext? = {
return WireGuardContext(packetFlow: self.packetFlow)
}()
// MARK: NEPacketTunnelProvider
@ -49,7 +51,6 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
NSLog("wg log: \(level): \(tag): \(msg)")
}
wgContext = WireGuardContext(packetFlow: self.packetFlow)
let handle = withStringsAsGoStrings(interfaceName, settings) { (nameGoStr, settingsGoStr) -> Int32 in
return withUnsafeMutablePointer(to: &wgContext) { (wgCtxPtr) -> Int32 in