diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-12-22 03:41:54 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-12-22 03:42:01 +0100 |
commit | 8365adf4351c380004d2c871a81231083b2373cc (patch) | |
tree | fbc5b14bb9977c33bbe31a1a436cbc44d40e7b5a /WireGuard/WireGuardNetworkExtension | |
parent | RTL support (diff) | |
download | wireguard-apple-8365adf4351c380004d2c871a81231083b2373cc.tar.xz wireguard-apple-8365adf4351c380004d2c871a81231083b2373cc.zip |
Localize remaining strings in network extension
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r-- | WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift | 22 | ||||
-rw-r--r-- | WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift | 21 |
2 files changed, 10 insertions, 33 deletions
diff --git a/WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift b/WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift index ac1a636..43aa0d7 100644 --- a/WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift +++ b/WireGuard/WireGuardNetworkExtension/ErrorNotifier.swift @@ -4,32 +4,16 @@ import NetworkExtension class ErrorNotifier { - let activationAttemptId: String? - weak var tunnelProvider: NEPacketTunnelProvider? - init(activationAttemptId: String?, tunnelProvider: NEPacketTunnelProvider) { + init(activationAttemptId: String?) { self.activationAttemptId = activationAttemptId - self.tunnelProvider = tunnelProvider ErrorNotifier.removeLastErrorFile() } - func errorMessage(for error: PacketTunnelProviderError) -> (String, String)? { - switch error { - case .savedProtocolConfigurationIsInvalid: - return ("Activation failure", "Could not retrieve tunnel information from the saved configuration.") - case .dnsResolutionFailure: - return ("DNS resolution failure", "One or more endpoint domains could not be resolved.") - case .couldNotStartWireGuard: - return ("Activation failure", "WireGuard backend could not be started.") - case .coultNotSetNetworkSettings: - return ("Activation failure", "Error applying network settings on the tunnel.") - } - } - func notify(_ error: PacketTunnelProviderError) { - 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) + guard let activationAttemptId = activationAttemptId, let lastErrorFilePath = FileManager.networkExtensionLastErrorFileURL?.path else { return } + let errorMessageData = "\(activationAttemptId)\n\(error)".data(using: .utf8) FileManager.default.createFile(atPath: lastErrorFilePath, contents: errorMessageData, attributes: nil) } diff --git a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift index bcec9b2..bc4b542 100644 --- a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift +++ b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift @@ -6,13 +6,6 @@ import Network import NetworkExtension import os.log -enum PacketTunnelProviderError: Error { - case savedProtocolConfigurationIsInvalid - case dnsResolutionFailure - case couldNotStartWireGuard - case coultNotSetNetworkSettings -} - class PacketTunnelProvider: NEPacketTunnelProvider { private var wgHandle: Int32? @@ -26,7 +19,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider { override func startTunnel(options: [String: NSObject]?, completionHandler startTunnelCompletionHandler: @escaping (Error?) -> Void) { let activationAttemptId = options?["activationAttemptId"] as? String - let errorNotifier = ErrorNotifier(activationAttemptId: activationAttemptId, tunnelProvider: self) + let errorNotifier = ErrorNotifier(activationAttemptId: activationAttemptId) guard let tunnelProviderProtocol = protocolConfiguration as? NETunnelProviderProtocol, let tunnelConfiguration = tunnelProviderProtocol.asTunnelConfiguration() else { @@ -52,8 +45,8 @@ class PacketTunnelProvider: NEPacketTunnelProvider { let fileDescriptor = packetFlow.value(forKeyPath: "socket.fileDescriptor") as! Int32 //swiftlint:disable:this force_cast if fileDescriptor < 0 { wg_log(.error, staticMessage: "Starting tunnel failed: Could not determine file descriptor") - errorNotifier.notify(PacketTunnelProviderError.couldNotStartWireGuard) - startTunnelCompletionHandler(PacketTunnelProviderError.couldNotStartWireGuard) + errorNotifier.notify(PacketTunnelProviderError.couldNotDetermineFileDescriptor) + startTunnelCompletionHandler(PacketTunnelProviderError.couldNotDetermineFileDescriptor) return } @@ -67,8 +60,8 @@ class PacketTunnelProvider: NEPacketTunnelProvider { let handle = wireguardSettings.withGoString { return wgTurnOn($0, fileDescriptor) } if handle < 0 { wg_log(.error, message: "Starting tunnel failed with wgTurnOn returning \(handle)") - errorNotifier.notify(PacketTunnelProviderError.couldNotStartWireGuard) - startTunnelCompletionHandler(PacketTunnelProviderError.couldNotStartWireGuard) + errorNotifier.notify(PacketTunnelProviderError.couldNotStartBackend) + startTunnelCompletionHandler(PacketTunnelProviderError.couldNotStartBackend) return } wgHandle = handle @@ -77,8 +70,8 @@ class PacketTunnelProvider: NEPacketTunnelProvider { setTunnelNetworkSettings(networkSettings) { error in if let error = error { wg_log(.error, message: "Starting tunnel failed with setTunnelNetworkSettings returning \(error.localizedDescription)") - errorNotifier.notify(PacketTunnelProviderError.coultNotSetNetworkSettings) - startTunnelCompletionHandler(PacketTunnelProviderError.coultNotSetNetworkSettings) + errorNotifier.notify(PacketTunnelProviderError.couldNotSetNetworkSettings) + startTunnelCompletionHandler(PacketTunnelProviderError.couldNotSetNetworkSettings) } else { startTunnelCompletionHandler(nil) } |