From 8860abc89eb0cde8918e7cbc9b1883ae577555a5 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 5 Nov 2018 06:23:26 +0100 Subject: TunnelsManager: account for no or many endpoints Signed-off-by: Jason A. Donenfeld --- .../WireGuard/VPN/PacketTunnelOptionsGenerator.swift | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'WireGuard/WireGuard/VPN/PacketTunnelOptionsGenerator.swift') diff --git a/WireGuard/WireGuard/VPN/PacketTunnelOptionsGenerator.swift b/WireGuard/WireGuard/VPN/PacketTunnelOptionsGenerator.swift index 35d4bb7..3eabde7 100644 --- a/WireGuard/WireGuard/VPN/PacketTunnelOptionsGenerator.swift +++ b/WireGuard/WireGuard/VPN/PacketTunnelOptionsGenerator.swift @@ -48,19 +48,23 @@ class PacketTunnelOptionsGenerator { // Remote address - let remoteAddress: String - if let firstEndpoint = resolvedEndpoints.compactMap({ $0 }).first { - switch (firstEndpoint.host) { + /* iOS requires a tunnel endpoint, whereas in WireGuard it's valid for + * a tunnel to have no endpoint, or for there to be many endpoints, in + * which case, displaying a single one in settings doesn't really + * make sense. So, we fill it in with this placeholder, which is not + * a valid IP address that will actually route over the Internet. + */ + var remoteAddress: String = "0.0.0.0" + let endpointsCompact = resolvedEndpoints.compactMap({ $0 }) + if endpointsCompact.count == 1 { + switch (endpointsCompact.first!.host) { case .ipv4(let address): remoteAddress = "\(address)" case .ipv6(let address): remoteAddress = "\(address)" default: - fatalError("Endpoint must be resolved") + break } - } else { - // We don't have any peer with an endpoint - remoteAddress = "" } options[.remoteAddress] = remoteAddress as NSObject -- cgit v1.2.3-59-g8ed1b