aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/Shared/Model
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-11-10 19:08:21 +0530
committerRoopesh Chander <roop@roopc.net>2018-11-11 01:17:36 +0530
commit4b7094d652c657de0b802dcee91f0ccf2e07bb58 (patch)
treeb6c1b06b43aebb27f3292261c33d6e19d4b8eb59 /WireGuard/Shared/Model
parentModel: ActivityType enum to represent VPN-on-demand options (diff)
downloadwireguard-apple-4b7094d652c657de0b802dcee91f0ccf2e07bb58.tar.xz
wireguard-apple-4b7094d652c657de0b802dcee91f0ccf2e07bb58.zip
Model: Add activationType to tunnel configuration
We make sure existing tunnel serializations can be deserialized correctly. We also bump up the tunnelConfigurationVersion, because the tunnel configuration contents have changed. Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/Shared/Model')
-rw-r--r--WireGuard/Shared/Model/ActivationType.swift36
-rw-r--r--WireGuard/Shared/Model/Configuration.swift6
2 files changed, 24 insertions, 18 deletions
diff --git a/WireGuard/Shared/Model/ActivationType.swift b/WireGuard/Shared/Model/ActivationType.swift
index 56b0e6c3..ea5927d6 100644
--- a/WireGuard/Shared/Model/ActivationType.swift
+++ b/WireGuard/Shared/Model/ActivationType.swift
@@ -3,18 +3,18 @@
enum ActivationType {
case activateManually
- case useOnDemandForAnyInternetActivity
- case useOnDemandOnlyOverWifi
- case useOnDemandOnlyOverCellular
+ case useOnDemandOverWifiAndCellular
+ case useOnDemandOverWifiOnly
+ case useOnDemandOverCellularOnly
}
extension ActivationType: Codable {
// We use separate coding keys in case we might have a enum with associated values in the future
enum CodingKeys: CodingKey {
case activateManually
- case useOnDemandForAnyInternetActivity
- case useOnDemandOnlyOverWifi
- case useOnDemandOnlyOverCellular
+ case useOnDemandOverWifiAndCellular
+ case useOnDemandOverWifiOnly
+ case useOnDemandOverCellularOnly
}
// Decoding error
@@ -28,12 +28,12 @@ extension ActivationType: Codable {
switch self {
case .activateManually:
try container.encode(true, forKey: CodingKeys.activateManually)
- case .useOnDemandForAnyInternetActivity:
- try container.encode(true, forKey: CodingKeys.useOnDemandForAnyInternetActivity)
- case .useOnDemandOnlyOverWifi:
- try container.encode(true, forKey: CodingKeys.useOnDemandOnlyOverWifi)
- case .useOnDemandOnlyOverCellular:
- try container.encode(true, forKey: CodingKeys.useOnDemandOnlyOverCellular)
+ case .useOnDemandOverWifiAndCellular:
+ try container.encode(true, forKey: CodingKeys.useOnDemandOverWifiAndCellular)
+ case .useOnDemandOverWifiOnly:
+ try container.encode(true, forKey: CodingKeys.useOnDemandOverWifiOnly)
+ case .useOnDemandOverCellularOnly:
+ try container.encode(true, forKey: CodingKeys.useOnDemandOverCellularOnly)
}
}
@@ -46,18 +46,18 @@ extension ActivationType: Codable {
return
}
- if let isValid = try? container.decode(Bool.self, forKey: CodingKeys.useOnDemandForAnyInternetActivity), isValid {
- self = .useOnDemandForAnyInternetActivity
+ if let isValid = try? container.decode(Bool.self, forKey: CodingKeys.useOnDemandOverWifiAndCellular), isValid {
+ self = .useOnDemandOverWifiAndCellular
return
}
- if let isValid = try? container.decode(Bool.self, forKey: CodingKeys.useOnDemandOnlyOverWifi), isValid {
- self = .useOnDemandOnlyOverWifi
+ if let isValid = try? container.decode(Bool.self, forKey: CodingKeys.useOnDemandOverWifiOnly), isValid {
+ self = .useOnDemandOverWifiOnly
return
}
- if let isValid = try? container.decode(Bool.self, forKey: CodingKeys.useOnDemandOnlyOverCellular), isValid {
- self = .useOnDemandOnlyOverCellular
+ if let isValid = try? container.decode(Bool.self, forKey: CodingKeys.useOnDemandOverCellularOnly), isValid {
+ self = .useOnDemandOverCellularOnly
return
}
diff --git a/WireGuard/Shared/Model/Configuration.swift b/WireGuard/Shared/Model/Configuration.swift
index 45c29c11..f6598bba 100644
--- a/WireGuard/Shared/Model/Configuration.swift
+++ b/WireGuard/Shared/Model/Configuration.swift
@@ -7,9 +7,11 @@ import Foundation
final class TunnelConfiguration {
var interface: InterfaceConfiguration
let peers: [PeerConfiguration]
+ var activationType: ActivationType
init(interface: InterfaceConfiguration, peers: [PeerConfiguration]) {
self.interface = interface
self.peers = peers
+ self.activationType = .activateManually
let peerPublicKeysArray = peers.map { $0.publicKey }
let peerPublicKeysSet = Set<Data>(peerPublicKeysArray)
@@ -61,11 +63,15 @@ extension TunnelConfiguration: Decodable {
enum CodingKeys: CodingKey {
case interface
case peers
+ case activationType
}
convenience init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
let interface = try values.decode(InterfaceConfiguration.self, forKey: .interface)
let peers = try values.decode([PeerConfiguration].self, forKey: .peers)
+ let activationType = (try? values.decode(ActivationType.self, forKey: .activationType)) ?? .activateManually
+
self.init(interface: interface, peers: peers)
+ self.activationType = activationType
}
}