Skip to content

Commit

Permalink
fix: issue of modification on active tunnel
Browse files Browse the repository at this point in the history
Signed-off-by: George Kutsurua <[email protected]>
  • Loading branch information
suquant committed Dec 7, 2021
1 parent 23618f9 commit 256f43b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Sources/WireGuardApp/Tunnel/TunnelsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ class TunnelsManager {
guard let self = self else { return }

let loadedTunnelProviders = managers ?? []
var removedTunnels: [TunnelContainer] = []

for (index, currentTunnel) in self.tunnels.enumerated().reversed() {
if !loadedTunnelProviders.contains(where: { $0.isEquivalentTo(currentTunnel) }) {
// Tunnel was deleted outside the app
removedTunnels.append(currentTunnel)
self.tunnels.remove(at: index)
self.tunnelsListDelegate?.tunnelRemoved(at: index, tunnel: currentTunnel)
}
Expand All @@ -109,6 +111,10 @@ class TunnelsManager {
}
}
let tunnel = TunnelContainer(tunnel: loadedTunnelProvider)
// Removed tunnel contains programmatically changed status, so we copying it to new one
if let removedTunnel = removedTunnels.first(where: { $0.name == tunnel.name }), [TunnelStatus.restarting, TunnelStatus.reasserting, TunnelStatus.waiting].contains(removedTunnel.status) {
tunnel.status = removedTunnel.status
}
self.tunnels.append(tunnel)
self.tunnels.sort { TunnelsManager.tunnelNameIsLessThan($0.name, $1.name) }
self.tunnelsListDelegate?.tunnelAdded(at: self.tunnels.firstIndex(of: tunnel)!)
Expand Down

0 comments on commit 256f43b

Please sign in to comment.