Move EndpointProtocol/SocketType to Core
This commit is contained in:
parent
0800c943a8
commit
f91db4cbf1
|
@ -7,6 +7,10 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
0E011F7A2196D93600BA59EE /* SocketType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E011F792196D93600BA59EE /* SocketType.swift */; };
|
||||
0E011F7B2196D93600BA59EE /* SocketType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E011F792196D93600BA59EE /* SocketType.swift */; };
|
||||
0E011F7D2196D97200BA59EE /* EndpointProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E011F7C2196D97200BA59EE /* EndpointProtocol.swift */; };
|
||||
0E011F7E2196D97200BA59EE /* EndpointProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E011F7C2196D97200BA59EE /* EndpointProtocol.swift */; };
|
||||
0E041D092152E6FE0025FE3C /* SessionProxy+TLSWrap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E041D082152E6FE0025FE3C /* SessionProxy+TLSWrap.swift */; };
|
||||
0E041D0A2152E6FE0025FE3C /* SessionProxy+TLSWrap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E041D082152E6FE0025FE3C /* SessionProxy+TLSWrap.swift */; };
|
||||
0E041D0C2152E80A0025FE3C /* StaticKeyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E041D0B2152E80A0025FE3C /* StaticKeyTests.swift */; };
|
||||
|
@ -223,6 +227,8 @@
|
|||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
0E011F792196D93600BA59EE /* SocketType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketType.swift; sourceTree = "<group>"; };
|
||||
0E011F7C2196D97200BA59EE /* EndpointProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EndpointProtocol.swift; sourceTree = "<group>"; };
|
||||
0E041D082152E6FE0025FE3C /* SessionProxy+TLSWrap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SessionProxy+TLSWrap.swift"; sourceTree = "<group>"; };
|
||||
0E041D0B2152E80A0025FE3C /* StaticKeyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StaticKeyTests.swift; sourceTree = "<group>"; };
|
||||
0E07595C20EF6D1400F38FD8 /* CryptoCBC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CryptoCBC.m; sourceTree = "<group>"; };
|
||||
|
@ -540,6 +546,7 @@
|
|||
0EFEB4352006D3C800F81029 /* DataPath.h */,
|
||||
0EFEB44C2006D3C800F81029 /* DataPath.m */,
|
||||
0EE7A79D20F6488400B42E6A /* DataPathCrypto.h */,
|
||||
0E011F7C2196D97200BA59EE /* EndpointProtocol.swift */,
|
||||
0EFEB4362006D3C800F81029 /* Errors.h */,
|
||||
0EFEB44B2006D3C800F81029 /* Errors.m */,
|
||||
0EFEB4452006D3C800F81029 /* IOInterface.swift */,
|
||||
|
@ -565,6 +572,7 @@
|
|||
0E3E0F202108A8CC00B371C1 /* SessionProxy+PushReply.swift */,
|
||||
0EFEB42B2006D3C800F81029 /* SessionProxy+SessionKey.swift */,
|
||||
0E041D082152E6FE0025FE3C /* SessionProxy+TLSWrap.swift */,
|
||||
0E011F792196D93600BA59EE /* SocketType.swift */,
|
||||
0EE3B3E321471C3A0027AB17 /* StaticKey.swift */,
|
||||
0EFEB4442006D3C800F81029 /* TLSBox.h */,
|
||||
0EFEB4302006D3C800F81029 /* TLSBox.m */,
|
||||
|
@ -1071,6 +1079,7 @@
|
|||
0EFEB4622006D3C800F81029 /* SecureRandom.swift in Sources */,
|
||||
0EFEB45D2006D3C800F81029 /* CryptoBox.m in Sources */,
|
||||
0E3B15C92152B05E00984B17 /* CryptoCTR.m in Sources */,
|
||||
0E011F7D2196D97200BA59EE /* EndpointProtocol.swift in Sources */,
|
||||
0EBBF2FA2085061600E36B40 /* NETCPInterface.swift in Sources */,
|
||||
0E0C2125212ED29D008AB282 /* SessionError.swift in Sources */,
|
||||
0E12B2A821456C0200B4BAE9 /* ControlChannel.swift in Sources */,
|
||||
|
@ -1106,6 +1115,7 @@
|
|||
0EFEB4762006D3C800F81029 /* DataPath.m in Sources */,
|
||||
0E0C2127212ED29D008AB282 /* SessionProxy+Configuration.swift in Sources */,
|
||||
0EFEB4692006D3C800F81029 /* Packet.swift in Sources */,
|
||||
0E011F7A2196D93600BA59EE /* SocketType.swift in Sources */,
|
||||
0EFEB45A2006D3C800F81029 /* TunnelInterface.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
@ -1131,6 +1141,7 @@
|
|||
0EBBF3012085196000E36B40 /* NWTCPConnectionState+Description.swift in Sources */,
|
||||
0EFEB4962006D7F300F81029 /* ProtocolMacros.swift in Sources */,
|
||||
0E3B15CA2152B05E00984B17 /* CryptoCTR.m in Sources */,
|
||||
0E011F7E2196D97200BA59EE /* EndpointProtocol.swift in Sources */,
|
||||
0EFEB48A2006D7C400F81029 /* TunnelKitProvider.swift in Sources */,
|
||||
0E0C2126212ED29D008AB282 /* SessionError.swift in Sources */,
|
||||
0E12B2A921456C0200B4BAE9 /* ControlChannel.swift in Sources */,
|
||||
|
@ -1166,6 +1177,7 @@
|
|||
0EFEB49D2006D7F300F81029 /* IOInterface.swift in Sources */,
|
||||
0E0C2128212ED29D008AB282 /* SessionProxy+Configuration.swift in Sources */,
|
||||
0EFEB4972006D7F300F81029 /* SessionProxy+Authenticator.swift in Sources */,
|
||||
0E011F7B2196D93600BA59EE /* SocketType.swift in Sources */,
|
||||
0EFEB49B2006D7F300F81029 /* Packet.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
|
@ -48,7 +48,7 @@ class ConnectionStrategy {
|
|||
|
||||
private var resolvedAddresses: [String]?
|
||||
|
||||
private let endpointProtocols: [TunnelKitProvider.EndpointProtocol]
|
||||
private let endpointProtocols: [EndpointProtocol]
|
||||
|
||||
private var currentProtocolIndex = 0
|
||||
|
||||
|
@ -119,7 +119,7 @@ class ConnectionStrategy {
|
|||
return true
|
||||
}
|
||||
|
||||
private func currentProtocol() -> TunnelKitProvider.EndpointProtocol {
|
||||
private func currentProtocol() -> EndpointProtocol {
|
||||
return endpointProtocols[currentProtocolIndex]
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ class ConnectionStrategy {
|
|||
}
|
||||
|
||||
private extension NEProvider {
|
||||
func createSocket(to address: String, protocol endpointProtocol: TunnelKitProvider.EndpointProtocol) -> GenericSocket {
|
||||
func createSocket(to address: String, protocol endpointProtocol: EndpointProtocol) -> GenericSocket {
|
||||
let endpoint = NWHostEndpoint(hostname: address, port: "\(endpointProtocol.port)")
|
||||
switch endpointProtocol.socketType {
|
||||
case .udp:
|
||||
|
|
|
@ -45,68 +45,6 @@ extension TunnelKitProvider {
|
|||
|
||||
// MARK: Configuration
|
||||
|
||||
/// A socket type between UDP (recommended) and TCP.
|
||||
public enum SocketType: String {
|
||||
|
||||
/// UDP socket type.
|
||||
case udp = "UDP"
|
||||
|
||||
/// TCP socket type.
|
||||
case tcp = "TCP"
|
||||
}
|
||||
|
||||
/// Defines the communication protocol of an endpoint.
|
||||
public struct EndpointProtocol: RawRepresentable, Equatable, CustomStringConvertible {
|
||||
|
||||
/// The socket type.
|
||||
public let socketType: SocketType
|
||||
|
||||
/// The remote port.
|
||||
public let port: UInt16
|
||||
|
||||
/// :nodoc:
|
||||
public init(_ socketType: SocketType, _ port: UInt16) {
|
||||
self.socketType = socketType
|
||||
self.port = port
|
||||
}
|
||||
|
||||
// MARK: RawRepresentable
|
||||
|
||||
/// :nodoc:
|
||||
public init?(rawValue: String) {
|
||||
let components = rawValue.components(separatedBy: ":")
|
||||
guard components.count == 2 else {
|
||||
return nil
|
||||
}
|
||||
guard let socketType = SocketType(rawValue: components[0]) else {
|
||||
return nil
|
||||
}
|
||||
guard let port = UInt16(components[1]) else {
|
||||
return nil
|
||||
}
|
||||
self.init(socketType, port)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public var rawValue: String {
|
||||
return "\(socketType.rawValue):\(port)"
|
||||
}
|
||||
|
||||
// MARK: Equatable
|
||||
|
||||
/// :nodoc:
|
||||
public static func ==(lhs: EndpointProtocol, rhs: EndpointProtocol) -> Bool {
|
||||
return (lhs.socketType == rhs.socketType) && (lhs.port == rhs.port)
|
||||
}
|
||||
|
||||
// MARK: CustomStringConvertible
|
||||
|
||||
/// :nodoc:
|
||||
public var description: String {
|
||||
return rawValue
|
||||
}
|
||||
}
|
||||
|
||||
/// The way to create a `TunnelKitProvider.Configuration` object for the tunnel profile.
|
||||
public struct ConfigurationBuilder {
|
||||
|
||||
|
@ -578,10 +516,10 @@ extension TunnelKitProvider.Configuration: Equatable {
|
|||
}
|
||||
|
||||
/// :nodoc:
|
||||
extension TunnelKitProvider.EndpointProtocol: Codable {
|
||||
extension EndpointProtocol: Codable {
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.singleValueContainer()
|
||||
guard let proto = try TunnelKitProvider.EndpointProtocol(rawValue: container.decode(String.self)) else {
|
||||
guard let proto = try EndpointProtocol(rawValue: container.decode(String.self)) else {
|
||||
throw TunnelKitProvider.ProviderConfigurationError.parameter(name: "endpointProtocol.decodable")
|
||||
}
|
||||
self.init(proto.socketType, proto.port)
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
//
|
||||
// EndpointProtocol.swift
|
||||
// TunnelKit
|
||||
//
|
||||
// Created by Davide De Rosa on 11/10/18.
|
||||
// Copyright (c) 2018 Davide De Rosa. All rights reserved.
|
||||
//
|
||||
// https://github.com/keeshux
|
||||
//
|
||||
// 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
|
||||
|
||||
/// Defines the communication protocol of an endpoint.
|
||||
public struct EndpointProtocol: RawRepresentable, Equatable, CustomStringConvertible {
|
||||
|
||||
/// The socket type.
|
||||
public let socketType: SocketType
|
||||
|
||||
/// The remote port.
|
||||
public let port: UInt16
|
||||
|
||||
/// :nodoc:
|
||||
public init(_ socketType: SocketType, _ port: UInt16) {
|
||||
self.socketType = socketType
|
||||
self.port = port
|
||||
}
|
||||
|
||||
// MARK: RawRepresentable
|
||||
|
||||
/// :nodoc:
|
||||
public init?(rawValue: String) {
|
||||
let components = rawValue.components(separatedBy: ":")
|
||||
guard components.count == 2 else {
|
||||
return nil
|
||||
}
|
||||
guard let socketType = SocketType(rawValue: components[0]) else {
|
||||
return nil
|
||||
}
|
||||
guard let port = UInt16(components[1]) else {
|
||||
return nil
|
||||
}
|
||||
self.init(socketType, port)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public var rawValue: String {
|
||||
return "\(socketType.rawValue):\(port)"
|
||||
}
|
||||
|
||||
// MARK: Equatable
|
||||
|
||||
/// :nodoc:
|
||||
public static func ==(lhs: EndpointProtocol, rhs: EndpointProtocol) -> Bool {
|
||||
return (lhs.socketType == rhs.socketType) && (lhs.port == rhs.port)
|
||||
}
|
||||
|
||||
// MARK: CustomStringConvertible
|
||||
|
||||
/// :nodoc:
|
||||
public var description: String {
|
||||
return rawValue
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
// SockeType.swift
|
||||
// TunnelKit
|
||||
//
|
||||
// Created by Davide De Rosa on 11/10/18.
|
||||
// Copyright (c) 2018 Davide De Rosa. All rights reserved.
|
||||
//
|
||||
// https://github.com/keeshux
|
||||
//
|
||||
// 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
|
||||
|
||||
/// A socket type between UDP (recommended) and TCP.
|
||||
public enum SocketType: String {
|
||||
|
||||
/// UDP socket type.
|
||||
case udp = "UDP"
|
||||
|
||||
/// TCP socket type.
|
||||
case tcp = "TCP"
|
||||
}
|
Loading…
Reference in New Issue