Skip to content

Commit

Permalink
fix: update disconnect method in VPNManager
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajhilje committed Oct 18, 2023
1 parent 9c496cc commit 9c83415
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions IVPNClient/Managers/VPNManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,27 +232,23 @@ class VPNManager {
func installOnDemandRules(settings: ConnectionSettings, accessDetails: AccessDetails) {
switch settings {
case .ipsec:
self.disable(tunnelType: .openvpn) { _ in
disable(tunnelType: .openvpn) { _ in
self.disable(tunnelType: .wireguard) { _ in
self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in
self.disconnect(tunnelType: .ipsec)
}
}
}
case .openvpn:
self.disable(tunnelType: .ipsec) { _ in
disable(tunnelType: .ipsec) { _ in
self.disable(tunnelType: .wireguard) { _ in
self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in
self.disconnect(tunnelType: .openvpn)
}
self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in }
}
}
case .wireguard:
self.disable(tunnelType: .ipsec) { _ in
disable(tunnelType: .ipsec) { _ in
self.disable(tunnelType: .openvpn) { _ in
self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in
self.disconnect(tunnelType: .wireguard)
}
self.setup(settings: settings, accessDetails: accessDetails, status: .disconnected) { _ in }
}
}
}
Expand All @@ -272,14 +268,9 @@ class VPNManager {
}

func disconnect(tunnelType: TunnelType, reconnectAutomatically: Bool = false) {
getManagerFor(tunnelType: tunnelType) { manager in
DispatchQueue.async {
manager.connection.stopVPNTunnel()
}

if !UserDefaults.shared.networkProtectionEnabled || reconnectAutomatically {
self.removeOnDemandRule(manager: manager)
}
getManagerFor(tunnelType: tunnelType) { [self] manager in
manager.connection.stopVPNTunnel()
removeOnDemandRule(manager: manager)
}
}

Expand Down

0 comments on commit 9c83415

Please sign in to comment.