2022-04-12 13:09:14 +00:00
|
|
|
//
|
|
|
|
// Network.swift
|
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 2/15/22.
|
|
|
|
// Copyright (c) 2022 Davide De Rosa. All rights reserved.
|
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// This file is part of Passepartout.
|
|
|
|
//
|
|
|
|
// Passepartout 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.
|
|
|
|
//
|
|
|
|
// Passepartout 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 Passepartout. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import TunnelKitCore
|
|
|
|
import NetworkExtension
|
|
|
|
|
|
|
|
public enum Network {
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Network {
|
|
|
|
public enum Choice: String, Codable {
|
|
|
|
case automatic // OpenVPN pulls from server
|
|
|
|
|
|
|
|
case manual
|
|
|
|
|
|
|
|
public static let defaultChoice: Choice = .automatic
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public protocol NetworkChoiceRepresentable {
|
|
|
|
var choice: Network.Choice { get set }
|
|
|
|
}
|
|
|
|
|
|
|
|
public protocol GatewaySettingsProviding {
|
|
|
|
var isDefaultIPv4: Bool { get }
|
|
|
|
|
|
|
|
var isDefaultIPv6: Bool { get }
|
|
|
|
}
|
|
|
|
|
|
|
|
public protocol DNSSettingsProviding {
|
|
|
|
var dnsProtocol: DNSProtocol { get }
|
|
|
|
|
|
|
|
var dnsServers: [String] { get }
|
|
|
|
|
|
|
|
var dnsHTTPSURL: URL? { get }
|
|
|
|
|
|
|
|
var dnsTLSServerName: String? { get }
|
|
|
|
|
|
|
|
var dnsSearchDomains: [String] { get }
|
|
|
|
}
|
|
|
|
|
|
|
|
public protocol ProxySettingsProviding {
|
|
|
|
var proxyServer: Proxy? { get }
|
|
|
|
|
|
|
|
var proxyAutoConfigurationURL: URL? { get }
|
|
|
|
|
|
|
|
var proxyBypassDomains: [String] { get }
|
|
|
|
}
|
|
|
|
|
|
|
|
public protocol MTUSettingsProviding {
|
|
|
|
var mtuBytes: Int { get }
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
extension Network {
|
|
|
|
public struct GatewaySettings: Codable, Equatable, NetworkChoiceRepresentable, GatewaySettingsProviding {
|
|
|
|
public var choice: Network.Choice
|
|
|
|
|
|
|
|
public var isDefaultIPv4 = true
|
|
|
|
|
|
|
|
public var isDefaultIPv6 = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Network {
|
|
|
|
public struct DNSSettings: Codable, Equatable, NetworkChoiceRepresentable, DNSSettingsProviding {
|
|
|
|
public var choice: Network.Choice
|
|
|
|
|
|
|
|
public var isDNSEnabled = true
|
|
|
|
|
|
|
|
public var dnsProtocol: DNSProtocol = .plain
|
|
|
|
|
|
|
|
public var dnsServers: [String] = []
|
|
|
|
|
|
|
|
public var dnsSearchDomains: [String] = []
|
|
|
|
|
|
|
|
public var dnsHTTPSURL: URL?
|
|
|
|
|
|
|
|
public var dnsTLSServerName: String?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Network {
|
|
|
|
public struct ProxySettings: Codable, Equatable, NetworkChoiceRepresentable, ProxySettingsProviding {
|
2022-04-13 17:34:43 +00:00
|
|
|
public enum ConfigurationType: String, Codable {
|
|
|
|
case manual
|
|
|
|
|
|
|
|
case pac
|
|
|
|
|
|
|
|
case disabled
|
|
|
|
}
|
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
public var choice: Network.Choice
|
|
|
|
|
2022-04-13 17:34:43 +00:00
|
|
|
public var configurationType: ConfigurationType = .manual
|
2022-04-12 13:09:14 +00:00
|
|
|
|
|
|
|
public var proxyAddress: String?
|
|
|
|
|
|
|
|
public var proxyPort: UInt16?
|
|
|
|
|
|
|
|
public var proxyBypassDomains: [String] = []
|
|
|
|
|
2022-04-13 17:45:27 +00:00
|
|
|
public var proxyAutoConfigurationURL: URL?
|
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
public var proxyServer: Proxy? {
|
|
|
|
guard let address = proxyAddress, let port = proxyPort, !address.isEmpty, port > 0 else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return Proxy(address, port)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Network {
|
|
|
|
public struct MTUSettings: Codable, Equatable, NetworkChoiceRepresentable, MTUSettingsProviding {
|
|
|
|
public var choice: Network.Choice
|
|
|
|
|
|
|
|
public var mtuBytes = 0
|
|
|
|
}
|
|
|
|
}
|