Avoid using 'VPN' in code where possible
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
6528a581de
commit
5ae9eec555
|
@ -20,10 +20,10 @@ enum TunnelsManagerError: WireGuardAppError {
|
||||||
// Tunnels list management
|
// Tunnels list management
|
||||||
case tunnelNameEmpty
|
case tunnelNameEmpty
|
||||||
case tunnelAlreadyExistsWithThatName
|
case tunnelAlreadyExistsWithThatName
|
||||||
case vpnSystemErrorOnListingTunnels
|
case systemErrorOnListingTunnels
|
||||||
case vpnSystemErrorOnAddTunnel
|
case systemErrorOnAddTunnel
|
||||||
case vpnSystemErrorOnModifyTunnel
|
case systemErrorOnModifyTunnel
|
||||||
case vpnSystemErrorOnRemoveTunnel
|
case systemErrorOnRemoveTunnel
|
||||||
|
|
||||||
// Tunnel activation
|
// Tunnel activation
|
||||||
case attemptingActivationWhenTunnelIsNotInactive
|
case attemptingActivationWhenTunnelIsNotInactive
|
||||||
|
@ -39,13 +39,13 @@ enum TunnelsManagerError: WireGuardAppError {
|
||||||
return ("No name provided", "Can't create tunnel with an empty name")
|
return ("No name provided", "Can't create tunnel with an empty name")
|
||||||
case .tunnelAlreadyExistsWithThatName:
|
case .tunnelAlreadyExistsWithThatName:
|
||||||
return ("Name already exists", "A tunnel with that name already exists")
|
return ("Name already exists", "A tunnel with that name already exists")
|
||||||
case .vpnSystemErrorOnListingTunnels:
|
case .systemErrorOnListingTunnels:
|
||||||
return ("Unable to list tunnels", "Internal error")
|
return ("Unable to list tunnels", "Internal error")
|
||||||
case .vpnSystemErrorOnAddTunnel:
|
case .systemErrorOnAddTunnel:
|
||||||
return ("Unable to create tunnel", "Internal error")
|
return ("Unable to create tunnel", "Internal error")
|
||||||
case .vpnSystemErrorOnModifyTunnel:
|
case .systemErrorOnModifyTunnel:
|
||||||
return ("Unable to modify tunnel", "Internal error")
|
return ("Unable to modify tunnel", "Internal error")
|
||||||
case .vpnSystemErrorOnRemoveTunnel:
|
case .systemErrorOnRemoveTunnel:
|
||||||
return ("Unable to remove tunnel", "Internal error")
|
return ("Unable to remove tunnel", "Internal error")
|
||||||
case .attemptingActivationWhenTunnelIsNotInactive:
|
case .attemptingActivationWhenTunnelIsNotInactive:
|
||||||
return ("Activation failure", "The tunnel is already active or in the process of being activated")
|
return ("Activation failure", "The tunnel is already active or in the process of being activated")
|
||||||
|
@ -83,7 +83,7 @@ class TunnelsManager {
|
||||||
NETunnelProviderManager.loadAllFromPreferences { managers, error in
|
NETunnelProviderManager.loadAllFromPreferences { managers, error in
|
||||||
if let error = error {
|
if let error = error {
|
||||||
os_log("Failed to load tunnel provider managers: %{public}@", log: OSLog.default, type: .debug, "\(error)")
|
os_log("Failed to load tunnel provider managers: %{public}@", log: OSLog.default, type: .debug, "\(error)")
|
||||||
completionHandler(.failure(TunnelsManagerError.vpnSystemErrorOnListingTunnels))
|
completionHandler(.failure(TunnelsManagerError.systemErrorOnListingTunnels))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
completionHandler(.success(TunnelsManager(tunnelProviders: managers ?? [])))
|
completionHandler(.success(TunnelsManager(tunnelProviders: managers ?? [])))
|
||||||
|
@ -115,7 +115,7 @@ class TunnelsManager {
|
||||||
tunnelProviderManager.saveToPreferences { [weak self] error in
|
tunnelProviderManager.saveToPreferences { [weak self] error in
|
||||||
guard error == nil else {
|
guard error == nil else {
|
||||||
os_log("Add: Saving configuration failed: %{public}@", log: OSLog.default, type: .error, "\(error!)")
|
os_log("Add: Saving configuration failed: %{public}@", log: OSLog.default, type: .error, "\(error!)")
|
||||||
completionHandler(.failure(TunnelsManagerError.vpnSystemErrorOnAddTunnel))
|
completionHandler(.failure(TunnelsManagerError.systemErrorOnAddTunnel))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if let self = self {
|
if let self = self {
|
||||||
|
@ -172,7 +172,7 @@ class TunnelsManager {
|
||||||
tunnelProviderManager.saveToPreferences { [weak self] error in
|
tunnelProviderManager.saveToPreferences { [weak self] error in
|
||||||
guard error == nil else {
|
guard error == nil else {
|
||||||
os_log("Modify: Saving configuration failed: %{public}@", log: OSLog.default, type: .error, "\(error!)")
|
os_log("Modify: Saving configuration failed: %{public}@", log: OSLog.default, type: .error, "\(error!)")
|
||||||
completionHandler(TunnelsManagerError.vpnSystemErrorOnModifyTunnel)
|
completionHandler(TunnelsManagerError.systemErrorOnModifyTunnel)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if let self = self {
|
if let self = self {
|
||||||
|
@ -197,7 +197,7 @@ class TunnelsManager {
|
||||||
tunnel.isActivateOnDemandEnabled = tunnelProviderManager.isOnDemandEnabled
|
tunnel.isActivateOnDemandEnabled = tunnelProviderManager.isOnDemandEnabled
|
||||||
guard error == nil else {
|
guard error == nil else {
|
||||||
os_log("Modify: Re-loading after saving configuration failed: %{public}@", log: OSLog.default, type: .error, "\(error!)")
|
os_log("Modify: Re-loading after saving configuration failed: %{public}@", log: OSLog.default, type: .error, "\(error!)")
|
||||||
completionHandler(TunnelsManagerError.vpnSystemErrorOnModifyTunnel)
|
completionHandler(TunnelsManagerError.systemErrorOnModifyTunnel)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
completionHandler(nil)
|
completionHandler(nil)
|
||||||
|
@ -215,7 +215,7 @@ class TunnelsManager {
|
||||||
tunnelProviderManager.removeFromPreferences { [weak self] error in
|
tunnelProviderManager.removeFromPreferences { [weak self] error in
|
||||||
guard error == nil else {
|
guard error == nil else {
|
||||||
os_log("Remove: Saving configuration failed: %{public}@", log: OSLog.default, type: .error, "\(error!)")
|
os_log("Remove: Saving configuration failed: %{public}@", log: OSLog.default, type: .error, "\(error!)")
|
||||||
completionHandler(TunnelsManagerError.vpnSystemErrorOnRemoveTunnel)
|
completionHandler(TunnelsManagerError.systemErrorOnRemoveTunnel)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if let self = self {
|
if let self = self {
|
||||||
|
@ -394,13 +394,13 @@ class TunnelContainer: NSObject {
|
||||||
os_log("startActivation: Success", log: OSLog.default, type: .debug)
|
os_log("startActivation: Success", log: OSLog.default, type: .debug)
|
||||||
completionHandler(nil)
|
completionHandler(nil)
|
||||||
} catch let error {
|
} catch let error {
|
||||||
guard let vpnError = error as? NEVPNError else {
|
guard let systemError = error as? NEVPNError else {
|
||||||
os_log("Failed to activate tunnel: Error: %{public}@", log: OSLog.default, type: .debug, "\(error)")
|
os_log("Failed to activate tunnel: Error: %{public}@", log: OSLog.default, type: .debug, "\(error)")
|
||||||
status = .inactive
|
status = .inactive
|
||||||
completionHandler(TunnelsManagerError.tunnelActivationAttemptFailed)
|
completionHandler(TunnelsManagerError.tunnelActivationAttemptFailed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
guard vpnError.code == NEVPNError.configurationInvalid || vpnError.code == NEVPNError.configurationStale else {
|
guard systemError.code == NEVPNError.configurationInvalid || systemError.code == NEVPNError.configurationStale else {
|
||||||
os_log("Failed to activate tunnel: VPN Error: %{public}@", log: OSLog.default, type: .debug, "\(error)")
|
os_log("Failed to activate tunnel: VPN Error: %{public}@", log: OSLog.default, type: .debug, "\(error)")
|
||||||
status = .inactive
|
status = .inactive
|
||||||
completionHandler(TunnelsManagerError.tunnelActivationAttemptFailed)
|
completionHandler(TunnelsManagerError.tunnelActivationAttemptFailed)
|
||||||
|
@ -416,7 +416,7 @@ class TunnelContainer: NSObject {
|
||||||
}
|
}
|
||||||
os_log("startActivation: Tunnel reloaded", log: OSLog.default, type: .info)
|
os_log("startActivation: Tunnel reloaded", log: OSLog.default, type: .info)
|
||||||
os_log("startActivation: Invoking startActivation", log: OSLog.default, type: .debug)
|
os_log("startActivation: Invoking startActivation", log: OSLog.default, type: .debug)
|
||||||
self?.startActivation(recursionCount: recursionCount + 1, lastError: vpnError, tunnelConfiguration: tunnelConfiguration, completionHandler: completionHandler)
|
self?.startActivation(recursionCount: recursionCount + 1, lastError: systemError, tunnelConfiguration: tunnelConfiguration, completionHandler: completionHandler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -435,8 +435,8 @@ class TunnelContainer: NSObject {
|
||||||
|
|
||||||
case restarting // Restarting tunnel (done after saving modifications to an active tunnel)
|
case restarting // Restarting tunnel (done after saving modifications to an active tunnel)
|
||||||
|
|
||||||
init(from vpnStatus: NEVPNStatus) {
|
init(from systemStatus: NEVPNStatus) {
|
||||||
switch vpnStatus {
|
switch systemStatus {
|
||||||
case .connected:
|
case .connected:
|
||||||
self = .active
|
self = .active
|
||||||
case .connecting:
|
case .connecting:
|
||||||
|
|
|
@ -83,7 +83,7 @@ class PacketTunnelSettingsGenerator {
|
||||||
|
|
||||||
let dnsServerStrings = tunnelConfiguration.interface.dns.map { $0.stringRepresentation() }
|
let dnsServerStrings = tunnelConfiguration.interface.dns.map { $0.stringRepresentation() }
|
||||||
let dnsSettings = NEDNSSettings(servers: dnsServerStrings)
|
let dnsSettings = NEDNSSettings(servers: dnsServerStrings)
|
||||||
dnsSettings.matchDomains = [""] // All DNS queries must first go through the VPN's DNS
|
dnsSettings.matchDomains = [""] // All DNS queries must first go through the tunnel's DNS
|
||||||
networkSettings.dnsSettings = dnsSettings
|
networkSettings.dnsSettings = dnsSettings
|
||||||
|
|
||||||
let mtu = tunnelConfiguration.interface.mtu ?? 0
|
let mtu = tunnelConfiguration.interface.mtu ?? 0
|
||||||
|
|
Loading…
Reference in New Issue