From 470da3ffcc057db9823e2c5a97ad3f619c26f9a7 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sat, 22 Dec 2018 06:56:12 +0100 Subject: [PATCH] Reassign tunnelProvider if it changes from outside the app --- WireGuard/WireGuard/Tunnel/TunnelsManager.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift index 8b5311d..a2360a8 100644 --- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift +++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift @@ -281,7 +281,9 @@ class TunnelsManager { guard let self = self, let session = statusChangeNotification.object as? NETunnelProviderSession, let tunnelProvider = session.manager as? NETunnelProviderManager, - let tunnel = self.tunnels.first(where: { $0.tunnelProvider == tunnelProvider }) else { return } + let tunnelConfiguration = TunnelContainer(tunnel: tunnelProvider).tunnelConfiguration, + let tunnel = self.tunnels.first(where: { $0.tunnelConfiguration == tunnelConfiguration }) else { return } + tunnel.tunnelProvider = tunnelProvider wg_log(.debug, message: "Tunnel '\(tunnel.name)' connection status changed to '\(tunnel.tunnelProvider.connection.status)'") @@ -364,7 +366,7 @@ class TunnelContainer: NSObject { var activationAttemptId: String? var activationTimer: Timer? - fileprivate let tunnelProvider: NETunnelProviderManager + fileprivate var tunnelProvider: NETunnelProviderManager private var lastTunnelConnectionStatus: NEVPNStatus? var tunnelConfiguration: TunnelConfiguration? {