Skip to content

Commit

Permalink
Move KeyPolicy under State's namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
acb-mv committed Apr 4, 2024
1 parent 8f69b07 commit 57ba6e3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extension PacketTunnelActor {
- Parameter keyPolicy: a reference to key policy held either in connection state or blocked state struct.
- Returns: `true` when the policy was modified, otherwise `false`.
*/
private func setCurrentKeyPolicy(_ keyPolicy: inout KeyPolicy) {
private func setCurrentKeyPolicy(_ keyPolicy: inout State.KeyPolicy) {
if case .usePrior = keyPolicy {
keyPolicy = .useCurrent
}
Expand Down
2 changes: 1 addition & 1 deletion ios/PacketTunnelCore/Actor/PacketTunnelActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ extension PacketTunnelActor {
settings: Settings,
reason: ReconnectReason
) throws -> State.ConnectionData? {
var keyPolicy: KeyPolicy = .useCurrent
var keyPolicy: State.KeyPolicy = .useCurrent
var networkReachability = defaultPathObserver.defaultPath?.networkReachability ?? .undetermined
var lastKeyRotation: Date?

Expand Down
6 changes: 3 additions & 3 deletions ios/PacketTunnelCore/Actor/State+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ extension State {
}
}

extension KeyPolicy {
extension State.KeyPolicy {
func logFormat() -> String {
switch self {
case .useCurrent:
Expand All @@ -165,8 +165,8 @@ extension KeyPolicy {
}
}

extension KeyPolicy: Equatable {
static func == (lhs: KeyPolicy, rhs: KeyPolicy) -> Bool {
extension State.KeyPolicy: Equatable {
static func == (lhs: State.KeyPolicy, rhs: State.KeyPolicy) -> Bool {
switch (lhs, rhs) {
case (.useCurrent, .useCurrent): true
case let (.usePrior(priorA, _), .usePrior(priorB, _)): priorA == priorB
Expand Down
20 changes: 10 additions & 10 deletions ios/PacketTunnelCore/Actor/State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,28 @@ enum State: Equatable {
case error(BlockingData)
}

/// Policy describing what WG key to use for tunnel communication.
enum KeyPolicy {
/// Use current key stored in device data.
case useCurrent

/// Use prior key until timer fires.
case usePrior(_ priorKey: PrivateKey, _ timerTask: AutoCancellingTask)
}

/// Enum describing network availability.
public enum NetworkReachability: Equatable, Codable {
case undetermined, reachable, unreachable
}

protocol StateAssociatedData {
var currentKey: PrivateKey? { get set }
var keyPolicy: KeyPolicy { get set }
var keyPolicy: State.KeyPolicy { get set }
var networkReachability: NetworkReachability { get set }
var lastKeyRotation: Date? { get set }
}

extension State {
/// Policy describing what WG key to use for tunnel communication.
enum KeyPolicy {
/// Use current key stored in device data.
case useCurrent

/// Use prior key until timer fires.
case usePrior(_ priorKey: PrivateKey, _ timerTask: AutoCancellingTask)
}

/// Data associated with states that hold connection data.
struct ConnectionData: Equatable, StateAssociatedData {
/// Current selected relay.
Expand Down

0 comments on commit 57ba6e3

Please sign in to comment.