Skip to content

Commit 517de3a

Browse files
committed
Merge branch 'introduce-a-state-that-means-we-are-exchanging-keys-in-ios-530'
2 parents 579945f + 8ab109d commit 517de3a

10 files changed

+185
-76
lines changed

ios/MullvadVPN/Coordinators/ApplicationCoordinator.swift

+5
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,11 @@ final class ApplicationCoordinator: Coordinator, Presenting, RootContainerViewCo
980980
case .connected, .connecting, .reconnecting, .waitingForConnectivity(.noConnection), .error:
981981
tunnelManager.reconnectTunnel(selectNewRelay: true)
982982

983+
#if DEBUG
984+
case .negotiatingKey:
985+
tunnelManager.reconnectTunnel(selectNewRelay: true)
986+
#endif
987+
983988
case .disconnecting, .disconnected:
984989
tunnelManager.startTunnel()
985990

ios/MullvadVPN/TunnelManager/MapConnectionStatusOperation.swift

+11-5
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,27 @@ class MapConnectionStatusOperation: AsyncOperation {
5050
fetchTunnelStatus(tunnel: tunnel) { observedState in
5151
switch observedState {
5252
case let .connected(connectionState):
53-
return connectionState.isNetworkReachable
53+
connectionState.isNetworkReachable
5454
? .connected(connectionState.selectedRelay)
5555
: .waitingForConnectivity(.noConnection)
5656
case let .connecting(connectionState):
57-
return connectionState.isNetworkReachable
57+
connectionState.isNetworkReachable
5858
? .connecting(connectionState.selectedRelay)
5959
: .waitingForConnectivity(.noConnection)
60+
#if DEBUG
61+
case let .negotiatingKey(connectionState):
62+
connectionState.isNetworkReachable
63+
? .negotiatingKey(connectionState.selectedRelay)
64+
: .waitingForConnectivity(.noConnection)
65+
#endif
6066
case let .reconnecting(connectionState):
61-
return connectionState.isNetworkReachable
67+
connectionState.isNetworkReachable
6268
? .reconnecting(connectionState.selectedRelay)
6369
: .waitingForConnectivity(.noConnection)
6470
case let .error(blockedState):
65-
return .error(blockedState.reason)
71+
.error(blockedState.reason)
6672
case .initial, .disconnecting, .disconnected:
67-
return .none
73+
.none
6874
}
6975
}
7076
return

ios/MullvadVPN/TunnelManager/StopTunnelOperation.swift

+26-17
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,36 @@ class StopTunnelOperation: ResultOperation<Void> {
3636
finish(result: .success(()))
3737

3838
case .connected, .connecting, .reconnecting, .waitingForConnectivity(.noConnection), .error:
39-
guard let tunnel = interactor.tunnel else {
40-
finish(result: .failure(UnsetTunnelError()))
41-
return
42-
}
39+
doShutDownTunnel()
4340

44-
// Disable on-demand when stopping the tunnel to prevent it from coming back up
45-
tunnel.isOnDemandEnabled = false
46-
47-
tunnel.saveToPreferences { error in
48-
self.dispatchQueue.async {
49-
if let error {
50-
self.finish(result: .failure(error))
51-
} else {
52-
tunnel.stop()
53-
self.finish(result: .success(()))
54-
}
55-
}
56-
}
41+
#if DEBUG
42+
case .negotiatingKey:
43+
doShutDownTunnel()
44+
#endif
5745

5846
case .disconnected, .disconnecting, .pendingReconnect, .waitingForConnectivity(.noNetwork):
5947
finish(result: .success(()))
6048
}
6149
}
50+
51+
private func doShutDownTunnel() {
52+
guard let tunnel = interactor.tunnel else {
53+
finish(result: .failure(UnsetTunnelError()))
54+
return
55+
}
56+
57+
// Disable on-demand when stopping the tunnel to prevent it from coming back up
58+
tunnel.isOnDemandEnabled = false
59+
60+
tunnel.saveToPreferences { error in
61+
self.dispatchQueue.async {
62+
if let error {
63+
self.finish(result: .failure(error))
64+
} else {
65+
tunnel.stop()
66+
self.finish(result: .success(()))
67+
}
68+
}
69+
}
70+
}
6271
}

ios/MullvadVPN/TunnelManager/TunnelManager.swift

+5
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,11 @@ final class TunnelManager: StorePaymentObserver {
675675
// while the tunnel process is trying to connect.
676676
startPollingTunnelStatus(interval: establishingTunnelStatusPollInterval)
677677

678+
#if DEBUG
679+
case .negotiatingKey:
680+
startPollingTunnelStatus(interval: establishingTunnelStatusPollInterval)
681+
#endif
682+
678683
case .connected, .waitingForConnectivity(.noConnection):
679684
// Start polling tunnel status to keep connectivity status up to date.
680685
startPollingTunnelStatus(interval: establishedTunnelStatusPollInterval)

ios/MullvadVPN/TunnelManager/TunnelState.swift

+33-16
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ enum TunnelState: Equatable, CustomStringConvertible {
5050
/// Connecting the tunnel.
5151
case connecting(SelectedRelay?)
5252

53+
#if DEBUG
54+
/// Negotiating a key for post-quantum resistance
55+
case negotiatingKey(SelectedRelay)
56+
#endif
57+
5358
/// Connected the tunnel
5459
case connected(SelectedRelay)
5560

@@ -75,46 +80,58 @@ enum TunnelState: Equatable, CustomStringConvertible {
7580
var description: String {
7681
switch self {
7782
case .pendingReconnect:
78-
return "pending reconnect after disconnect"
83+
"pending reconnect after disconnect"
7984
case let .connecting(tunnelRelay):
8085
if let tunnelRelay {
81-
return "connecting to \(tunnelRelay.hostname)"
86+
"connecting to \(tunnelRelay.hostname)"
8287
} else {
83-
return "connecting, fetching relay"
88+
"connecting, fetching relay"
8489
}
8590
case let .connected(tunnelRelay):
86-
return "connected to \(tunnelRelay.hostname)"
91+
"connected to \(tunnelRelay.hostname)"
8792
case let .disconnecting(actionAfterDisconnect):
88-
return "disconnecting and then \(actionAfterDisconnect)"
93+
"disconnecting and then \(actionAfterDisconnect)"
8994
case .disconnected:
90-
return "disconnected"
95+
"disconnected"
9196
case let .reconnecting(tunnelRelay):
92-
return "reconnecting to \(tunnelRelay.hostname)"
97+
"reconnecting to \(tunnelRelay.hostname)"
9398
case .waitingForConnectivity:
94-
return "waiting for connectivity"
99+
"waiting for connectivity"
95100
case let .error(blockedStateReason):
96-
return "error state: \(blockedStateReason)"
101+
"error state: \(blockedStateReason)"
102+
#if DEBUG
103+
case let .negotiatingKey(tunnelRelay):
104+
"negotiating key with \(tunnelRelay.hostname)"
105+
#endif
97106
}
98107
}
99108

100109
var isSecured: Bool {
101110
switch self {
102111
case .reconnecting, .connecting, .connected, .waitingForConnectivity(.noConnection), .error(.accountExpired),
103112
.error(.deviceRevoked):
104-
return true
113+
true
105114
case .pendingReconnect, .disconnecting, .disconnected, .waitingForConnectivity(.noNetwork), .error:
106-
return false
115+
false
116+
#if DEBUG
117+
case .negotiatingKey:
118+
false
119+
#endif
107120
}
108121
}
109122

110123
var relay: SelectedRelay? {
111124
switch self {
112125
case let .connected(relay), let .reconnecting(relay):
113-
return relay
126+
relay
114127
case let .connecting(relay):
115-
return relay
128+
relay
129+
#if DEBUG
130+
case let .negotiatingKey(relay):
131+
relay
132+
#endif
116133
case .disconnecting, .disconnected, .waitingForConnectivity, .pendingReconnect, .error:
117-
return nil
134+
nil
118135
}
119136
}
120137
}
@@ -130,9 +147,9 @@ enum ActionAfterDisconnect: CustomStringConvertible {
130147
var description: String {
131148
switch self {
132149
case .nothing:
133-
return "do nothing"
150+
"do nothing"
134151
case .reconnect:
135-
return "reconnect"
152+
"reconnect"
136153
}
137154
}
138155
}

0 commit comments

Comments
 (0)