mirror of
https://github.com/passepartoutvpn/passepartout-apple.git
synced 2025-02-02 05:52:18 +00:00
Fix imports in NetworkSettingsBuilder
Also drop OpenVPN prefix, reserved for public entities.
This commit is contained in:
parent
faf9758a5c
commit
b3ebcfb6c8
@ -24,65 +24,59 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
#if !PP_FRAMEWORK
|
import PassepartoutKit
|
||||||
import PassepartoutCore
|
|
||||||
import PassepartoutOpenVPN
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extension OpenVPN {
|
/// Merges local and remote settings.
|
||||||
|
///
|
||||||
|
/// OpenVPN settings may be set locally, but may also received from a remote server. This object merges the local and remote ``OpenVPN/Configuration`` into a digestible list of `Module`.
|
||||||
|
struct NetworkSettingsBuilder {
|
||||||
|
|
||||||
/// Merges local and remote settings.
|
/// The client options.
|
||||||
///
|
let localOptions: OpenVPN.Configuration
|
||||||
/// OpenVPN settings may be set locally, but may also received from a remote server. This object merges the local and remote ``OpenVPN/Configuration`` into a digestible list of `Module`.
|
|
||||||
struct NetworkSettingsBuilder {
|
|
||||||
|
|
||||||
/// The client options.
|
/// The server options.
|
||||||
let localOptions: Configuration
|
let remoteOptions: OpenVPN.Configuration
|
||||||
|
|
||||||
/// The server options.
|
init(localOptions: OpenVPN.Configuration, remoteOptions: OpenVPN.Configuration) {
|
||||||
let remoteOptions: Configuration
|
self.localOptions = localOptions
|
||||||
|
self.remoteOptions = remoteOptions
|
||||||
|
}
|
||||||
|
|
||||||
init(localOptions: Configuration, remoteOptions: Configuration) {
|
/// A list of `Module` mapped from ``localOptions`` and ``remoteOptions``.
|
||||||
self.localOptions = localOptions
|
func modules() -> [Module] {
|
||||||
self.remoteOptions = remoteOptions
|
pp_log(.openvpn, .info, "Build modules from local/remote options")
|
||||||
|
|
||||||
|
return [
|
||||||
|
ipModule,
|
||||||
|
dnsModule,
|
||||||
|
httpProxyModule
|
||||||
|
].compactMap { $0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
func print() {
|
||||||
|
pp_log(.openvpn, .notice, "Negotiated options (remote overrides local)")
|
||||||
|
if let negCipher = remoteOptions.cipher {
|
||||||
|
pp_log(.openvpn, .notice, "\tCipher: \(negCipher.rawValue)")
|
||||||
|
}
|
||||||
|
if let negFraming = remoteOptions.compressionFraming {
|
||||||
|
pp_log(.openvpn, .notice, "\tCompression framing: \(negFraming)")
|
||||||
|
}
|
||||||
|
if let negCompression = remoteOptions.compressionAlgorithm {
|
||||||
|
pp_log(.openvpn, .notice, "\tCompression algorithm: \(negCompression)")
|
||||||
|
}
|
||||||
|
if let negPing = remoteOptions.keepAliveInterval {
|
||||||
|
pp_log(.openvpn, .notice, "\tKeep-alive interval: \(negPing.asTimeString)")
|
||||||
|
}
|
||||||
|
if let negPingRestart = remoteOptions.keepAliveTimeout {
|
||||||
|
pp_log(.openvpn, .notice, "\tKeep-alive timeout: \(negPingRestart.asTimeString)")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A list of `Module` mapped from ``localOptions`` and ``remoteOptions``.
|
|
||||||
func modules() -> [Module] {
|
|
||||||
pp_log(.openvpn, .info, "Build modules from local/remote options")
|
|
||||||
|
|
||||||
return [
|
|
||||||
ipModule,
|
|
||||||
dnsModule,
|
|
||||||
httpProxyModule
|
|
||||||
].compactMap { $0 }
|
|
||||||
}
|
|
||||||
|
|
||||||
func print() {
|
|
||||||
pp_log(.openvpn, .notice, "Negotiated options (remote overrides local)")
|
|
||||||
if let negCipher = remoteOptions.cipher {
|
|
||||||
pp_log(.openvpn, .notice, "\tCipher: \(negCipher.rawValue)")
|
|
||||||
}
|
|
||||||
if let negFraming = remoteOptions.compressionFraming {
|
|
||||||
pp_log(.openvpn, .notice, "\tCompression framing: \(negFraming)")
|
|
||||||
}
|
|
||||||
if let negCompression = remoteOptions.compressionAlgorithm {
|
|
||||||
pp_log(.openvpn, .notice, "\tCompression algorithm: \(negCompression)")
|
|
||||||
}
|
|
||||||
if let negPing = remoteOptions.keepAliveInterval {
|
|
||||||
pp_log(.openvpn, .notice, "\tKeep-alive interval: \(negPing.asTimeString)")
|
|
||||||
}
|
|
||||||
if let negPingRestart = remoteOptions.keepAliveTimeout {
|
|
||||||
pp_log(.openvpn, .notice, "\tKeep-alive timeout: \(negPingRestart.asTimeString)")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Pull
|
// MARK: - Pull
|
||||||
|
|
||||||
private extension OpenVPN.NetworkSettingsBuilder {
|
private extension NetworkSettingsBuilder {
|
||||||
var pullRoutes: Bool {
|
var pullRoutes: Bool {
|
||||||
!(localOptions.noPullMask?.contains(.routes) ?? false)
|
!(localOptions.noPullMask?.contains(.routes) ?? false)
|
||||||
}
|
}
|
||||||
@ -98,7 +92,7 @@ private extension OpenVPN.NetworkSettingsBuilder {
|
|||||||
|
|
||||||
// MARK: - Overall
|
// MARK: - Overall
|
||||||
|
|
||||||
private extension OpenVPN.NetworkSettingsBuilder {
|
private extension NetworkSettingsBuilder {
|
||||||
var isGateway: Bool {
|
var isGateway: Bool {
|
||||||
isIPv4Gateway || isIPv6Gateway
|
isIPv4Gateway || isIPv6Gateway
|
||||||
}
|
}
|
||||||
@ -166,7 +160,7 @@ private extension OpenVPN.NetworkSettingsBuilder {
|
|||||||
|
|
||||||
// MARK: - IP
|
// MARK: - IP
|
||||||
|
|
||||||
private extension OpenVPN.NetworkSettingsBuilder {
|
private extension NetworkSettingsBuilder {
|
||||||
|
|
||||||
// IPv4/6 address/mask MUST come from server options
|
// IPv4/6 address/mask MUST come from server options
|
||||||
// routes, instead, can both come from server and local options
|
// routes, instead, can both come from server and local options
|
||||||
@ -241,7 +235,7 @@ private extension OpenVPN.NetworkSettingsBuilder {
|
|||||||
|
|
||||||
// MARK: - DNS
|
// MARK: - DNS
|
||||||
|
|
||||||
private extension OpenVPN.NetworkSettingsBuilder {
|
private extension NetworkSettingsBuilder {
|
||||||
private var dnsModule: Module? {
|
private var dnsModule: Module? {
|
||||||
let dnsServers = allDNSServers
|
let dnsServers = allDNSServers
|
||||||
guard !dnsServers.isEmpty else {
|
guard !dnsServers.isEmpty else {
|
||||||
@ -278,7 +272,7 @@ private extension OpenVPN.NetworkSettingsBuilder {
|
|||||||
|
|
||||||
// MARK: - HTTP Proxy
|
// MARK: - HTTP Proxy
|
||||||
|
|
||||||
private extension OpenVPN.NetworkSettingsBuilder {
|
private extension NetworkSettingsBuilder {
|
||||||
private var httpProxyModule: Module? {
|
private var httpProxyModule: Module? {
|
||||||
var proxySettings: HTTPProxyModule.Builder?
|
var proxySettings: HTTPProxyModule.Builder?
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ extension OpenVPNConnection: OpenVPNSessionDelegate {
|
|||||||
|
|
||||||
environment.setEnvironmentValue(remoteOptions, forKey: TunnelEnvironmentKeys.OpenVPN.serverConfiguration)
|
environment.setEnvironmentValue(remoteOptions, forKey: TunnelEnvironmentKeys.OpenVPN.serverConfiguration)
|
||||||
|
|
||||||
let builder = OpenVPN.NetworkSettingsBuilder(localOptions: configuration, remoteOptions: remoteOptions)
|
let builder = NetworkSettingsBuilder(localOptions: configuration, remoteOptions: remoteOptions)
|
||||||
builder.print()
|
builder.print()
|
||||||
do {
|
do {
|
||||||
try await controller.setTunnelSettings(with: TunnelRemoteInfo(
|
try await controller.setTunnelSettings(with: TunnelRemoteInfo(
|
||||||
|
Loading…
Reference in New Issue
Block a user