Strip dependencies on TunnelKitCore

- TunnelKitManager
- TunnelKitIKE
- TunnelKitOpenVPNManager
This commit is contained in:
Davide De Rosa 2021-11-23 12:20:47 +01:00
parent f1f2dddbf2
commit 8e6624e113
11 changed files with 16 additions and 23 deletions

View File

@ -57,18 +57,16 @@ let package = Package(
.target(
name: "TunnelKitManager",
dependencies: [
"TunnelKitCore"
"SwiftyBeaver"
]),
.target(
name: "TunnelKitAppExtension",
dependencies: [
"TunnelKitCore",
"SwiftyBeaver"
"TunnelKitCore"
]),
.target(
name: "TunnelKitIKE",
dependencies: [
"TunnelKitCore",
"TunnelKitManager"
]),
.target(

View File

@ -1,2 +1 @@
@_exported import TunnelKitCore
@_exported import TunnelKitManager

View File

@ -60,8 +60,6 @@ public class CoreConfiguration {
public static var versionIdentifier: String?
public static let logsSensitiveData = false
public static var reconnectionDelay = 2.0
}
extension CustomStringConvertible {

View File

@ -75,9 +75,8 @@ public struct EndpointProtocol: RawRepresentable, Equatable, CustomStringConvert
extension EndpointProtocol: Codable {
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
guard let proto = try EndpointProtocol(rawValue: container.decode(String.self)) else {
throw ConfigurationError.malformed(option: "remote/proto")
}
let rawValue = try container.decode(String.self)
let proto = EndpointProtocol(rawValue: rawValue) ?? EndpointProtocol(.udp, 1198)
self.init(proto.socketType, proto.port)
}

View File

@ -64,8 +64,8 @@ public class NativeProvider: VPNProvider {
provider.disconnect(completionHandler: completionHandler)
}
public func reconnect(configuration: VPNConfiguration, completionHandler: ((Error?) -> Void)?) {
provider.reconnect(configuration: configuration, completionHandler: completionHandler)
public func reconnect(configuration: VPNConfiguration, delay: Double? = nil, completionHandler: ((Error?) -> Void)?) {
provider.reconnect(configuration: configuration, delay: delay, completionHandler: completionHandler)
}
public func uninstall(completionHandler: (() -> Void)?) {

View File

@ -63,7 +63,7 @@ public class MockVPNProvider: VPNProvider, VPNProviderIPC {
completionHandler?(nil)
}
public func reconnect(configuration: VPNConfiguration, completionHandler: ((Error?) -> Void)?) {
public func reconnect(configuration: VPNConfiguration, delay: Double?, completionHandler: ((Error?) -> Void)?) {
isEnabled = true
status = .connected
NotificationCenter.default.post(name: VPN.didChangeStatus, object: self)

View File

@ -26,7 +26,6 @@
import Foundation
import NetworkExtension
import SwiftyBeaver
import TunnelKitCore
private let log = SwiftyBeaver.self
@ -147,10 +146,11 @@ public class NetworkExtensionVPNProvider: VPNProvider {
manager.saveToPreferences(completionHandler: completionHandler)
}
public func reconnect(configuration: VPNConfiguration, completionHandler: ((Error?) -> Void)?) {
public func reconnect(configuration: VPNConfiguration, delay: Double? = nil, completionHandler: ((Error?) -> Void)?) {
guard let configuration = configuration as? NetworkExtensionVPNConfiguration else {
fatalError("Not a NetworkExtensionVPNConfiguration")
}
let delay = delay ?? 2.0
install(configuration: configuration) { error in
guard error == nil else {
completionHandler?(error)
@ -161,7 +161,7 @@ public class NetworkExtensionVPNProvider: VPNProvider {
}
if self.status != .disconnected {
self.manager?.connection.stopVPNTunnel()
DispatchQueue.main.asyncAfter(deadline: .now() + CoreConfiguration.reconnectionDelay, execute: connectBlock)
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: connectBlock)
} else {
connectBlock()
}

View File

@ -72,9 +72,10 @@ public protocol VPNProvider: AnyObject {
Reconnects to the VPN.
- Parameter configuration: The `VPNConfiguration` to install.
- Parameter delay: The reconnection delay in seconds.
- Parameter completionHandler: The completion handler with an optional error.
*/
func reconnect(configuration: VPNConfiguration, completionHandler: ((Error?) -> Void)?)
func reconnect(configuration: VPNConfiguration, delay: Double?, completionHandler: ((Error?) -> Void)?)
/**
Uninstalls the VPN profile.

View File

@ -37,10 +37,8 @@
import Foundation
import NetworkExtension
import SwiftyBeaver
import TunnelKitCore
import TunnelKitOpenVPNCore
import TunnelKitManager
import CTunnelKitCore
import TunnelKitOpenVPNCore
import __TunnelKitUtils
private let log = SwiftyBeaver.self

View File

@ -25,8 +25,8 @@
import Foundation
import NetworkExtension
import TunnelKitOpenVPNCore
import TunnelKitManager
import TunnelKitOpenVPNCore
/// `VPNProvider` for OpenVPN protocol.
public class OpenVPNProvider: VPNProvider, VPNProviderIPC {
@ -71,8 +71,8 @@ public class OpenVPNProvider: VPNProvider, VPNProviderIPC {
provider.disconnect(completionHandler: completionHandler)
}
public func reconnect(configuration: VPNConfiguration, completionHandler: ((Error?) -> Void)?) {
provider.reconnect(configuration: configuration, completionHandler: completionHandler)
public func reconnect(configuration: VPNConfiguration, delay: Double? = nil, completionHandler: ((Error?) -> Void)?) {
provider.reconnect(configuration: configuration, delay: delay, completionHandler: completionHandler)
}
public func uninstall(completionHandler: (() -> Void)?) {