aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuardNetworkExtension
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-11-08 16:40:38 +0530
committerRoopesh Chander <roop@roopc.net>2018-11-08 17:52:11 +0530
commitc17e4a27a2192c28a1c4d6ba58c4c33040a2d8bf (patch)
treee0ce4ecdbac1881f40b585e7653fcbe8266298d2 /WireGuard/WireGuardNetworkExtension
parentDNSResolver: Let's not cache DNS resolution results anymore (diff)
downloadwireguard-apple-c17e4a27a2192c28a1c4d6ba58c4c33040a2d8bf.tar.xz
wireguard-apple-c17e4a27a2192c28a1c4d6ba58c4c33040a2d8bf.zip
DNSResolver: Simplify
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuardNetworkExtension')
-rw-r--r--WireGuard/WireGuardNetworkExtension/DNSResolver.swift34
1 files changed, 6 insertions, 28 deletions
diff --git a/WireGuard/WireGuardNetworkExtension/DNSResolver.swift b/WireGuard/WireGuardNetworkExtension/DNSResolver.swift
index d69b96d..0874fd9 100644
--- a/WireGuard/WireGuardNetworkExtension/DNSResolver.swift
+++ b/WireGuard/WireGuardNetworkExtension/DNSResolver.swift
@@ -9,18 +9,9 @@ enum DNSResolverError: Error {
}
class DNSResolver {
- let endpoints: [Endpoint?]
- let dispatchGroup: DispatchGroup
- var dispatchWorkItems: [DispatchWorkItem]
- init(endpoints: [Endpoint?]) {
- self.endpoints = endpoints
- self.dispatchWorkItems = []
- self.dispatchGroup = DispatchGroup()
- }
-
- func isAllEndpointsAlreadyResolved() -> Bool {
- for endpoint in self.endpoints {
+ static func isAllEndpointsAlreadyResolved(endpoints: [Endpoint?]) -> Bool {
+ for endpoint in endpoints {
guard let endpoint = endpoint else { continue }
if (!endpoint.hasHostAsIPAddress()) {
return false
@@ -29,17 +20,15 @@ class DNSResolver {
return true
}
- func resolveSync() throws -> [Endpoint?] {
- let endpoints = self.endpoints
- let dispatchGroup = self.dispatchGroup
- dispatchWorkItems = []
+ static func resolveSync(endpoints: [Endpoint?]) throws -> [Endpoint?] {
+ let dispatchGroup: DispatchGroup = DispatchGroup()
- if (isAllEndpointsAlreadyResolved()) {
+ if (isAllEndpointsAlreadyResolved(endpoints: endpoints)) {
return endpoints
}
var resolvedEndpoints: [Endpoint?] = Array<Endpoint?>(repeating: nil, count: endpoints.count)
- for (i, endpoint) in self.endpoints.enumerated() {
+ for (i, endpoint) in endpoints.enumerated() {
guard let endpoint = endpoint else { continue }
if (endpoint.hasHostAsIPAddress()) {
resolvedEndpoints[i] = endpoint
@@ -47,7 +36,6 @@ class DNSResolver {
let workItem = DispatchWorkItem {
resolvedEndpoints[i] = DNSResolver.resolveSync(endpoint: endpoint)
}
- dispatchWorkItems.append(workItem)
DispatchQueue.global(qos: .userInitiated).async(group: dispatchGroup, execute: workItem)
}
}
@@ -72,16 +60,6 @@ class DNSResolver {
}
return resolvedEndpoints
}
-
- func cancel() {
- for workItem in dispatchWorkItems {
- workItem.cancel()
- }
- }
-
- deinit {
- cancel()
- }
}
extension DNSResolver {