aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuardNetworkExtension
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-12-21 18:50:32 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2018-12-21 18:50:32 +0100
commitec031b1f19c7b85b52ef478b8dfe3f8e173cf046 (patch)
treec8c6e394d51a8c977c0f3b73f4389755a4fa4842 /WireGuard/WireGuardNetworkExtension
parentUpdated NETunnelProvider save format (diff)
downloadwireguard-apple-ec031b1f19c7b85b52ef478b8dfe3f8e173cf046.tar.xz
wireguard-apple-ec031b1f19c7b85b52ef478b8dfe3f8e173cf046.zip
Get rid of superflous isActivateOnDemandEnabled key
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift19
-rw-r--r--WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift17
2 files changed, 4 insertions, 32 deletions
diff --git a/WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift b/WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift
index 1b74d5d4..a9bcc144 100644
--- a/WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift
+++ b/WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift
@@ -9,7 +9,6 @@ class ErrorNotifier {
weak var tunnelProvider: NEPacketTunnelProvider?
var tunnelName: String?
- var isActivateOnDemandEnabled = false
init(activationAttemptId: String?, tunnelProvider: NEPacketTunnelProvider) {
self.activationAttemptId = activationAttemptId
@@ -31,21 +30,9 @@ class ErrorNotifier {
}
func notify(_ error: PacketTunnelProviderError) {
- guard let (title, message) = errorMessage(for: error) else { return }
- if let activationAttemptId = activationAttemptId, let lastErrorFilePath = FileManager.networkExtensionLastErrorFileURL?.path {
- // The tunnel was started from the app
- let onDemandMessage = isActivateOnDemandEnabled ? " This tunnel has Activate On Demand enabled, so this tunnel might be activated automatically. You may turn off Activate On Demand in the WireGuard app by navigating to: '\(tunnelName ?? "tunnel")' > Edit." : ""
- let errorMessageData = "\(activationAttemptId)\n\(title)\n\(message)\(onDemandMessage)".data(using: .utf8)
- FileManager.default.createFile(atPath: lastErrorFilePath, contents: errorMessageData, attributes: nil)
- } else {
- // The tunnel was probably started from iOS Settings app or activated on-demand
- if let tunnelProvider = self.tunnelProvider {
- // displayMessage() is deprecated, but there's no better alternative if invoked from iOS Settings
- if !isActivateOnDemandEnabled { // If using activate-on-demand, don't use displayMessage
- tunnelProvider.displayMessage("\(title): \(message)") { _ in }
- }
- }
- }
+ guard let (title, message) = errorMessage(for: error), let activationAttemptId = activationAttemptId, let lastErrorFilePath = FileManager.networkExtensionLastErrorFileURL?.path else { return }
+ let errorMessageData = "\(activationAttemptId)\n\(title)\n\(message)".data(using: .utf8)
+ FileManager.default.createFile(atPath: lastErrorFilePath, contents: errorMessageData, attributes: nil)
}
static func removeLastErrorFile() {
diff --git a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
index f32a0044..27a42c5d 100644
--- a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
+++ b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
@@ -24,7 +24,6 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
networkMonitor?.cancel()
}
- //swiftlint:disable:next function_body_length
override func startTunnel(options: [String: NSObject]?, completionHandler startTunnelCompletionHandler: @escaping (Error?) -> Void) {
let activationAttemptId = options?["activationAttemptId"] as? String
let errorNotifier = ErrorNotifier(activationAttemptId: activationAttemptId, tunnelProvider: self)
@@ -39,22 +38,8 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
configureLogger()
let tunnelName = tunnelConfiguration.interface.name
- wg_log(.info, message: "Starting tunnel '\(tunnelName)'")
+ wg_log(.info, message: "Starting tunnel '\(tunnelName)' from the " + (activationAttemptId == nil ? "OS directly, rather than the app" : "app"))
- if activationAttemptId != nil {
- wg_log(.info, staticMessage: "Tunnel activated from the app")
- } else {
- wg_log(.info, staticMessage: "Tunnel not activated from the app")
- }
-
- let isActivateOnDemandEnabled = tunnelProviderProtocol.isActivateOnDemandEnabled
- if isActivateOnDemandEnabled {
- wg_log(.info, staticMessage: "Tunnel has Activate On Demand enabled")
- } else {
- wg_log(.info, staticMessage: "Tunnel has Activate On Demand disabled")
- }
-
- errorNotifier.isActivateOnDemandEnabled = isActivateOnDemandEnabled
errorNotifier.tunnelName = tunnelName
let endpoints = tunnelConfiguration.peers.map { $0.endpoint }