]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
DNSResolver: No need to resolve if the endpoint is already an IP address
authorRoopesh Chander <roop@roopc.net>
Tue, 6 Nov 2018 18:08:02 +0000 (23:38 +0530)
committerRoopesh Chander <roop@roopc.net>
Tue, 6 Nov 2018 18:29:48 +0000 (23:59 +0530)
Signed-off-by: Roopesh Chander <roop@roopc.net>
WireGuard/WireGuard/VPN/DNSResolver.swift

index e75045473a39d48d543cd5d60127540b2f24095e..6b7b73b7ec4116d13bbaff977a83df7574d07ccc 100644 (file)
@@ -20,7 +20,9 @@ class DNSResolver {
         var resolvedEndpoints: [Endpoint?] = Array<Endpoint?>(repeating: nil, count: endpoints.count)
         for (i, endpoint) in self.endpoints.enumerated() {
             guard let endpoint = endpoint else { continue }
-            if let resolvedEndpointStringInCache = DNSResolver.cache.object(forKey: endpoint.stringRepresentation() as NSString),
+            if (endpoint.hasHostAsIPAddress()) {
+                resolvedEndpoints[i] = endpoint
+            } else if let resolvedEndpointStringInCache = DNSResolver.cache.object(forKey: endpoint.stringRepresentation() as NSString),
                 let resolvedEndpointInCache = Endpoint(from: resolvedEndpointStringInCache as String) {
                 resolvedEndpoints[i] = resolvedEndpointInCache
             } else {
@@ -38,7 +40,9 @@ class DNSResolver {
         var isResolvedByDNSRequest: [Bool] = Array<Bool>(repeating: false, count: endpoints.count)
         for (i, endpoint) in self.endpoints.enumerated() {
             guard let endpoint = endpoint else { continue }
-            if let resolvedEndpointStringInCache = DNSResolver.cache.object(forKey: endpoint.stringRepresentation() as NSString),
+            if (endpoint.hasHostAsIPAddress()) {
+                resolvedEndpoints[i] = endpoint
+            } else if let resolvedEndpointStringInCache = DNSResolver.cache.object(forKey: endpoint.stringRepresentation() as NSString),
                 let resolvedEndpointInCache = Endpoint(from: resolvedEndpointStringInCache as String) {
                 resolvedEndpoints[i] = resolvedEndpointInCache
             } else {