From 170d089a44af0a93c73bd529a017d496ccbe9b7e Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Fri, 8 Jan 2021 18:41:48 +0100 Subject: [PATCH] Add ConnectionProfile.serviceDelegate Requires explicit CodingKey to skip field serialization. Waiting for @transient or the like. --- .../Sources/Model/ConnectionProfile.swift | 2 ++ .../Profiles/HostConnectionProfile.swift | 24 +++++++++++++++++ .../PlaceholderConnectionProfile.swift | 2 ++ .../Profiles/ProviderConnectionProfile.swift | 26 +++++++++++++++++++ 4 files changed, 54 insertions(+) diff --git a/Passepartout/Core/Sources/Model/ConnectionProfile.swift b/Passepartout/Core/Sources/Model/ConnectionProfile.swift index 2d4edefc..6c0e1fea 100644 --- a/Passepartout/Core/Sources/Model/ConnectionProfile.swift +++ b/Passepartout/Core/Sources/Model/ConnectionProfile.swift @@ -48,6 +48,8 @@ public protocol ConnectionProfile: class, EndpointDataSource, CustomStringConver var manualNetworkSettings: ProfileNetworkSettings? { get set } + var serviceDelegate: ConnectionServiceDelegate? { get set } + func generate(from configuration: OpenVPNTunnelProvider.Configuration, preferences: Preferences) throws -> OpenVPNTunnelProvider.Configuration } diff --git a/Passepartout/Core/Sources/Model/Profiles/HostConnectionProfile.swift b/Passepartout/Core/Sources/Model/Profiles/HostConnectionProfile.swift index afd9fbf7..9a411f28 100644 --- a/Passepartout/Core/Sources/Model/Profiles/HostConnectionProfile.swift +++ b/Passepartout/Core/Sources/Model/Profiles/HostConnectionProfile.swift @@ -27,6 +27,28 @@ import Foundation import TunnelKit public class HostConnectionProfile: ConnectionProfile, Codable, Equatable { + + // XXX: drop after @transient serviceDelegate + public enum CodingKeys: CodingKey { + case hostname + + case parameters + + case customAddress + + case customProtocol + + case id + + case username + + case trustedNetworks + + case networkChoices + + case manualNetworkSettings + } + public let hostname: String public var parameters: OpenVPNTunnelProvider.Configuration @@ -64,6 +86,8 @@ public class HostConnectionProfile: ConnectionProfile, Codable, Equatable { public var manualNetworkSettings: ProfileNetworkSettings? + public weak var serviceDelegate: ConnectionServiceDelegate? + public func generate(from configuration: OpenVPNTunnelProvider.Configuration, preferences: Preferences) throws -> OpenVPNTunnelProvider.Configuration { guard let endpointProtocols = parameters.sessionConfiguration.endpointProtocols, !endpointProtocols.isEmpty else { preconditionFailure("No endpointProtocols") diff --git a/Passepartout/Core/Sources/Model/Profiles/PlaceholderConnectionProfile.swift b/Passepartout/Core/Sources/Model/Profiles/PlaceholderConnectionProfile.swift index 601f9d45..bc12ac0d 100644 --- a/Passepartout/Core/Sources/Model/Profiles/PlaceholderConnectionProfile.swift +++ b/Passepartout/Core/Sources/Model/Profiles/PlaceholderConnectionProfile.swift @@ -48,6 +48,8 @@ public class PlaceholderConnectionProfile: ConnectionProfile { public var manualNetworkSettings: ProfileNetworkSettings? + public weak var serviceDelegate: ConnectionServiceDelegate? + public func generate(from configuration: OpenVPNTunnelProvider.Configuration, preferences: Preferences) throws -> OpenVPNTunnelProvider.Configuration { fatalError("Generating configuration from a PlaceholderConnectionProfile") } diff --git a/Passepartout/Core/Sources/Model/Profiles/ProviderConnectionProfile.swift b/Passepartout/Core/Sources/Model/Profiles/ProviderConnectionProfile.swift index b6fc327b..618e6324 100644 --- a/Passepartout/Core/Sources/Model/Profiles/ProviderConnectionProfile.swift +++ b/Passepartout/Core/Sources/Model/Profiles/ProviderConnectionProfile.swift @@ -27,6 +27,30 @@ import Foundation import TunnelKit public class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable { + + // XXX: drop after @transient serviceDelegate + public enum CodingKeys: CodingKey { + case name + + case poolId + + case presetId + + case customAddress + + case customProtocol + + case favoriteGroupIds + + case username + + case trustedNetworks + + case networkChoices + + case manualNetworkSettings + } + public let name: Infrastructure.Name public var infrastructure: Infrastructure { @@ -122,6 +146,8 @@ public class ProviderConnectionProfile: ConnectionProfile, Codable, Equatable { public var manualNetworkSettings: ProfileNetworkSettings? + public weak var serviceDelegate: ConnectionServiceDelegate? + public func generate(from configuration: OpenVPNTunnelProvider.Configuration, preferences: Preferences) throws -> OpenVPNTunnelProvider.Configuration { guard let pool = pool else { preconditionFailure("Nil pool?")