]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
Got TunnelsManager back under the max file length by splitting out NEVPNStatus+Custom...
authorEric Kuck <eric@bluelinelabs.com>
Mon, 17 Dec 2018 05:51:25 +0000 (23:51 -0600)
committerEric Kuck <eric@bluelinelabs.com>
Mon, 17 Dec 2018 05:51:25 +0000 (23:51 -0600)
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
WireGuard/WireGuard.xcodeproj/project.pbxproj
WireGuard/WireGuard/Tunnel/NEVPNStatus+CustomStringConvertible.swift [new file with mode: 0644]
WireGuard/WireGuard/Tunnel/TunnelsManager.swift
WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift
WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift
WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift

index 6b77eaefb3685d911f19abf11e11e2596638c185..7bb7d0a61b10323b5557eeab3284e587b941bb86 100644 (file)
@@ -16,6 +16,7 @@
                5F4541A221C2D6DF00994C13 /* BorderedTextButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F4541A121C2D6DF00994C13 /* BorderedTextButton.swift */; };
                5F4541A621C4449E00994C13 /* ButtonCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F4541A521C4449E00994C13 /* ButtonCell.swift */; };
                5F4541A921C451D100994C13 /* TunnelStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F4541A821C451D100994C13 /* TunnelStatus.swift */; };
+               5F4541AE21C7704300994C13 /* NEVPNStatus+CustomStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F4541AD21C7704300994C13 /* NEVPNStatus+CustomStringConvertible.swift */; };
                6F5A2B4621AFDED40081EDD8 /* FileManager+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F5A2B4421AFDE020081EDD8 /* FileManager+Extension.swift */; };
                6F5A2B4821AFF49A0081EDD8 /* FileManager+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F5A2B4421AFDE020081EDD8 /* FileManager+Extension.swift */; };
                6F5D0C1D218352EF000F85AD /* PacketTunnelProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F5D0C1C218352EF000F85AD /* PacketTunnelProvider.swift */; };
                5F4541A121C2D6DF00994C13 /* BorderedTextButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BorderedTextButton.swift; sourceTree = "<group>"; };
                5F4541A521C4449E00994C13 /* ButtonCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonCell.swift; sourceTree = "<group>"; };
                5F4541A821C451D100994C13 /* TunnelStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelStatus.swift; sourceTree = "<group>"; };
+               5F4541AD21C7704300994C13 /* NEVPNStatus+CustomStringConvertible.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NEVPNStatus+CustomStringConvertible.swift"; sourceTree = "<group>"; };
                6F5A2B4421AFDE020081EDD8 /* FileManager+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FileManager+Extension.swift"; sourceTree = "<group>"; };
                6F5D0C1421832391000F85AD /* DNSResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DNSResolver.swift; sourceTree = "<group>"; };
                6F5D0C1A218352EF000F85AD /* WireGuardNetworkExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = WireGuardNetworkExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
                                6FFA5DA32197085D0001E2F7 /* ActivateOnDemandSetting.swift */,
                                5F4541A821C451D100994C13 /* TunnelStatus.swift */,
                                6FB1017821C57DE600766195 /* MockTunnels.swift */,
+                               5F4541AD21C7704300994C13 /* NEVPNStatus+CustomStringConvertible.swift */,
                        );
                        path = Tunnel;
                        sourceTree = "<group>";
                                6FDEF8082187442100D8FBF6 /* WgQuickConfigFileWriter.swift in Sources */,
                                6FE254FB219C10800028284D /* ZipImporter.swift in Sources */,
                                6F7774EA217229DB006A79B3 /* IPAddressRange.swift in Sources */,
+                               5F4541AE21C7704300994C13 /* NEVPNStatus+CustomStringConvertible.swift in Sources */,
                                6F7774E82172020C006A79B3 /* Configuration.swift in Sources */,
                                6FDEF7FB21863B6100D8FBF6 /* unzip.c in Sources */,
                                6F6899A8218044FC0012E523 /* Curve25519.swift in Sources */,
diff --git a/WireGuard/WireGuard/Tunnel/NEVPNStatus+CustomStringConvertible.swift b/WireGuard/WireGuard/Tunnel/NEVPNStatus+CustomStringConvertible.swift
new file mode 100644 (file)
index 0000000..0668b8a
--- /dev/null
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: MIT
+// Copyright © 2018 WireGuard LLC. All Rights Reserved.
+
+import Foundation
+import NetworkExtension
+
+extension NEVPNStatus: CustomDebugStringConvertible {
+    public var debugDescription: String {
+        switch self {
+        case .connected: return "connected"
+        case .connecting: return "connecting"
+        case .disconnected: return "disconnected"
+        case .disconnecting: return "disconnecting"
+        case .reasserting: return "reasserting"
+        case .invalid: return "invalid"
+        }
+    }
+}
index ff8c720b350aa9ae5be7c11bbb5b037583df7834..2785be4ca4124bee8fadc5b8271ac7ac990858ef 100644 (file)
@@ -79,7 +79,6 @@ enum TunnelsManagerError: WireGuardAppError {
 }
 
 class TunnelsManager {
-
     private var tunnels: [TunnelContainer]
     weak var tunnelsListDelegate: TunnelsManagerListDelegate?
     weak var activationDelegate: TunnelsManagerActivationDelegate?
@@ -166,9 +165,9 @@ class TunnelsManager {
         }
 
         let tunnelProviderManager = tunnel.tunnelProvider
-        let isNameChanged = (tunnelName != tunnelProviderManager.localizedDescription)
+        let isNameChanged = tunnelName != tunnelProviderManager.localizedDescription
         if isNameChanged {
-            if tunnels.contains(where: { $0.name == tunnelName }) {
+            guard !tunnels.contains(where: { $0.name == tunnelName }) else {
                 completionHandler(TunnelsManagerError.tunnelAlreadyExistsWithThatName)
                 return
             }
@@ -178,7 +177,7 @@ class TunnelsManager {
         tunnelProviderManager.localizedDescription = tunnelName
         tunnelProviderManager.isEnabled = true
 
-        let isActivatingOnDemand = (!tunnelProviderManager.isOnDemandEnabled && activateOnDemandSetting.isActivateOnDemandEnabled)
+        let isActivatingOnDemand = !tunnelProviderManager.isOnDemandEnabled && activateOnDemandSetting.isActivateOnDemandEnabled
         activateOnDemandSetting.apply(on: tunnelProviderManager)
 
         tunnelProviderManager.saveToPreferences { [weak self] error in
@@ -187,7 +186,6 @@ class TunnelsManager {
                 completionHandler(TunnelsManagerError.systemErrorOnModifyTunnel)
                 return
             }
-            
             guard let self = self else { return }
             
             if isNameChanged {
@@ -439,8 +437,7 @@ class TunnelContainer: NSObject {
                 }
                 wg_log(.debug, staticMessage: "startActivation: Tunnel saved after re-enabling")
                 wg_log(.debug, staticMessage: "startActivation: Invoking startActivation")
-                self.startActivation(recursionCount: recursionCount + 1, lastError: NEVPNError(NEVPNError.configurationUnknown),
-                                     activationDelegate: activationDelegate)
+                self.startActivation(recursionCount: recursionCount + 1, lastError: NEVPNError(NEVPNError.configurationUnknown), activationDelegate: activationDelegate)
             }
             return
         }
@@ -488,16 +485,3 @@ class TunnelContainer: NSObject {
         (tunnelProvider.connection as? NETunnelProviderSession)?.stopTunnel()
     }
 }
-
-extension NEVPNStatus: CustomDebugStringConvertible {
-    public var debugDescription: String {
-        switch self {
-        case .connected: return "connected"
-        case .connecting: return "connecting"
-        case .disconnected: return "disconnected"
-        case .disconnecting: return "disconnecting"
-        case .reasserting: return "reasserting"
-        case .invalid: return "invalid"
-        }
-    }
-}
index 82e6f81ae197b0b9ddfc276e2c6129a2d2775a00..1e480b96f025af4b516c88a99abcbaf826303ad8 100644 (file)
@@ -24,7 +24,6 @@ class MainViewController: UISplitViewController {
 
         viewControllers = [ masterNC, detailNC ]
 
-        // State restoration
         restorationIdentifier = "MainVC"
         masterNC.restorationIdentifier = "MasterNC"
         detailNC.restorationIdentifier = "DetailNC"
index 0188c62766f1ac5895315e8191da23ce302c1366..05961394085b12998c953fc3acdc67206b44e5ca 100644 (file)
@@ -89,7 +89,6 @@ class TunnelsListTableViewController: UIViewController {
     }
 
     override func viewWillAppear(_: Bool) {
-        // Remove selection when getting back to the list view on iPhone
         if let selectedRowIndexPath = tableView.indexPathForSelectedRow {
             tableView.deselectRow(at: selectedRowIndexPath, animated: false)
         }
index 0bc791583554cc658207035bb514c88f6a52c3b3..8fd5cad60d40eb356351120620765ba66e84ee75 100644 (file)
@@ -13,17 +13,12 @@ enum PacketTunnelProviderError: Error {
     case coultNotSetNetworkSettings
 }
 
-/// A packet tunnel provider object.
 class PacketTunnelProvider: NEPacketTunnelProvider {
-
-    // MARK: Properties
-
+    
     private var wgHandle: Int32?
 
     private var networkMonitor: NWPathMonitor?
 
-    // MARK: NEPacketTunnelProvider
-
     deinit {
         networkMonitor?.cancel()
     }
@@ -45,7 +40,6 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
 
     //swiftlint:disable:next function_body_length
     func startTunnel(with tunnelConfiguration: TunnelConfiguration, errorNotifier: ErrorNotifier, completionHandler startTunnelCompletionHandler: @escaping (Error?) -> Void) {
-
         configureLogger()
 
         wg_log(.info, message: "Starting tunnel '\(tunnelConfiguration.interface.name)'")
@@ -66,8 +60,6 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
         }
         assert(endpoints.count == resolvedEndpoints.count)
 
-        // Setup packetTunnelSettingsGenerator
-
         let packetTunnelSettingsGenerator = PacketTunnelSettingsGenerator(tunnelConfiguration: tunnelConfiguration, resolvedEndpoints: resolvedEndpoints)
 
         // Bring up wireguard-go backend
@@ -110,8 +102,6 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
 
         wgHandle = handle
 
-        // Apply network settings
-
         let networkSettings: NEPacketTunnelNetworkSettings = packetTunnelSettingsGenerator.generateNetworkSettings()
         setTunnelNetworkSettings(networkSettings) { error in
             if let error = error {
@@ -120,12 +110,11 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
                 errorNotifier.notify(PacketTunnelProviderError.coultNotSetNetworkSettings)
                 startTunnelCompletionHandler(PacketTunnelProviderError.coultNotSetNetworkSettings)
             } else {
-                startTunnelCompletionHandler(nil /* No errors */)
+                startTunnelCompletionHandler(nil)
             }
         }
     }
 
-    /// Begin the process of stopping the tunnel.
     override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
         networkMonitor?.cancel()
         networkMonitor = nil