TunnelsTracker: Simplify using TunnelsManager.tunnelInOperation()

This commit is contained in:
Roopesh Chander 2019-01-24 18:11:55 +05:30
parent a099d6fa26
commit 4df2b7e642
1 changed files with 2 additions and 17 deletions

View File

@ -33,18 +33,7 @@ class TunnelsTracker {
init(tunnelsManager: TunnelsManager) { init(tunnelsManager: TunnelsManager) {
self.tunnelsManager = tunnelsManager self.tunnelsManager = tunnelsManager
currentTunnel = tunnelsManager.tunnelInOperation()
if let waitingTunnel = tunnelsManager.waitingTunnel() {
currentTunnel = waitingTunnel
} else {
for index in 0 ..< tunnelsManager.numberOfTunnels() {
let tunnel = tunnelsManager.tunnel(at: index)
if tunnel.status != .inactive {
currentTunnel = tunnel
break
}
}
}
for index in 0 ..< tunnelsManager.numberOfTunnels() { for index in 0 ..< tunnelsManager.numberOfTunnels() {
let tunnel = tunnelsManager.tunnel(at: index) let tunnel = tunnelsManager.tunnel(at: index)
@ -61,11 +50,7 @@ class TunnelsTracker {
guard let self = self else { return } guard let self = self else { return }
if tunnel.status == .deactivating || tunnel.status == .inactive { if tunnel.status == .deactivating || tunnel.status == .inactive {
if self.currentTunnel == tunnel { if self.currentTunnel == tunnel {
if let waitingTunnel = self.tunnelsManager.waitingTunnel() { self.currentTunnel = self.tunnelsManager.tunnelInOperation()
self.currentTunnel = waitingTunnel
} else if tunnel.status == .inactive {
self.currentTunnel = nil
}
} }
} else { } else {
self.currentTunnel = tunnel self.currentTunnel = tunnel