aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Kuck <eric@bluelinelabs.com>2018-12-16 23:51:25 -0600
committerEric Kuck <eric@bluelinelabs.com>2018-12-16 23:51:25 -0600
commited9b4c85edd17b2b9361f8c7a1a83f91f98cdb8f (patch)
tree5ba59b66646fe7eae8041558cb160506f4cba642
parentPotential fix for insertRowAtIndexPath crash (diff)
downloadwireguard-apple-ed9b4c85edd17b2b9361f8c7a1a83f91f98cdb8f.tar.xz
wireguard-apple-ed9b4c85edd17b2b9361f8c7a1a83f91f98cdb8f.zip
Got TunnelsManager back under the max file length by splitting out NEVPNStatus+CustomStringConvertible
Signed-off-by: Eric Kuck <eric@bluelinelabs.com>
-rw-r--r--WireGuard/WireGuard.xcodeproj/project.pbxproj4
-rw-r--r--WireGuard/WireGuard/Tunnel/NEVPNStatus+CustomStringConvertible.swift18
-rw-r--r--WireGuard/WireGuard/Tunnel/TunnelsManager.swift24
-rw-r--r--WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift1
-rw-r--r--WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift1
-rw-r--r--WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift15
6 files changed, 28 insertions, 35 deletions
diff --git a/WireGuard/WireGuard.xcodeproj/project.pbxproj b/WireGuard/WireGuard.xcodeproj/project.pbxproj
index 6b77eaef..7bb7d0a6 100644
--- a/WireGuard/WireGuard.xcodeproj/project.pbxproj
+++ b/WireGuard/WireGuard.xcodeproj/project.pbxproj
@@ -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 */; };
@@ -111,6 +112,7 @@
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; };
@@ -300,6 +302,7 @@
6FFA5DA32197085D0001E2F7 /* ActivateOnDemandSetting.swift */,
5F4541A821C451D100994C13 /* TunnelStatus.swift */,
6FB1017821C57DE600766195 /* MockTunnels.swift */,
+ 5F4541AD21C7704300994C13 /* NEVPNStatus+CustomStringConvertible.swift */,
);
path = Tunnel;
sourceTree = "<group>";
@@ -678,6 +681,7 @@
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
index 00000000..0668b8a5
--- /dev/null
+++ b/WireGuard/WireGuard/Tunnel/NEVPNStatus+CustomStringConvertible.swift
@@ -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"
+ }
+ }
+}
diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
index ff8c720b..2785be4c 100644
--- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
+++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
@@ -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"
- }
- }
-}
diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift
index 82e6f81a..1e480b96 100644
--- a/WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift
@@ -24,7 +24,6 @@ class MainViewController: UISplitViewController {
viewControllers = [ masterNC, detailNC ]
- // State restoration
restorationIdentifier = "MainVC"
masterNC.restorationIdentifier = "MasterNC"
detailNC.restorationIdentifier = "DetailNC"
diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift
index 0188c627..05961394 100644
--- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift
@@ -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)
}
diff --git a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
index 0bc79158..8fd5cad6 100644
--- a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
+++ b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
@@ -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