Merge pull request #10 from keeshux/bridge-compression-framing

Bridge CompressionFraming to Swift
This commit is contained in:
Davide De Rosa 2018-08-31 01:46:41 +02:00 committed by GitHub
commit a4375ba08a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 56 additions and 35 deletions

View File

@ -30,7 +30,7 @@
0E1108B31F77B9F900A92462 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0E1108B21F77B9F900A92462 /* Assets.xcassets */; };
0E1108B61F77B9F900A92462 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0E1108B41F77B9F900A92462 /* LaunchScreen.storyboard */; };
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 */; };
0E3E0F222108A8CC00B371C1 /* SessionProxy+PushReply.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E3E0F202108A8CC00B371C1 /* SessionProxy+PushReply.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>"; };
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>"; };
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; };
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>"; };
@ -414,8 +414,8 @@
children = (
0EFEB42E2006D3C800F81029 /* Allocation.h */,
0EFEB4462006D3C800F81029 /* Allocation.m */,
0E245D6B2137F73600B012A2 /* CompressionFraming.h */,
0ED9C8632138139000621BA3 /* CompressionFraming.swift */,
0E245D6B2137F73600B012A2 /* CompressionFramingNative.h */,
0EFEB44A2006D3C800F81029 /* CoreConfiguration.swift */,
0E07597C20F0060E00F38FD8 /* CryptoAEAD.h */,
0E07597D20F0060E00F38FD8 /* CryptoAEAD.m */,
@ -518,7 +518,7 @@
0EFEB46B2006D3C800F81029 /* CryptoBox.h in Headers */,
0EFEB4592006D3C800F81029 /* Allocation.h in Headers */,
0EFEB4582006D3C800F81029 /* MSS.h in Headers */,
0E245D6C2137F73600B012A2 /* CompressionFraming.h in Headers */,
0E245D6C2137F73600B012A2 /* CompressionFramingNative.h in Headers */,
0EFEB4602006D3C800F81029 /* DataPath.h in Headers */,
0E07597E20F0060E00F38FD8 /* CryptoAEAD.h in Headers */,
0EFEB46C2006D3C800F81029 /* ZeroingData.h in Headers */,

View File

@ -38,7 +38,6 @@
import Foundation
import NetworkExtension
import SwiftyBeaver
import __TunnelKitNative
private let log = SwiftyBeaver.self
@ -165,7 +164,7 @@ extension TunnelKitProvider {
public var mtu: Int
/// 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).
public var renegotiatesAfterSeconds: Int?
@ -265,7 +264,7 @@ extension TunnelKitProvider {
self.clientCertificate = clientCertificate
self.clientKey = clientKey
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
} else {
compressionFraming = .disabled
@ -379,7 +378,7 @@ extension TunnelKitProvider {
public let mtu: Int
/// - Seealso: `TunnelKitProvider.ConfigurationBuilder.compressionFraming`
public let compressionFraming: CompressionFraming
public let compressionFraming: SessionProxy.CompressionFraming
/// - Seealso: `TunnelKitProvider.ConfigurationBuilder.renegotiatesAfterSeconds`
public let renegotiatesAfterSeconds: Int?

View File

@ -26,7 +26,29 @@
import Foundation
import __TunnelKitNative
extension CompressionFraming: CustomStringConvertible {
extension SessionProxy {
/// Defines the type of compression framing.
public enum CompressionFraming: Int, CustomStringConvertible {
/// No compression framing.
case disabled
/// Framing compatible with 2.4 `compress`.
case compress
/// Framing compatible with `comp-lzo` (deprecated).
@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 {
@ -41,4 +63,5 @@ extension CompressionFraming: CustomStringConvertible {
return "comp-lzo"
}
}
}
}

View File

@ -1,5 +1,5 @@
//
// CompressionFraming.h
// CompressionFramingNative.h
// TunnelKit
//
// Created by Davide De Rosa on 8/30/18.
@ -25,8 +25,8 @@
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, CompressionFraming) {
CompressionFramingDisabled,
CompressionFramingCompress,
CompressionFramingCompLZO __attribute__((deprecated))
typedef NS_ENUM(NSInteger, CompressionFramingNative) {
CompressionFramingNativeDisabled,
CompressionFramingNativeCompress,
CompressionFramingNativeCompLZO __attribute__((deprecated))
};

View File

@ -51,7 +51,7 @@
usesReplayProtection:(BOOL)usesReplayProtection;
- (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 *> *)decryptPackets:(nonnull NSArray<NSData *> *)packets keepAlive:(nullable bool *)keepAlive error:(NSError **)error;

View File

@ -109,7 +109,7 @@
self.inReplay = [[ReplayProtector alloc] init];
}
self.compressionFraming = CompressionFramingDisabled;
self.compressionFraming = CompressionFramingNativeDisabled;
}
return self;
}
@ -165,10 +165,10 @@
[self.decrypter setPeerId:peerId];
}
- (void)setCompressionFraming:(CompressionFraming)compressionFraming
- (void)setCompressionFraming:(CompressionFramingNative)compressionFraming
{
switch (compressionFraming) {
case CompressionFramingDisabled: {
case CompressionFramingNativeDisabled: {
self.assemblePayloadBlock = ^(uint8_t * _Nonnull packetDest, NSInteger * _Nonnull packetLengthOffset, NSData * _Nonnull payload) {
memcpy(packetDest, payload.bytes, payload.length);
*packetLengthOffset = 0;
@ -179,7 +179,7 @@
};
break;
}
case CompressionFramingCompress: {
case CompressionFramingNativeCompress: {
self.assemblePayloadBlock = ^(uint8_t * _Nonnull packetDest, NSInteger * _Nonnull packetLengthOffset, NSData * _Nonnull payload) {
memcpy(packetDest, payload.bytes, payload.length);
packetDest[payload.length] = packetDest[0];
@ -194,7 +194,7 @@
};
break;
}
case CompressionFramingCompLZO: {
case CompressionFramingNativeCompLZO: {
self.assemblePayloadBlock = ^(uint8_t * _Nonnull packetDest, NSInteger * _Nonnull packetLengthOffset, NSData * _Nonnull payload) {
memcpy(packetDest + 1, payload.bytes, payload.length);
packetDest[0] = DataPacketNoCompress;

View File

@ -36,7 +36,6 @@
//
import Foundation
import __TunnelKitNative
extension SessionProxy {

View File

@ -111,7 +111,7 @@ extension SessionProxy {
func startHandlingPackets(withPeerId peerId: UInt32? = nil, compressionFraming: CompressionFraming = .disabled) {
dataPath?.setPeerId(peerId ?? PacketPeerIdDisabled)
dataPath?.setCompressionFraming(compressionFraming)
dataPath?.setCompressionFraming(compressionFraming.native)
canHandlePackets = true
}

View File

@ -43,7 +43,7 @@ module __TunnelKitNative {
header "MSS.h"
header "PacketMacros.h"
header "ReplayProtector.h"
header "CompressionFraming.h"
header "CompressionFramingNative.h"
header "DataPath.h"
header "DataPathEncryption.h"
export *