diff --git a/WireGuard/WireGuardNetworkExtension/DNSResolver.swift b/WireGuard/WireGuardNetworkExtension/DNSResolver.swift index 32cbf78..3929862 100644 --- a/WireGuard/WireGuardNetworkExtension/DNSResolver.swift +++ b/WireGuard/WireGuardNetworkExtension/DNSResolver.swift @@ -4,10 +4,6 @@ import Network import Foundation -enum DNSResolverError: Error { - case dnsResolutionFailed(hostnames: [String]) -} - class DNSResolver { static func isAllEndpointsAlreadyResolved(endpoints: [Endpoint?]) -> Bool { @@ -20,7 +16,7 @@ class DNSResolver { return true } - static func resolveSync(endpoints: [Endpoint?]) throws -> [Endpoint?] { + static func resolveSync(endpoints: [Endpoint?]) -> [Endpoint?]? { let dispatchGroup = DispatchGroup() if isAllEndpointsAlreadyResolved(endpoints: endpoints) { @@ -56,7 +52,8 @@ class DNSResolver { } } if !hostnamesWithDnsResolutionFailure.isEmpty { - throw DNSResolverError.dnsResolutionFailed(hostnames: hostnamesWithDnsResolutionFailure) + wg_log(.error, message: "DNS resolution failed for the following hostnames: \(hostnamesWithDnsResolutionFailure.joined(separator: ", "))") + return nil } return resolvedEndpoints } diff --git a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift index 8d71f0b..c418ebc 100644 --- a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift +++ b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift @@ -58,11 +58,9 @@ class PacketTunnelProvider: NEPacketTunnelProvider { errorNotifier.tunnelName = tunnelName let endpoints = tunnelConfiguration.peers.map { $0.endpoint } - guard let resolvedEndpoints = resolveDomainNames(endpoints: endpoints) else { - wg_log(.error, staticMessage: "Starting tunnel failed: DNS resolution failure") - let dnsError = PacketTunnelProviderError.dnsResolutionFailure - errorNotifier.notify(dnsError) - startTunnelCompletionHandler(dnsError) + guard let resolvedEndpoints = DNSResolver.resolveSync(endpoints: endpoints) else { + errorNotifier.notify(PacketTunnelProviderError.dnsResolutionFailure) + startTunnelCompletionHandler(PacketTunnelProviderError.dnsResolutionFailure) return } assert(endpoints.count == resolvedEndpoints.count) @@ -167,18 +165,6 @@ class PacketTunnelProvider: NEPacketTunnelProvider { } } - private func resolveDomainNames(endpoints: [Endpoint?]) -> [Endpoint?]? { - do { - return try DNSResolver.resolveSync(endpoints: endpoints) - } catch DNSResolverError.dnsResolutionFailed(let hostnames) { - wg_log(.error, message: "DNS resolution failed for the following hostnames: \(hostnames.joined(separator: ", "))") - } catch { - // There can be no other errors from DNSResolver.resolveSync() - fatalError() - } - return nil - } - private func connect(interfaceName: String, settings: String, fileDescriptor: Int32) -> Int32 { return withStringsAsGoStrings(interfaceName, settings) { return wgTurnOn($0.0, $0.1, fileDescriptor) } }