aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/Tunnel
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-03-08 16:12:54 +0530
committerJason A. Donenfeld <Jason@zx2c4.com>2019-03-18 06:46:55 +0100
commit062b4d4b16bbe1b64a679a4fd77599380a9742d0 (patch)
tree1519c3d399dc914083ee091cbeab625089f06f69 /WireGuard/WireGuard/Tunnel
parenton-demand: TunnelViewModel: Remove unused on-demand-related methods (diff)
downloadwireguard-apple-062b4d4b16bbe1b64a679a4fd77599380a9742d0.tar.xz
wireguard-apple-062b4d4b16bbe1b64a679a4fd77599380a9742d0.zip
on-demand: Remove ActivateOnDemandSetting type
The ActivateOnDemandOption type shall be used instead Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/Tunnel')
-rw-r--r--WireGuard/WireGuard/Tunnel/ActivateOnDemandOption.swift (renamed from WireGuard/WireGuard/Tunnel/ActivateOnDemandSetting.swift)38
-rw-r--r--WireGuard/WireGuard/Tunnel/TunnelsManager.swift14
2 files changed, 14 insertions, 38 deletions
diff --git a/WireGuard/WireGuard/Tunnel/ActivateOnDemandSetting.swift b/WireGuard/WireGuard/Tunnel/ActivateOnDemandOption.swift
index 89edd777..8b39f8cf 100644
--- a/WireGuard/WireGuard/Tunnel/ActivateOnDemandSetting.swift
+++ b/WireGuard/WireGuard/Tunnel/ActivateOnDemandOption.swift
@@ -3,13 +3,8 @@
import NetworkExtension
-struct ActivateOnDemandSetting {
- var isActivateOnDemandEnabled: Bool
- var activateOnDemandOption: ActivateOnDemandOption
-}
-
enum ActivateOnDemandOption: Equatable {
- case none // Valid only when isActivateOnDemandEnabled is false
+ case off
case wiFiInterfaceOnly(ActivateOnDemandSSIDOption)
case nonWiFiInterfaceOnly
case anyInterface(ActivateOnDemandSSIDOption)
@@ -29,12 +24,11 @@ enum ActivateOnDemandSSIDOption: Equatable {
case exceptSpecificSSIDs([String])
}
-extension ActivateOnDemandSetting {
+extension ActivateOnDemandOption {
func apply(on tunnelProviderManager: NETunnelProviderManager) {
- tunnelProviderManager.isOnDemandEnabled = isActivateOnDemandEnabled
let rules: [NEOnDemandRule]?
- switch activateOnDemandOption {
- case .none:
+ switch self {
+ case .off:
rules = nil
case .wiFiInterfaceOnly(let ssidOption):
rules = ssidOnDemandRules(option: ssidOption) + [NEOnDemandRuleDisconnect(interfaceType: nonWiFiInterfaceType)]
@@ -48,6 +42,7 @@ extension ActivateOnDemandSetting {
}
}
tunnelProviderManager.onDemandRules = rules
+ tunnelProviderManager.isOnDemandEnabled = self != .off
}
init(from tunnelProviderManager: NETunnelProviderManager) {
@@ -55,7 +50,7 @@ extension ActivateOnDemandSetting {
let activateOnDemandOption: ActivateOnDemandOption
switch rules.count {
case 0:
- activateOnDemandOption = .none
+ activateOnDemandOption = .off
case 1:
let rule = rules[0]
precondition(rule.action == .connect)
@@ -90,19 +85,10 @@ extension ActivateOnDemandSetting {
fatalError("Unexpected number of onDemandRules set on tunnel provider manager")
}
- self.activateOnDemandOption = activateOnDemandOption
- if activateOnDemandOption == .none {
- isActivateOnDemandEnabled = false
- } else {
- isActivateOnDemandEnabled = tunnelProviderManager.isOnDemandEnabled
- }
+ self = activateOnDemandOption
}
}
-extension ActivateOnDemandSetting {
- static var defaultSetting = ActivateOnDemandSetting(isActivateOnDemandEnabled: false, activateOnDemandOption: .none)
-}
-
private extension NEOnDemandRuleConnect {
convenience init(interfaceType: NEOnDemandRuleInterfaceType, ssids: [String]? = nil) {
self.init()
@@ -132,13 +118,3 @@ private func ssidOnDemandRules(option: ActivateOnDemandSSIDOption) -> [NEOnDeman
NEOnDemandRuleConnect(interfaceType: .wiFi)]
}
}
-
-extension ActivateOnDemandSetting {
- init(with option: ActivateOnDemandOption) {
- if option == .none {
- self = ActivateOnDemandSetting(isActivateOnDemandEnabled: false, activateOnDemandOption: option)
- } else {
- self = ActivateOnDemandSetting(isActivateOnDemandEnabled: true, activateOnDemandOption: option)
- }
- }
-}
diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
index 1a467f56..8f4c87ce 100644
--- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
+++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
@@ -97,7 +97,7 @@ class TunnelsManager {
}
}
- func add(tunnelConfiguration: TunnelConfiguration, activateOnDemandSetting: ActivateOnDemandSetting = ActivateOnDemandSetting.defaultSetting, completionHandler: @escaping (WireGuardResult<TunnelContainer>) -> Void) {
+ func add(tunnelConfiguration: TunnelConfiguration, onDemandOption: ActivateOnDemandOption = .off, completionHandler: @escaping (WireGuardResult<TunnelContainer>) -> Void) {
let tunnelName = tunnelConfiguration.name ?? ""
if tunnelName.isEmpty {
completionHandler(.failure(TunnelsManagerError.tunnelNameEmpty))
@@ -113,7 +113,7 @@ class TunnelsManager {
tunnelProviderManager.setTunnelConfiguration(tunnelConfiguration)
tunnelProviderManager.isEnabled = true
- activateOnDemandSetting.apply(on: tunnelProviderManager)
+ onDemandOption.apply(on: tunnelProviderManager)
let activeTunnel = tunnels.first { $0.status == .active || $0.status == .activating }
@@ -167,7 +167,7 @@ class TunnelsManager {
}
}
- func modify(tunnel: TunnelContainer, tunnelConfiguration: TunnelConfiguration, activateOnDemandSetting: ActivateOnDemandSetting, completionHandler: @escaping (TunnelsManagerError?) -> Void) {
+ func modify(tunnel: TunnelContainer, tunnelConfiguration: TunnelConfiguration, onDemandOption: ActivateOnDemandOption, completionHandler: @escaping (TunnelsManagerError?) -> Void) {
let tunnelName = tunnelConfiguration.name ?? ""
if tunnelName.isEmpty {
completionHandler(TunnelsManagerError.tunnelNameEmpty)
@@ -191,8 +191,8 @@ class TunnelsManager {
}
tunnelProviderManager.isEnabled = true
- let isActivatingOnDemand = !tunnelProviderManager.isOnDemandEnabled && activateOnDemandSetting.isActivateOnDemandEnabled
- activateOnDemandSetting.apply(on: tunnelProviderManager)
+ let isActivatingOnDemand = !tunnelProviderManager.isOnDemandEnabled && onDemandOption != .off
+ onDemandOption.apply(on: tunnelProviderManager)
tunnelProviderManager.saveToPreferences { [weak self] error in
guard error == nil else {
@@ -455,8 +455,8 @@ class TunnelContainer: NSObject {
return tunnelProvider.tunnelConfiguration
}
- var activateOnDemandSetting: ActivateOnDemandSetting {
- return ActivateOnDemandSetting(from: tunnelProvider)
+ var onDemandOption: ActivateOnDemandOption {
+ return ActivateOnDemandOption(from: tunnelProvider)
}
init(tunnel: NETunnelProviderManager) {