aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-02-24 19:30:14 +0530
committerRoopesh Chander <roop@roopc.net>2019-02-24 19:30:14 +0530
commit5ed28907ecab4f7c001ab604be664eb46033bdc5 (patch)
tree3b78037b3e0ff66f064c90ba10ab89875785bd1c /WireGuard
parentImporting: Show OS error when unable to open a .conf file (diff)
downloadwireguard-apple-5ed28907ecab4f7c001ab604be664eb46033bdc5.tar.xz
wireguard-apple-5ed28907ecab4f7c001ab604be664eb46033bdc5.zip
iOS: Hack to restart active tunnel after adding a new tunnel
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/Tunnel/TunnelsManager.swift17
1 files changed, 16 insertions, 1 deletions
diff --git a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
index ece1e72..e05bea9 100644
--- a/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
+++ b/WireGuard/WireGuard/Tunnel/TunnelsManager.swift
@@ -115,6 +115,8 @@ class TunnelsManager {
activateOnDemandSetting.apply(on: tunnelProviderManager)
+ let activeTunnel = tunnels.first { $0.status == .active || $0.status == .activating }
+
tunnelProviderManager.saveToPreferences { [weak self] error in
guard error == nil else {
wg_log(.error, message: "Add: Saving configuration failed: \(error!)")
@@ -125,6 +127,19 @@ class TunnelsManager {
guard let self = self else { return }
+ #if os(iOS)
+ // HACK: In iOS, adding a tunnel causes deactivation of any currently active tunnel.
+ // This is an ugly hack to reactivate the tunnel that has been deactivated like that.
+ if let activeTunnel = activeTunnel {
+ if activeTunnel.status == .inactive || activeTunnel.status == .deactivating {
+ self.startActivation(of: activeTunnel)
+ }
+ if activeTunnel.status == .active || activeTunnel.status == .activating {
+ activeTunnel.status = .restarting
+ }
+ }
+ #endif
+
let tunnel = TunnelContainer(tunnel: tunnelProviderManager)
self.tunnels.append(tunnel)
self.tunnels.sort { $0.name < $1.name }
@@ -440,7 +455,7 @@ class TunnelContainer: NSObject {
}
func refreshStatus() {
- if (status == .restarting) && (tunnelProvider.connection.status == .disconnected || tunnelProvider.connection.status == .disconnecting) {
+ if status == .restarting {
return
}
status = TunnelStatus(from: tunnelProvider.connection.status)