Merge pull request #10 from keeshux/bridge-compression-framing
Bridge CompressionFraming to Swift
This commit is contained in:
commit
a4375ba08a
|
@ -30,7 +30,7 @@
|
||||||
0E1108B31F77B9F900A92462 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0E1108B21F77B9F900A92462 /* Assets.xcassets */; };
|
0E1108B31F77B9F900A92462 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0E1108B21F77B9F900A92462 /* Assets.xcassets */; };
|
||||||
0E1108B61F77B9F900A92462 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0E1108B41F77B9F900A92462 /* LaunchScreen.storyboard */; };
|
0E1108B61F77B9F900A92462 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0E1108B41F77B9F900A92462 /* LaunchScreen.storyboard */; };
|
||||||
0E245D692135972800B012A2 /* PushTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E245D682135972800B012A2 /* PushTests.swift */; };
|
0E245D692135972800B012A2 /* PushTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E245D682135972800B012A2 /* PushTests.swift */; };
|
||||||
0E245D6C2137F73600B012A2 /* CompressionFraming.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E245D6B2137F73600B012A2 /* CompressionFraming.h */; };
|
0E245D6C2137F73600B012A2 /* CompressionFramingNative.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E245D6B2137F73600B012A2 /* CompressionFramingNative.h */; };
|
||||||
0E3E0F212108A8CC00B371C1 /* SessionProxy+PushReply.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E3E0F202108A8CC00B371C1 /* SessionProxy+PushReply.swift */; };
|
0E3E0F212108A8CC00B371C1 /* SessionProxy+PushReply.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E3E0F202108A8CC00B371C1 /* SessionProxy+PushReply.swift */; };
|
||||||
0E3E0F222108A8CC00B371C1 /* SessionProxy+PushReply.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E3E0F202108A8CC00B371C1 /* SessionProxy+PushReply.swift */; };
|
0E3E0F222108A8CC00B371C1 /* SessionProxy+PushReply.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E3E0F202108A8CC00B371C1 /* SessionProxy+PushReply.swift */; };
|
||||||
0E58F1302138AC2F00A49F27 /* DNSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E58F12F2138AC2F00A49F27 /* DNSTests.swift */; };
|
0E58F1302138AC2F00A49F27 /* DNSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E58F12F2138AC2F00A49F27 /* DNSTests.swift */; };
|
||||||
|
@ -190,7 +190,7 @@
|
||||||
0E1108B71F77B9F900A92462 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
0E1108B71F77B9F900A92462 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
0E17D7F91F730D9F009EE129 /* TunnelKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TunnelKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
0E17D7F91F730D9F009EE129 /* TunnelKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TunnelKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
0E245D682135972800B012A2 /* PushTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PushTests.swift; sourceTree = "<group>"; };
|
0E245D682135972800B012A2 /* PushTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PushTests.swift; sourceTree = "<group>"; };
|
||||||
0E245D6B2137F73600B012A2 /* CompressionFraming.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompressionFraming.h; sourceTree = "<group>"; };
|
0E245D6B2137F73600B012A2 /* CompressionFramingNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompressionFramingNative.h; sourceTree = "<group>"; };
|
||||||
0E3251C51F95770D00C108D9 /* TunnelKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TunnelKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
0E3251C51F95770D00C108D9 /* TunnelKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TunnelKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
0E3E0F202108A8CC00B371C1 /* SessionProxy+PushReply.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SessionProxy+PushReply.swift"; sourceTree = "<group>"; };
|
0E3E0F202108A8CC00B371C1 /* SessionProxy+PushReply.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SessionProxy+PushReply.swift"; sourceTree = "<group>"; };
|
||||||
0E58F12F2138AC2F00A49F27 /* DNSTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DNSTests.swift; sourceTree = "<group>"; };
|
0E58F12F2138AC2F00A49F27 /* DNSTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DNSTests.swift; sourceTree = "<group>"; };
|
||||||
|
@ -414,8 +414,8 @@
|
||||||
children = (
|
children = (
|
||||||
0EFEB42E2006D3C800F81029 /* Allocation.h */,
|
0EFEB42E2006D3C800F81029 /* Allocation.h */,
|
||||||
0EFEB4462006D3C800F81029 /* Allocation.m */,
|
0EFEB4462006D3C800F81029 /* Allocation.m */,
|
||||||
0E245D6B2137F73600B012A2 /* CompressionFraming.h */,
|
|
||||||
0ED9C8632138139000621BA3 /* CompressionFraming.swift */,
|
0ED9C8632138139000621BA3 /* CompressionFraming.swift */,
|
||||||
|
0E245D6B2137F73600B012A2 /* CompressionFramingNative.h */,
|
||||||
0EFEB44A2006D3C800F81029 /* CoreConfiguration.swift */,
|
0EFEB44A2006D3C800F81029 /* CoreConfiguration.swift */,
|
||||||
0E07597C20F0060E00F38FD8 /* CryptoAEAD.h */,
|
0E07597C20F0060E00F38FD8 /* CryptoAEAD.h */,
|
||||||
0E07597D20F0060E00F38FD8 /* CryptoAEAD.m */,
|
0E07597D20F0060E00F38FD8 /* CryptoAEAD.m */,
|
||||||
|
@ -518,7 +518,7 @@
|
||||||
0EFEB46B2006D3C800F81029 /* CryptoBox.h in Headers */,
|
0EFEB46B2006D3C800F81029 /* CryptoBox.h in Headers */,
|
||||||
0EFEB4592006D3C800F81029 /* Allocation.h in Headers */,
|
0EFEB4592006D3C800F81029 /* Allocation.h in Headers */,
|
||||||
0EFEB4582006D3C800F81029 /* MSS.h in Headers */,
|
0EFEB4582006D3C800F81029 /* MSS.h in Headers */,
|
||||||
0E245D6C2137F73600B012A2 /* CompressionFraming.h in Headers */,
|
0E245D6C2137F73600B012A2 /* CompressionFramingNative.h in Headers */,
|
||||||
0EFEB4602006D3C800F81029 /* DataPath.h in Headers */,
|
0EFEB4602006D3C800F81029 /* DataPath.h in Headers */,
|
||||||
0E07597E20F0060E00F38FD8 /* CryptoAEAD.h in Headers */,
|
0E07597E20F0060E00F38FD8 /* CryptoAEAD.h in Headers */,
|
||||||
0EFEB46C2006D3C800F81029 /* ZeroingData.h in Headers */,
|
0EFEB46C2006D3C800F81029 /* ZeroingData.h in Headers */,
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import NetworkExtension
|
import NetworkExtension
|
||||||
import SwiftyBeaver
|
import SwiftyBeaver
|
||||||
import __TunnelKitNative
|
|
||||||
|
|
||||||
private let log = SwiftyBeaver.self
|
private let log = SwiftyBeaver.self
|
||||||
|
|
||||||
|
@ -165,7 +164,7 @@ extension TunnelKitProvider {
|
||||||
public var mtu: Int
|
public var mtu: Int
|
||||||
|
|
||||||
/// Sets compression framing, disabled by default.
|
/// Sets compression framing, disabled by default.
|
||||||
public var compressionFraming: CompressionFraming
|
public var compressionFraming: SessionProxy.CompressionFraming
|
||||||
|
|
||||||
/// The number of seconds after which a renegotiation is started. Set to `nil` to disable renegotiation (default).
|
/// The number of seconds after which a renegotiation is started. Set to `nil` to disable renegotiation (default).
|
||||||
public var renegotiatesAfterSeconds: Int?
|
public var renegotiatesAfterSeconds: Int?
|
||||||
|
@ -265,7 +264,7 @@ extension TunnelKitProvider {
|
||||||
self.clientCertificate = clientCertificate
|
self.clientCertificate = clientCertificate
|
||||||
self.clientKey = clientKey
|
self.clientKey = clientKey
|
||||||
mtu = providerConfiguration[S.mtu] as? Int ?? 1250
|
mtu = providerConfiguration[S.mtu] as? Int ?? 1250
|
||||||
if let compressionFramingValue = providerConfiguration[S.compressionFraming] as? Int, let compressionFraming = CompressionFraming(rawValue: compressionFramingValue) {
|
if let compressionFramingValue = providerConfiguration[S.compressionFraming] as? Int, let compressionFraming = SessionProxy.CompressionFraming(rawValue: compressionFramingValue) {
|
||||||
self.compressionFraming = compressionFraming
|
self.compressionFraming = compressionFraming
|
||||||
} else {
|
} else {
|
||||||
compressionFraming = .disabled
|
compressionFraming = .disabled
|
||||||
|
@ -379,7 +378,7 @@ extension TunnelKitProvider {
|
||||||
public let mtu: Int
|
public let mtu: Int
|
||||||
|
|
||||||
/// - Seealso: `TunnelKitProvider.ConfigurationBuilder.compressionFraming`
|
/// - Seealso: `TunnelKitProvider.ConfigurationBuilder.compressionFraming`
|
||||||
public let compressionFraming: CompressionFraming
|
public let compressionFraming: SessionProxy.CompressionFraming
|
||||||
|
|
||||||
/// - Seealso: `TunnelKitProvider.ConfigurationBuilder.renegotiatesAfterSeconds`
|
/// - Seealso: `TunnelKitProvider.ConfigurationBuilder.renegotiatesAfterSeconds`
|
||||||
public let renegotiatesAfterSeconds: Int?
|
public let renegotiatesAfterSeconds: Int?
|
||||||
|
|
|
@ -26,19 +26,42 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import __TunnelKitNative
|
import __TunnelKitNative
|
||||||
|
|
||||||
extension CompressionFraming: CustomStringConvertible {
|
extension SessionProxy {
|
||||||
|
|
||||||
/// :nodoc:
|
/// Defines the type of compression framing.
|
||||||
public var description: String {
|
public enum CompressionFraming: Int, CustomStringConvertible {
|
||||||
switch self {
|
|
||||||
case .disabled:
|
/// No compression framing.
|
||||||
return "disabled"
|
case disabled
|
||||||
|
|
||||||
case .compress:
|
/// Framing compatible with 2.4 `compress`.
|
||||||
return "compress"
|
case compress
|
||||||
|
|
||||||
case .compLZO:
|
/// Framing compatible with `comp-lzo` (deprecated).
|
||||||
return "comp-lzo"
|
@available(*, deprecated)
|
||||||
|
case compLZO
|
||||||
|
|
||||||
|
var native: CompressionFramingNative {
|
||||||
|
guard let val = CompressionFramingNative(rawValue: rawValue) else {
|
||||||
|
fatalError("Unhandled CompressionFraming bridging")
|
||||||
|
}
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: CustomStringConvertible
|
||||||
|
|
||||||
|
/// :nodoc:
|
||||||
|
public var description: String {
|
||||||
|
switch self {
|
||||||
|
case .disabled:
|
||||||
|
return "disabled"
|
||||||
|
|
||||||
|
case .compress:
|
||||||
|
return "compress"
|
||||||
|
|
||||||
|
case .compLZO:
|
||||||
|
return "comp-lzo"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//
|
//
|
||||||
// CompressionFraming.h
|
// CompressionFramingNative.h
|
||||||
// TunnelKit
|
// TunnelKit
|
||||||
//
|
//
|
||||||
// Created by Davide De Rosa on 8/30/18.
|
// Created by Davide De Rosa on 8/30/18.
|
||||||
|
@ -25,8 +25,8 @@
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
typedef NS_ENUM(NSInteger, CompressionFraming) {
|
typedef NS_ENUM(NSInteger, CompressionFramingNative) {
|
||||||
CompressionFramingDisabled,
|
CompressionFramingNativeDisabled,
|
||||||
CompressionFramingCompress,
|
CompressionFramingNativeCompress,
|
||||||
CompressionFramingCompLZO __attribute__((deprecated))
|
CompressionFramingNativeCompLZO __attribute__((deprecated))
|
||||||
};
|
};
|
|
@ -51,7 +51,7 @@
|
||||||
usesReplayProtection:(BOOL)usesReplayProtection;
|
usesReplayProtection:(BOOL)usesReplayProtection;
|
||||||
|
|
||||||
- (void)setPeerId:(uint32_t)peerId; // 24-bit, discard most significant byte
|
- (void)setPeerId:(uint32_t)peerId; // 24-bit, discard most significant byte
|
||||||
- (void)setCompressionFraming:(CompressionFraming)compressionFraming;
|
- (void)setCompressionFraming:(CompressionFramingNative)compressionFraming;
|
||||||
|
|
||||||
- (NSArray<NSData *> *)encryptPackets:(nonnull NSArray<NSData *> *)packets key:(uint8_t)key error:(NSError **)error;
|
- (NSArray<NSData *> *)encryptPackets:(nonnull NSArray<NSData *> *)packets key:(uint8_t)key error:(NSError **)error;
|
||||||
- (NSArray<NSData *> *)decryptPackets:(nonnull NSArray<NSData *> *)packets keepAlive:(nullable bool *)keepAlive error:(NSError **)error;
|
- (NSArray<NSData *> *)decryptPackets:(nonnull NSArray<NSData *> *)packets keepAlive:(nullable bool *)keepAlive error:(NSError **)error;
|
||||||
|
|
|
@ -109,7 +109,7 @@
|
||||||
self.inReplay = [[ReplayProtector alloc] init];
|
self.inReplay = [[ReplayProtector alloc] init];
|
||||||
}
|
}
|
||||||
|
|
||||||
self.compressionFraming = CompressionFramingDisabled;
|
self.compressionFraming = CompressionFramingNativeDisabled;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -165,10 +165,10 @@
|
||||||
[self.decrypter setPeerId:peerId];
|
[self.decrypter setPeerId:peerId];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setCompressionFraming:(CompressionFraming)compressionFraming
|
- (void)setCompressionFraming:(CompressionFramingNative)compressionFraming
|
||||||
{
|
{
|
||||||
switch (compressionFraming) {
|
switch (compressionFraming) {
|
||||||
case CompressionFramingDisabled: {
|
case CompressionFramingNativeDisabled: {
|
||||||
self.assemblePayloadBlock = ^(uint8_t * _Nonnull packetDest, NSInteger * _Nonnull packetLengthOffset, NSData * _Nonnull payload) {
|
self.assemblePayloadBlock = ^(uint8_t * _Nonnull packetDest, NSInteger * _Nonnull packetLengthOffset, NSData * _Nonnull payload) {
|
||||||
memcpy(packetDest, payload.bytes, payload.length);
|
memcpy(packetDest, payload.bytes, payload.length);
|
||||||
*packetLengthOffset = 0;
|
*packetLengthOffset = 0;
|
||||||
|
@ -179,7 +179,7 @@
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CompressionFramingCompress: {
|
case CompressionFramingNativeCompress: {
|
||||||
self.assemblePayloadBlock = ^(uint8_t * _Nonnull packetDest, NSInteger * _Nonnull packetLengthOffset, NSData * _Nonnull payload) {
|
self.assemblePayloadBlock = ^(uint8_t * _Nonnull packetDest, NSInteger * _Nonnull packetLengthOffset, NSData * _Nonnull payload) {
|
||||||
memcpy(packetDest, payload.bytes, payload.length);
|
memcpy(packetDest, payload.bytes, payload.length);
|
||||||
packetDest[payload.length] = packetDest[0];
|
packetDest[payload.length] = packetDest[0];
|
||||||
|
@ -194,7 +194,7 @@
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CompressionFramingCompLZO: {
|
case CompressionFramingNativeCompLZO: {
|
||||||
self.assemblePayloadBlock = ^(uint8_t * _Nonnull packetDest, NSInteger * _Nonnull packetLengthOffset, NSData * _Nonnull payload) {
|
self.assemblePayloadBlock = ^(uint8_t * _Nonnull packetDest, NSInteger * _Nonnull packetLengthOffset, NSData * _Nonnull payload) {
|
||||||
memcpy(packetDest + 1, payload.bytes, payload.length);
|
memcpy(packetDest + 1, payload.bytes, payload.length);
|
||||||
packetDest[0] = DataPacketNoCompress;
|
packetDest[0] = DataPacketNoCompress;
|
||||||
|
|
|
@ -36,7 +36,6 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import __TunnelKitNative
|
|
||||||
|
|
||||||
extension SessionProxy {
|
extension SessionProxy {
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ extension SessionProxy {
|
||||||
|
|
||||||
func startHandlingPackets(withPeerId peerId: UInt32? = nil, compressionFraming: CompressionFraming = .disabled) {
|
func startHandlingPackets(withPeerId peerId: UInt32? = nil, compressionFraming: CompressionFraming = .disabled) {
|
||||||
dataPath?.setPeerId(peerId ?? PacketPeerIdDisabled)
|
dataPath?.setPeerId(peerId ?? PacketPeerIdDisabled)
|
||||||
dataPath?.setCompressionFraming(compressionFraming)
|
dataPath?.setCompressionFraming(compressionFraming.native)
|
||||||
canHandlePackets = true
|
canHandlePackets = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ module __TunnelKitNative {
|
||||||
header "MSS.h"
|
header "MSS.h"
|
||||||
header "PacketMacros.h"
|
header "PacketMacros.h"
|
||||||
header "ReplayProtector.h"
|
header "ReplayProtector.h"
|
||||||
header "CompressionFraming.h"
|
header "CompressionFramingNative.h"
|
||||||
header "DataPath.h"
|
header "DataPath.h"
|
||||||
header "DataPathEncryption.h"
|
header "DataPathEncryption.h"
|
||||||
export *
|
export *
|
||||||
|
|
Loading…
Reference in New Issue