Skip to content

Commit 4d486c2

Browse files
acb-mvbuggmagnet
authored andcommitted
Rename State component types for clarity
1 parent 6a7406f commit 4d486c2

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

ios/PacketTunnelCore/Actor/PacketTunnelActor+ErrorState.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ extension PacketTunnelActor {
8484
return nil
8585
}
8686

87-
case .disconnecting, .disconnected:
87+
// Post quantum key exchange cannot enter the blocked state
88+
case .disconnecting, .disconnected, .negotiatingPostQuantumKey:
8889
return nil
8990
}
9091
}

ios/PacketTunnelCore/Actor/PacketTunnelActor.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ extension PacketTunnelActor {
164164
/// Stop the tunnel.
165165
private func stop() async {
166166
switch state {
167-
case let .connected(connState), let .connecting(connState), let .reconnecting(connState):
167+
case let .connected(connState), let .connecting(connState), let .reconnecting(connState),
168+
let .negotiatingPostQuantumKey(connState):
168169
state = .disconnecting(connState)
169170
tunnelMonitor.stop()
170171

@@ -199,6 +200,10 @@ extension PacketTunnelActor {
199200
private func reconnect(to nextRelay: NextRelay, reason: ReconnectReason) async {
200201
do {
201202
switch state {
203+
case .negotiatingPostQuantumKey:
204+
// There is no connection monitoring going on when exchanging keys.
205+
// The procedure starts from scratch for each reconnection attempts.
206+
try await tryStart(nextRelay: nextRelay, reason: reason)
202207
case .connecting, .connected, .reconnecting, .error:
203208
switch reason {
204209
case .connectionLoss:
@@ -326,7 +331,7 @@ extension PacketTunnelActor {
326331
connectionState.incrementAttemptCount()
327332
}
328333
fallthrough
329-
case var .connected(connectionState):
334+
case var .connected(connectionState), var .negotiatingPostQuantumKey(connectionState):
330335
let selectedRelay = try callRelaySelector(
331336
connectionState.selectedRelay,
332337
connectionState.connectionAttemptCount

ios/PacketTunnelCore/Actor/State+Extensions.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension State {
2323
case .initial:
2424
return .connecting
2525

26-
case .connecting:
26+
case .connecting, .negotiatingPostQuantumKey:
2727
return .connecting
2828

2929
case .connected, .reconnecting:
@@ -59,13 +59,15 @@ extension State {
5959
case let .error(blockedState):
6060
return "\(name): \(blockedState.reason)"
6161

62-
case .initial, .disconnecting, .disconnected:
62+
case .initial, .disconnecting, .disconnected, .negotiatingPostQuantumKey:
6363
return name
6464
}
6565
}
6666

6767
var name: String {
6868
switch self {
69+
case .negotiatingPostQuantumKey:
70+
"Negotiating Post Quantum Key"
6971
case .connected:
7072
"Connected"
7173
case .connecting:

ios/PacketTunnelCore/Actor/State.swift

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ enum State: Equatable {
5858
/// Initial state at the time when actor is initialized but before the first connection attempt.
5959
case initial
6060

61+
/// Establish a connection to the gateway, and exchange a post quantum key with the GRPC service that resides there.
62+
case negotiatingPostQuantumKey(ConnectionData)
63+
6164
/// Tunnel is attempting to connect.
6265
/// The actor should remain in this state until the very first connection is established, i.e determined by tunnel monitor.
6366
case connecting(ConnectionData)

0 commit comments

Comments
 (0)