Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Swiftlint warnings in MapConnectionStatusOperation #5108

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 57 additions & 45 deletions ios/MullvadVPN/TunnelManager/MapConnectionStatusOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,7 @@ class MapConnectionStatusOperation: AsyncOperation {

switch connectionStatus {
case .connecting:
switch tunnelState {
case .connecting:
break

default:
interactor.updateTunnelStatus { tunnelStatus in
tunnelStatus.state = .connecting(nil)
}
}

fetchTunnelStatus(tunnel: tunnel) { packetTunnelStatus in
if packetTunnelStatus.isNetworkReachable {
return packetTunnelStatus.tunnelRelay.map { .connecting($0) }
} else {
return .waitingForConnectivity(.noConnection)
}
}
handleConnectingState(tunnelState, tunnel)
return

case .reasserting:
Expand All @@ -87,36 +71,10 @@ class MapConnectionStatusOperation: AsyncOperation {
return

case .disconnected:
switch tunnelState {
case .pendingReconnect:
logger.debug("Ignore disconnected state when pending reconnect.")

case .disconnecting(.reconnect):
logger.debug("Restart the tunnel on disconnect.")
interactor.updateTunnelStatus { tunnelStatus in
tunnelStatus = TunnelStatus()
tunnelStatus.state = .pendingReconnect
}
interactor.startTunnel()

default:
setTunnelDisconnectedStatus()
}
handleDisconnectedState(tunnelState)

case .disconnecting:
switch tunnelState {
case .disconnecting:
break
default:
interactor.updateTunnelStatus { tunnelStatus in
let packetTunnelStatus = tunnelStatus.packetTunnelStatus

tunnelStatus = TunnelStatus()
tunnelStatus.state = packetTunnelStatus.isNetworkReachable
? .disconnecting(.nothing)
: .waitingForConnectivity(.noNetwork)
}
}
handleDisconnectionState(tunnelState)

case .invalid:
setTunnelDisconnectedStatus()
Expand All @@ -132,6 +90,60 @@ class MapConnectionStatusOperation: AsyncOperation {
request?.cancel()
}

private func handleConnectingState(_ tunnelState: TunnelState, _ tunnel: Tunnel) {
switch tunnelState {
case .connecting:
break

default:
interactor.updateTunnelStatus { tunnelStatus in
tunnelStatus.state = .connecting(nil)
}
}

fetchTunnelStatus(tunnel: tunnel) { packetTunnelStatus in
if packetTunnelStatus.isNetworkReachable {
return packetTunnelStatus.tunnelRelay.map { .connecting($0) }
} else {
return .waitingForConnectivity(.noConnection)
}
}
}

private func handleDisconnectionState(_ tunnelState: TunnelState) {
switch tunnelState {
case .disconnecting:
break
default:
interactor.updateTunnelStatus { tunnelStatus in
let packetTunnelStatus = tunnelStatus.packetTunnelStatus

tunnelStatus = TunnelStatus()
tunnelStatus.state = packetTunnelStatus.isNetworkReachable
? .disconnecting(.nothing)
: .waitingForConnectivity(.noNetwork)
}
}
}

private func handleDisconnectedState(_ tunnelState: TunnelState) {
switch tunnelState {
case .pendingReconnect:
logger.debug("Ignore disconnected state when pending reconnect.")

case .disconnecting(.reconnect):
logger.debug("Restart the tunnel on disconnect.")
interactor.updateTunnelStatus { tunnelStatus in
tunnelStatus = TunnelStatus()
tunnelStatus.state = .pendingReconnect
}
interactor.startTunnel()

default:
setTunnelDisconnectedStatus()
}
}

private func setTunnelDisconnectedStatus() {
interactor.updateTunnelStatus { tunnelStatus in
tunnelStatus = TunnelStatus()
Expand Down
Loading