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

Put app in blocked state on tunnel start if relay constraints cannot be satisfied #5300

Merged
Show file tree
Hide file tree
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
32 changes: 11 additions & 21 deletions ios/MullvadVPN/TunnelManager/StartTunnelOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,20 @@ class StartTunnelOperation: ResultOperation<Void> {
finish(result: .success(()))

case .disconnected, .pendingReconnect:
do {
let selectedRelay = try interactor.selectRelay()

makeTunnelProviderAndStartTunnel(selectedRelay: selectedRelay) { error in
self.finish(result: error.map { .failure($0) } ?? .success(()))
}
} catch {
finish(result: .failure(error))
makeTunnelProviderAndStartTunnel { error in
self.finish(result: error.map { .failure($0) } ?? .success(()))
}

default:
finish(result: .success(()))
}
}

private func makeTunnelProviderAndStartTunnel(
selectedRelay: SelectedRelay,
completionHandler: @escaping (Error?) -> Void
) {
private func makeTunnelProviderAndStartTunnel(completionHandler: @escaping (Error?) -> Void) {
makeTunnelProvider { result in
self.dispatchQueue.async {
do {
try self.startTunnel(
tunnel: try result.get(),
selectedRelay: selectedRelay
)

try self.startTunnel(tunnel: result.get())
completionHandler(nil)
} catch {
completionHandler(error)
Expand All @@ -85,11 +72,14 @@ class StartTunnelOperation: ResultOperation<Void> {
}
}

private func startTunnel(tunnel: Tunnel, selectedRelay: SelectedRelay) throws {
private func startTunnel(tunnel: Tunnel) throws {
let selectedRelay = try? interactor.selectRelay()
var tunnelOptions = PacketTunnelOptions()

do {
try tunnelOptions.setSelectedRelay(selectedRelay)
if let selectedRelay {
try tunnelOptions.setSelectedRelay(selectedRelay)
}
} catch {
logger.error(
error: error,
Expand All @@ -101,8 +91,8 @@ class StartTunnelOperation: ResultOperation<Void> {

interactor.updateTunnelStatus { tunnelStatus in
tunnelStatus = TunnelStatus()
tunnelStatus.packetTunnelStatus.tunnelRelay = selectedRelay.packetTunnelRelay
tunnelStatus.state = .connecting(selectedRelay.packetTunnelRelay)
tunnelStatus.packetTunnelStatus.tunnelRelay = selectedRelay?.packetTunnelRelay
tunnelStatus.state = .connecting(selectedRelay?.packetTunnelRelay)
}

try tunnel.start(options: tunnelOptions.rawOptions())
Expand Down
10 changes: 1 addition & 9 deletions ios/MullvadVPN/TunnelManager/TunnelManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,18 +284,10 @@ final class TunnelManager: StorePaymentObserver {
throw UnsetTunnelError()
}

let nextRelay: NextRelay = selectNewRelay ? .preSelected(try self.selectRelay()) : .current

return tunnel.reconnectTunnel(to: nextRelay) { result in
return tunnel.reconnectTunnel(to: selectNewRelay ? .random : .current) { result in
finish(result.error)
}
} catch {
if let error = error as? NoRelaysSatisfyingConstraintsError {
_ = self.setTunnelStatus { tunnelStatus in
tunnelStatus.state = .error(.noRelaysSatisfyingConstraints)
}
}

finish(error)

return AnyCancellable()
Expand Down
Loading