From 4cacf550a3416046ff3f6b2b2e5d41b4b3c332b4 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Mon, 29 Oct 2018 23:38:34 +0530 Subject: [PATCH] VPN: Specify an error when there are no peers with an endpoint Signed-off-by: Roopesh Chander --- WireGuard/WireGuard/VPN/TunnelsManager.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/WireGuard/WireGuard/VPN/TunnelsManager.swift b/WireGuard/WireGuard/VPN/TunnelsManager.swift index 1210d7e..6559382 100644 --- a/WireGuard/WireGuard/VPN/TunnelsManager.swift +++ b/WireGuard/WireGuard/VPN/TunnelsManager.swift @@ -13,6 +13,7 @@ protocol TunnelsManagerDelegate: class { } enum TunnelsManagerError: Error { + case noEndpoint case dnsResolutionFailed case tunnelOperationFailed case attemptingActivationWhenAnotherTunnelIsActive @@ -262,6 +263,10 @@ class TunnelContainer: NSObject { let dnsResolver = DNSResolver(endpoints: endpoints) assert(self.dnsResolver == nil) if let endpoints = dnsResolver.resolveWithoutNetworkRequests() { + guard (endpoints.contains(where: { $0 != nil })) else { + completionHandler(TunnelsManagerError.noEndpoint) + return + } self.tunnelProvider.loadFromPreferences { [weak self] (error) in guard let s = self else { return } s.startObservingTunnelStatus()