Strip dependencies on TunnelKitCore
- TunnelKitManager - TunnelKitIKE - TunnelKitOpenVPNManager
This commit is contained in:
parent
f1f2dddbf2
commit
8e6624e113
|
@ -57,18 +57,16 @@ let package = Package(
|
||||||
.target(
|
.target(
|
||||||
name: "TunnelKitManager",
|
name: "TunnelKitManager",
|
||||||
dependencies: [
|
dependencies: [
|
||||||
"TunnelKitCore"
|
"SwiftyBeaver"
|
||||||
]),
|
]),
|
||||||
.target(
|
.target(
|
||||||
name: "TunnelKitAppExtension",
|
name: "TunnelKitAppExtension",
|
||||||
dependencies: [
|
dependencies: [
|
||||||
"TunnelKitCore",
|
"TunnelKitCore"
|
||||||
"SwiftyBeaver"
|
|
||||||
]),
|
]),
|
||||||
.target(
|
.target(
|
||||||
name: "TunnelKitIKE",
|
name: "TunnelKitIKE",
|
||||||
dependencies: [
|
dependencies: [
|
||||||
"TunnelKitCore",
|
|
||||||
"TunnelKitManager"
|
"TunnelKitManager"
|
||||||
]),
|
]),
|
||||||
.target(
|
.target(
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
@_exported import TunnelKitCore
|
|
||||||
@_exported import TunnelKitManager
|
@_exported import TunnelKitManager
|
||||||
|
|
|
@ -60,8 +60,6 @@ public class CoreConfiguration {
|
||||||
public static var versionIdentifier: String?
|
public static var versionIdentifier: String?
|
||||||
|
|
||||||
public static let logsSensitiveData = false
|
public static let logsSensitiveData = false
|
||||||
|
|
||||||
public static var reconnectionDelay = 2.0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension CustomStringConvertible {
|
extension CustomStringConvertible {
|
||||||
|
|
|
@ -75,9 +75,8 @@ public struct EndpointProtocol: RawRepresentable, Equatable, CustomStringConvert
|
||||||
extension EndpointProtocol: Codable {
|
extension EndpointProtocol: Codable {
|
||||||
public init(from decoder: Decoder) throws {
|
public init(from decoder: Decoder) throws {
|
||||||
let container = try decoder.singleValueContainer()
|
let container = try decoder.singleValueContainer()
|
||||||
guard let proto = try EndpointProtocol(rawValue: container.decode(String.self)) else {
|
let rawValue = try container.decode(String.self)
|
||||||
throw ConfigurationError.malformed(option: "remote/proto")
|
let proto = EndpointProtocol(rawValue: rawValue) ?? EndpointProtocol(.udp, 1198)
|
||||||
}
|
|
||||||
self.init(proto.socketType, proto.port)
|
self.init(proto.socketType, proto.port)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,8 @@ public class NativeProvider: VPNProvider {
|
||||||
provider.disconnect(completionHandler: completionHandler)
|
provider.disconnect(completionHandler: completionHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func reconnect(configuration: VPNConfiguration, completionHandler: ((Error?) -> Void)?) {
|
public func reconnect(configuration: VPNConfiguration, delay: Double? = nil, completionHandler: ((Error?) -> Void)?) {
|
||||||
provider.reconnect(configuration: configuration, completionHandler: completionHandler)
|
provider.reconnect(configuration: configuration, delay: delay, completionHandler: completionHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func uninstall(completionHandler: (() -> Void)?) {
|
public func uninstall(completionHandler: (() -> Void)?) {
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class MockVPNProvider: VPNProvider, VPNProviderIPC {
|
||||||
completionHandler?(nil)
|
completionHandler?(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func reconnect(configuration: VPNConfiguration, completionHandler: ((Error?) -> Void)?) {
|
public func reconnect(configuration: VPNConfiguration, delay: Double?, completionHandler: ((Error?) -> Void)?) {
|
||||||
isEnabled = true
|
isEnabled = true
|
||||||
status = .connected
|
status = .connected
|
||||||
NotificationCenter.default.post(name: VPN.didChangeStatus, object: self)
|
NotificationCenter.default.post(name: VPN.didChangeStatus, object: self)
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import NetworkExtension
|
import NetworkExtension
|
||||||
import SwiftyBeaver
|
import SwiftyBeaver
|
||||||
import TunnelKitCore
|
|
||||||
|
|
||||||
private let log = SwiftyBeaver.self
|
private let log = SwiftyBeaver.self
|
||||||
|
|
||||||
|
@ -147,10 +146,11 @@ public class NetworkExtensionVPNProvider: VPNProvider {
|
||||||
manager.saveToPreferences(completionHandler: completionHandler)
|
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 {
|
guard let configuration = configuration as? NetworkExtensionVPNConfiguration else {
|
||||||
fatalError("Not a NetworkExtensionVPNConfiguration")
|
fatalError("Not a NetworkExtensionVPNConfiguration")
|
||||||
}
|
}
|
||||||
|
let delay = delay ?? 2.0
|
||||||
install(configuration: configuration) { error in
|
install(configuration: configuration) { error in
|
||||||
guard error == nil else {
|
guard error == nil else {
|
||||||
completionHandler?(error)
|
completionHandler?(error)
|
||||||
|
@ -161,7 +161,7 @@ public class NetworkExtensionVPNProvider: VPNProvider {
|
||||||
}
|
}
|
||||||
if self.status != .disconnected {
|
if self.status != .disconnected {
|
||||||
self.manager?.connection.stopVPNTunnel()
|
self.manager?.connection.stopVPNTunnel()
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + CoreConfiguration.reconnectionDelay, execute: connectBlock)
|
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: connectBlock)
|
||||||
} else {
|
} else {
|
||||||
connectBlock()
|
connectBlock()
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,9 +72,10 @@ public protocol VPNProvider: AnyObject {
|
||||||
Reconnects to the VPN.
|
Reconnects to the VPN.
|
||||||
|
|
||||||
- Parameter configuration: The `VPNConfiguration` to install.
|
- Parameter configuration: The `VPNConfiguration` to install.
|
||||||
|
- Parameter delay: The reconnection delay in seconds.
|
||||||
- Parameter completionHandler: The completion handler with an optional error.
|
- 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.
|
Uninstalls the VPN profile.
|
||||||
|
|
|
@ -37,10 +37,8 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import NetworkExtension
|
import NetworkExtension
|
||||||
import SwiftyBeaver
|
import SwiftyBeaver
|
||||||
import TunnelKitCore
|
|
||||||
import TunnelKitOpenVPNCore
|
|
||||||
import TunnelKitManager
|
import TunnelKitManager
|
||||||
import CTunnelKitCore
|
import TunnelKitOpenVPNCore
|
||||||
import __TunnelKitUtils
|
import __TunnelKitUtils
|
||||||
|
|
||||||
private let log = SwiftyBeaver.self
|
private let log = SwiftyBeaver.self
|
||||||
|
|
|
@ -25,8 +25,8 @@
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import NetworkExtension
|
import NetworkExtension
|
||||||
import TunnelKitOpenVPNCore
|
|
||||||
import TunnelKitManager
|
import TunnelKitManager
|
||||||
|
import TunnelKitOpenVPNCore
|
||||||
|
|
||||||
/// `VPNProvider` for OpenVPN protocol.
|
/// `VPNProvider` for OpenVPN protocol.
|
||||||
public class OpenVPNProvider: VPNProvider, VPNProviderIPC {
|
public class OpenVPNProvider: VPNProvider, VPNProviderIPC {
|
||||||
|
@ -71,8 +71,8 @@ public class OpenVPNProvider: VPNProvider, VPNProviderIPC {
|
||||||
provider.disconnect(completionHandler: completionHandler)
|
provider.disconnect(completionHandler: completionHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func reconnect(configuration: VPNConfiguration, completionHandler: ((Error?) -> Void)?) {
|
public func reconnect(configuration: VPNConfiguration, delay: Double? = nil, completionHandler: ((Error?) -> Void)?) {
|
||||||
provider.reconnect(configuration: configuration, completionHandler: completionHandler)
|
provider.reconnect(configuration: configuration, delay: delay, completionHandler: completionHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func uninstall(completionHandler: (() -> Void)?) {
|
public func uninstall(completionHandler: (() -> Void)?) {
|
||||||
|
|
Loading…
Reference in New Issue