From 4a71c0e98e59994b1beda3862e3411795fde6e54 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Sun, 28 Oct 2018 17:46:18 +0530 Subject: [PATCH] VPN: Remove ability to deactivate the tunnel while resolving DNS --- WireGuard/WireGuard/VPN/TunnelsManager.swift | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/WireGuard/WireGuard/VPN/TunnelsManager.swift b/WireGuard/WireGuard/VPN/TunnelsManager.swift index 2bbbac2..37b4b90 100644 --- a/WireGuard/WireGuard/VPN/TunnelsManager.swift +++ b/WireGuard/WireGuard/VPN/TunnelsManager.swift @@ -13,7 +13,6 @@ protocol TunnelsManagerDelegate: class { enum TunnelsManagerError: Error { case dnsResolutionFailed - case dnsResolutionCancelled case tunnelOperationFailed case attemptingActivationWhenAnotherTunnelIsActive case attemptingActivationWhenTunnelIsNotInactive @@ -252,16 +251,13 @@ class TunnelContainer: NSObject { status = .resolvingEndpointDomains dnsResolver.resolve { [weak self] endpoints in guard let s = self else { return } - if (s.dnsResolver == nil) { - s.status = .inactive - completionHandler(TunnelsManagerError.dnsResolutionCancelled) - return - } + assert(s.status == .resolvingEndpointDomains) + s.dnsResolver = nil guard let endpoints = endpoints else { completionHandler(TunnelsManagerError.dnsResolutionFailed) + s.status = .inactive return } - s.dnsResolver = nil s.startObservingTunnelStatus() let session = (s.tunnelProvider.connection as! NETunnelProviderSession) do { @@ -276,12 +272,10 @@ class TunnelContainer: NSObject { } fileprivate func startDeactivation() { - if (status != .inactive) { - dnsResolver = nil - assert(statusObservationToken != nil) - let session = (tunnelProvider.connection as! NETunnelProviderSession) - session.stopTunnel() - } + assert(status == .active) + assert(statusObservationToken != nil) + let session = (tunnelProvider.connection as! NETunnelProviderSession) + session.stopTunnel() } private func startObservingTunnelStatus() {