aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-11-03 07:03:09 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2018-11-03 07:03:23 +0100
commitec943587fad92a50bc58b1ae90d436267f117fcc (patch)
treee5480b232b62767b12d5d74a3edaf02d39acd20e
parentTunnelsManager: do not track currentTunnel (diff)
downloadwireguard-apple-ec943587fad92a50bc58b1ae90d436267f117fcc.tar.xz
wireguard-apple-ec943587fad92a50bc58b1ae90d436267f117fcc.zip
TunnelsManager: initialize observer on correct thread
Because of the callback recursion, this function needs to always be called from the right thread Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--WireGuard/WireGuard/VPN/TunnelsManager.swift12
1 files changed, 7 insertions, 5 deletions
diff --git a/WireGuard/WireGuard/VPN/TunnelsManager.swift b/WireGuard/WireGuard/VPN/TunnelsManager.swift
index 2aa415a7..f38ca88c 100644
--- a/WireGuard/WireGuard/VPN/TunnelsManager.swift
+++ b/WireGuard/WireGuard/VPN/TunnelsManager.swift
@@ -399,13 +399,14 @@ class TunnelContainer: NSObject {
}
private func startObservingTunnelStatus() {
- if (statusObservationToken != nil) { return }
- let connection = tunnelProvider.connection
- statusObservationToken = NotificationCenter.default.addObserver(
+ DispatchQueue.main.async { [weak self] in
+ guard let s = self else { return }
+ if (s.statusObservationToken != nil) { return }
+ let connection = s.tunnelProvider.connection
+ s.statusObservationToken = NotificationCenter.default.addObserver(
forName: .NEVPNStatusDidChange,
object: connection,
- queue: nil) { [weak self] (_) in
- guard let s = self else { return }
+ queue: nil) { (_) in
if ((s.status == .restarting) && (connection.status == .disconnected || connection.status == .disconnecting)) {
// Don't change s.status when disconnecting for a restart
if (connection.status == .disconnected) {
@@ -421,6 +422,7 @@ class TunnelContainer: NSObject {
if (s.status == .inactive) {
s.stopObservingTunnelStatus()
}
+ }
}
}