aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/Shared
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-11-12 14:02:09 +0530
committerRoopesh Chander <roop@roopc.net>2018-11-12 19:24:13 +0530
commitcc122d7463f98ab3f26d46ab849173ffd58d7951 (patch)
treec22e870308a68a26b4bdd7c0cd30bf5430dcc4ad /WireGuard/Shared
parentTunnelsManager: Support for on-demand rules (diff)
downloadwireguard-apple-cc122d7463f98ab3f26d46ab849173ffd58d7951.tar.xz
wireguard-apple-cc122d7463f98ab3f26d46ab849173ffd58d7951.zip
Model, Tunnels manager: Rewrite the model for VPN-on-demand
The VPN-on-demand settings should not be part of the tunnel configuration. Rather, the onDemandRules stored in the tunnel provider configuration serve as the one place where the VPN-on-demand settings are stored. Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/Shared/Model/ActivationType.swift66
-rw-r--r--WireGuard/Shared/Model/Configuration.swift22
-rw-r--r--WireGuard/Shared/NETunnelProviderProtocol+Extension.swift2
3 files changed, 2 insertions, 88 deletions
diff --git a/WireGuard/Shared/Model/ActivationType.swift b/WireGuard/Shared/Model/ActivationType.swift
deleted file mode 100644
index ea5927d6..00000000
--- a/WireGuard/Shared/Model/ActivationType.swift
+++ /dev/null
@@ -1,66 +0,0 @@
-// SPDX-License-Identifier: MIT
-// Copyright © 2018 WireGuard LLC. All Rights Reserved.
-
-enum ActivationType {
- case activateManually
- 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 useOnDemandOverWifiAndCellular
- case useOnDemandOverWifiOnly
- case useOnDemandOverCellularOnly
- }
-
- // Decoding error
- enum DecodingError: Error {
- case invalidInput
- }
-
- // Encoding
- func encode(to encoder: Encoder) throws {
- var container = encoder.container(keyedBy: CodingKeys.self)
- switch self {
- case .activateManually:
- try container.encode(true, forKey: CodingKeys.activateManually)
- 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)
- }
- }
-
- // Decoding
- init(from decoder: Decoder) throws {
- let container = try decoder.container(keyedBy: CodingKeys.self)
-
- if let isValid = try? container.decode(Bool.self, forKey: CodingKeys.activateManually), isValid {
- self = .activateManually
- return
- }
-
- 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.useOnDemandOverWifiOnly), isValid {
- self = .useOnDemandOverWifiOnly
- return
- }
-
- if let isValid = try? container.decode(Bool.self, forKey: CodingKeys.useOnDemandOverCellularOnly), isValid {
- self = .useOnDemandOverCellularOnly
- return
- }
-
- throw DecodingError.invalidInput
- }
-}
diff --git a/WireGuard/Shared/Model/Configuration.swift b/WireGuard/Shared/Model/Configuration.swift
index f6598bba..41ff7bc0 100644
--- a/WireGuard/Shared/Model/Configuration.swift
+++ b/WireGuard/Shared/Model/Configuration.swift
@@ -4,14 +4,12 @@
import Foundation
@available(OSX 10.14, iOS 12.0, *)
-final class TunnelConfiguration {
+final class TunnelConfiguration: Codable {
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)
@@ -57,21 +55,3 @@ struct PeerConfiguration: Codable {
if (publicKey.count != 32) { fatalError("Invalid public key") }
}
}
-
-extension TunnelConfiguration: Encodable { }
-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
- }
-}
diff --git a/WireGuard/Shared/NETunnelProviderProtocol+Extension.swift b/WireGuard/Shared/NETunnelProviderProtocol+Extension.swift
index 591b0eb3..ec8b294a 100644
--- a/WireGuard/Shared/NETunnelProviderProtocol+Extension.swift
+++ b/WireGuard/Shared/NETunnelProviderProtocol+Extension.swift
@@ -14,7 +14,7 @@ extension NETunnelProviderProtocol {
providerBundleIdentifier = "\(appId).network-extension"
providerConfiguration = [
"tunnelConfiguration": serializedTunnelConfiguration,
- "tunnelConfigurationVersion": 2
+ "tunnelConfigurationVersion": 1
]
let endpoints = tunnelConfiguration.peers.compactMap({$0.endpoint})