2020-06-12 21:08:25 +00:00
|
|
|
//
|
|
|
|
// VPNProvider.swift
|
|
|
|
// TunnelKit
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 9/6/18.
|
|
|
|
// Copyright (c) 2020 Davide De Rosa. All rights reserved.
|
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// This file is part of TunnelKit.
|
|
|
|
//
|
|
|
|
// TunnelKit is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// TunnelKit is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with TunnelKit. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2020-06-13 13:30:48 +00:00
|
|
|
/// Helps controlling a VPN without messing with underlying implementations.
|
2020-06-12 21:08:25 +00:00
|
|
|
public protocol VPNProvider: class {
|
2020-06-13 13:30:48 +00:00
|
|
|
|
|
|
|
/// `true` if the VPN is ready for use.
|
2020-06-12 21:08:25 +00:00
|
|
|
var isPrepared: Bool { get }
|
|
|
|
|
2020-06-13 13:30:48 +00:00
|
|
|
/// `true` if the associated VPN profile is enabled.
|
2020-06-12 21:08:25 +00:00
|
|
|
var isEnabled: Bool { get }
|
|
|
|
|
2020-06-13 13:30:48 +00:00
|
|
|
/// The status of the VPN.
|
2020-06-12 21:08:25 +00:00
|
|
|
var status: VPNStatus { get }
|
2020-06-13 13:30:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Prepares the VPN for use.
|
|
|
|
|
|
|
|
- Postcondition: The VPN is ready to use and `isPrepared` becomes `true`.
|
|
|
|
- Parameter completionHandler: The completion handler.
|
|
|
|
- Seealso: `isPrepared`
|
|
|
|
*/
|
2020-06-12 21:08:25 +00:00
|
|
|
func prepare(completionHandler: (() -> Void)?)
|
|
|
|
|
2020-06-13 13:30:48 +00:00
|
|
|
/**
|
|
|
|
Installs the VPN profile.
|
|
|
|
|
|
|
|
- Parameter configuration: The `VPNConfiguration` to install.
|
|
|
|
- Parameter completionHandler: The completion handler with an optional error.
|
|
|
|
*/
|
2020-06-12 21:08:25 +00:00
|
|
|
func install(configuration: VPNConfiguration, completionHandler: ((Error?) -> Void)?)
|
|
|
|
|
2020-06-13 13:30:48 +00:00
|
|
|
/**
|
|
|
|
Connects to the VPN.
|
|
|
|
|
|
|
|
- Parameter completionHandler: The completion handler with an optional error.
|
|
|
|
*/
|
2020-06-12 21:08:25 +00:00
|
|
|
func connect(completionHandler: ((Error?) -> Void)?)
|
|
|
|
|
2020-06-13 13:30:48 +00:00
|
|
|
/**
|
|
|
|
Disconnects from the VPN.
|
|
|
|
|
|
|
|
- Parameter completionHandler: The completion handler with an optional error.
|
|
|
|
*/
|
2020-06-12 21:08:25 +00:00
|
|
|
func disconnect(completionHandler: ((Error?) -> Void)?)
|
|
|
|
|
2020-06-13 13:30:48 +00:00
|
|
|
/**
|
|
|
|
Reconnects to the VPN.
|
|
|
|
|
|
|
|
- Parameter configuration: The `VPNConfiguration` to install.
|
|
|
|
- Parameter completionHandler: The completion handler with an optional error.
|
|
|
|
*/
|
2020-06-12 21:08:25 +00:00
|
|
|
func reconnect(configuration: VPNConfiguration, completionHandler: ((Error?) -> Void)?)
|
|
|
|
|
2020-06-13 13:30:48 +00:00
|
|
|
/**
|
|
|
|
Uninstalls the VPN profile.
|
|
|
|
|
|
|
|
- Parameter completionHandler: The completion handler.
|
|
|
|
*/
|
2020-06-12 21:08:25 +00:00
|
|
|
func uninstall(completionHandler: (() -> Void)?)
|
|
|
|
|
2020-06-13 13:30:48 +00:00
|
|
|
/**
|
|
|
|
Request a debug log from the VPN.
|
|
|
|
|
|
|
|
- Parameter fallback: The block resolving to a fallback `String` if no debug log is available.
|
|
|
|
- Parameter completionHandler: The completion handler with the debug log.
|
|
|
|
*/
|
2020-06-12 21:08:25 +00:00
|
|
|
func requestDebugLog(fallback: (() -> String)?, completionHandler: @escaping (String) -> Void)
|
|
|
|
|
2020-06-13 13:30:48 +00:00
|
|
|
/**
|
|
|
|
Requests the current received/sent bytes count from the VPN.
|
2020-06-12 21:08:25 +00:00
|
|
|
|
2020-06-13 13:30:48 +00:00
|
|
|
- Parameter completionHandler: The completion handler with an optional received/sent bytes count.
|
|
|
|
*/
|
|
|
|
func requestBytesCount(completionHandler: @escaping ((UInt, UInt)?) -> Void)
|
2020-06-12 21:08:25 +00:00
|
|
|
|
2020-06-13 13:30:48 +00:00
|
|
|
/**
|
|
|
|
Requests the server configuration from the VPN.
|
2020-06-12 21:08:25 +00:00
|
|
|
|
2020-06-13 13:30:48 +00:00
|
|
|
- Parameter completionHandler: The completion handler with an optional configuration object.
|
|
|
|
*/
|
|
|
|
func requestServerConfiguration(completionHandler: @escaping (Any?) -> Void)
|
2020-06-12 21:08:25 +00:00
|
|
|
}
|