From bd9d676c8f209bc1e86f6be3e7cd70dc745ae9db Mon Sep 17 00:00:00 2001 From: Jeroen Leenarts Date: Wed, 26 Sep 2018 11:22:54 +0200 Subject: [PATCH] Fix function length warning. Signed-off-by: Jason A. Donenfeld --- .../PacketTunnelProvider.swift | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuardNetworkExtension/PacketTunnelProvider.swift index cb8d092..a6ef5c3 100644 --- a/WireGuardNetworkExtension/PacketTunnelProvider.swift +++ b/WireGuardNetworkExtension/PacketTunnelProvider.swift @@ -14,8 +14,20 @@ class PacketTunnelProvider: NEPacketTunnelProvider { // MARK: Properties - var wgHandle: Int32? - var wgContext: WireGuardContext? + private var wgHandle: Int32? + private var wgContext: WireGuardContext? + + private var config: NETunnelProviderProtocol { + return self.protocolConfiguration as! NETunnelProviderProtocol // swiftlint:disable:this force_cast + } + + private var interfaceName: String { + return config.providerConfiguration![PCKeys.title.rawValue]! as! String // swiftlint:disable:this force_cast + } + + private var settings: String { + return config.providerConfiguration![PCKeys.settings.rawValue]! as! String // swiftlint:disable:this force_cast + } // MARK: NEPacketTunnelProvider @@ -23,10 +35,6 @@ class PacketTunnelProvider: NEPacketTunnelProvider { override func startTunnel(options: [String: NSObject]?, completionHandler startTunnelCompletionHandler: @escaping (Error?) -> Void) { os_log("Starting tunnel", log: Log.general, type: .info) - let config = self.protocolConfiguration as! NETunnelProviderProtocol // swiftlint:disable:this force_cast - let interfaceName = config.providerConfiguration![PCKeys.title.rawValue]! as! String // swiftlint:disable:this force_cast - let settings = config.providerConfiguration![PCKeys.settings.rawValue]! as! String // swiftlint:disable:this force_cast - let validatedEndpoints = (config.providerConfiguration?[PCKeys.endpoints.rawValue] as? String ?? "").commaSeparatedToArray().compactMap { try? Endpoint(endpointString: String($0)) }.compactMap {$0} let validatedAddresses = (config.providerConfiguration?[PCKeys.addresses.rawValue] as? String ?? "").commaSeparatedToArray().compactMap { try? CIDRAddress(stringRepresentation: String($0)) }.compactMap { $0 }