aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2020-12-02 13:52:24 +0100
committerAndrej Mihajlov <and@mullvad.net>2020-12-03 13:22:52 +0100
commit697d449dc8fc3d6760139bb7563ed412f826fea2 (patch)
treec4feeb1d0d2c9ee49104179b8f02e93bb56f305e
parentWireGuardKit: Fix docs for WireGuardAdapterError (diff)
downloadwireguard-apple-697d449dc8fc3d6760139bb7563ed412f826fea2.tar.xz
wireguard-apple-697d449dc8fc3d6760139bb7563ed412f826fea2.zip
WireGuardKit: Remove isStarted: bool from WireGuardAdapter
Signed-off-by: Andrej Mihajlov <and@mullvad.net>
-rw-r--r--WireGuardKit/Sources/WireGuardKit/WireGuardAdapter.swift23
1 files changed, 6 insertions, 17 deletions
diff --git a/WireGuardKit/Sources/WireGuardKit/WireGuardAdapter.swift b/WireGuardKit/Sources/WireGuardKit/WireGuardAdapter.swift
index 236629e..12f7d23 100644
--- a/WireGuardKit/Sources/WireGuardKit/WireGuardAdapter.swift
+++ b/WireGuardKit/Sources/WireGuardKit/WireGuardAdapter.swift
@@ -44,9 +44,6 @@ public class WireGuardAdapter {
/// Private queue used to synchronize access to `WireGuardAdapter` members.
private let workQueue = DispatchQueue(label: "WireGuardAdapterWorkQueue")
- /// Flag that tells if the adapter has already started.
- private var isStarted = false
-
/// Packet tunnel settings generator.
private var settingsGenerator: PacketTunnelSettingsGenerator?
@@ -139,7 +136,7 @@ public class WireGuardAdapter {
/// - completionHandler: completion handler.
public func start(tunnelConfiguration: TunnelConfiguration, completionHandler: @escaping (WireGuardAdapterError?) -> Void) {
workQueue.async {
- guard !self.isStarted else {
+ guard self.wireguardHandle == nil else {
completionHandler(.invalidState)
return
}
@@ -170,7 +167,6 @@ public class WireGuardAdapter {
if handle >= 0 {
self.wireguardHandle = handle
- self.isStarted = true
} else {
returnError = .startWireGuardBackend(handle)
}
@@ -185,7 +181,7 @@ public class WireGuardAdapter {
/// - Parameter completionHandler: completion handler.
public func stop(completionHandler: @escaping (WireGuardAdapterError?) -> Void) {
workQueue.async {
- guard self.isStarted else {
+ guard let handle = self.wireguardHandle else {
completionHandler(.invalidState)
return
}
@@ -193,12 +189,8 @@ public class WireGuardAdapter {
self.networkMonitor?.cancel()
self.networkMonitor = nil
- if let handle = self.wireguardHandle {
- wgTurnOff(handle)
- self.wireguardHandle = nil
- }
-
- self.isStarted = false
+ wgTurnOff(handle)
+ self.wireguardHandle = nil
completionHandler(nil)
}
@@ -210,7 +202,7 @@ public class WireGuardAdapter {
/// - completionHandler: completion handler.
public func update(tunnelConfiguration: TunnelConfiguration, completionHandler: @escaping (WireGuardAdapterError?) -> Void) {
workQueue.async {
- guard self.isStarted else {
+ guard let handle = self.wireguardHandle else {
completionHandler(.invalidState)
return
}
@@ -224,9 +216,7 @@ public class WireGuardAdapter {
if let error = error {
completionHandler(error)
} else {
- if let handle = self.wireguardHandle {
- wgSetConfig(handle, settingsGenerator!.uapiConfiguration())
- }
+ wgSetConfig(handle, settingsGenerator!.uapiConfiguration())
completionHandler(nil)
}
@@ -339,7 +329,6 @@ public class WireGuardAdapter {
/// Helper method used by network path monitor.
/// - Parameter path: new network path
private func didReceivePathUpdate(path: Network.NWPath) {
- guard self.isStarted else { return }
if let handle = self.wireguardHandle {
self.handleLogLine(level: .debug, message: "Network change detected with \(path.status) route and interface order \(path.availableInterfaces)")