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 d08ee36
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,11 +89,13 @@ 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
self.tunnels.remove(at: index)
removedTunnels.append(currentTunnel)
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 d08ee36

Please sign in to comment.