Complete jazzy documentation

This commit is contained in:
Davide De Rosa 2021-08-26 19:58:39 +02:00
parent 70f8c6cc2b
commit c442d44a0f
7 changed files with 106 additions and 8 deletions

View File

@ -43,16 +43,19 @@ custom_categories:
- NETCPSocket
- NETunnelInterface
- NEUDPSocket
- NSNotification
- name: Manager
children:
- VPN
- VPNProvider
- MockVPNProvider
- VPNConfiguration
- NetworkExtensionVPNConfiguration
- VPNProvider
- VPNProviderIPC
- VPNStatus
- NSNotification
- NetworkExtensionLocator
- NetworkExtensionNativeLocator
- NetworkExtensionTunnelLocator
- NetworkExtensionVPNConfiguration
- NetworkExtensionVPNProvider
- MockVPNProvider
- name: Protocols/OpenVPN
children:
- OpenVPN

View File

@ -25,7 +25,7 @@
import Foundation
/// :nodoc:
/// Simulates a VPN provider.
public class MockVPNProvider: VPNProvider, VPNProviderIPC {
// MARK: VPNProvider

View File

@ -26,6 +26,7 @@
import Foundation
import NetworkExtension
/// Entity able to look up a `NEVPNManager`.
public protocol NetworkExtensionLocator {
/**
@ -36,8 +37,10 @@ public protocol NetworkExtensionLocator {
func lookup(completionHandler: @escaping (NEVPNManager?, Error?) -> Void)
}
/// Locator for native VPN protocols.
public class NetworkExtensionNativeLocator: NetworkExtensionLocator {
/// :nodoc:
public init() {
}
@ -55,9 +58,15 @@ public class NetworkExtensionNativeLocator: NetworkExtensionLocator {
}
}
/// Locator for tunnel VPN protocols.
public class NetworkExtensionTunnelLocator: NetworkExtensionLocator {
private let bundleIdentifier: String
/**
Initializes the locator with the bundle identifier of the tunnel provider.
- Parameter bundleIdentifier: The bundle identifier of the tunnel provider.
*/
public init(bundleIdentifier: String) {
self.bundleIdentifier = bundleIdentifier
}

View File

@ -29,6 +29,7 @@ import SwiftyBeaver
private let log = SwiftyBeaver.self
/// `VPNProvider` based on the NetworkExtension framework.
public class NetworkExtensionVPNProvider: VPNProvider {
private var manager: NEVPNManager?
@ -36,6 +37,11 @@ public class NetworkExtensionVPNProvider: VPNProvider {
private var lastNotifiedStatus: VPNStatus?
/**
Initializes a provider with a `NetworkExtensionLocator`.
- Parameter locator: A `NetworkExtensionLocator` able to locate a `NEVPNManager`.
*/
public init(locator: NetworkExtensionLocator) {
self.locator = locator
@ -177,7 +183,7 @@ public class NetworkExtensionVPNProvider: VPNProvider {
// MARK: Helpers
public func lookup(completionHandler: @escaping (NEVPNManager?, Error?) -> Void) {
func lookup(completionHandler: @escaping (NEVPNManager?, Error?) -> Void) {
locator.lookup(completionHandler: completionHandler)
}

View File

@ -25,6 +25,7 @@
import Foundation
/// Common IPC functions supported by interactive VPN providers.
public protocol VPNProviderIPC {
/**

View File

@ -0,0 +1,74 @@
//
// NativeProvider.swift
// TunnelKit
//
// Created by Davide De Rosa on 4/11/21.
// Copyright (c) 2021 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
/// `VPNProvider` for native IPSec/IKEv2 configurations.
public class NativeProvider: VPNProvider {
private let provider: NetworkExtensionVPNProvider
/// :nodoc:
public init() {
provider = NetworkExtensionVPNProvider(locator: NetworkExtensionNativeLocator())
}
// MARK: VPNProvider
public var isPrepared: Bool {
return provider.isPrepared
}
public var isEnabled: Bool {
return provider.isEnabled
}
public var status: VPNStatus {
return provider.status
}
public func prepare(completionHandler: (() -> Void)?) {
provider.prepare(completionHandler: completionHandler)
}
public func install(configuration: VPNConfiguration, completionHandler: ((Error?) -> Void)?) {
provider.install(configuration: configuration, completionHandler: completionHandler)
}
public func connect(completionHandler: ((Error?) -> Void)?) {
provider.connect(completionHandler: completionHandler)
}
public func disconnect(completionHandler: ((Error?) -> Void)?) {
provider.disconnect(completionHandler: completionHandler)
}
public func reconnect(configuration: VPNConfiguration, completionHandler: ((Error?) -> Void)?) {
provider.reconnect(configuration: configuration, completionHandler: completionHandler)
}
public func uninstall(completionHandler: (() -> Void)?) {
provider.uninstall(completionHandler: completionHandler)
}
}

View File

@ -26,10 +26,15 @@
import Foundation
import NetworkExtension
/// :nodoc:
/// `VPNProvider` for OpenVPN protocol.
public class OpenVPNProvider: VPNProvider, VPNProviderIPC {
private let provider: NetworkExtensionVPNProvider
/**
Initializes a provider with the bundle identifier of the `OpenVPNTunnelProvider`.
- Parameter bundleIdentifier: The bundle identifier of the `OpenVPNTunnelProvider`.
*/
public init(bundleIdentifier: String) {
provider = NetworkExtensionVPNProvider(locator: NetworkExtensionTunnelLocator(bundleIdentifier: bundleIdentifier))
}