Parse compression from several places

- PUSH_REPLY
- .ovpn configuration
- TunnelKitProvider
This commit is contained in:
Davide De Rosa 2019-03-19 12:04:42 +01:00
parent 4d6d51818d
commit 0eb0e3e478
15 changed files with 209 additions and 29 deletions

View File

@ -80,6 +80,10 @@
0E58BF5722411F3E006FB157 /* LZO.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E58BF5522411F37006FB157 /* LZO.h */; };
0E58BF5922411FEF006FB157 /* LZO.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E58BF5822411FEF006FB157 /* LZO.m */; };
0E58BF5A22411FEF006FB157 /* LZO.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E58BF5822411FEF006FB157 /* LZO.m */; };
0E58BF502240F98F006FB157 /* CompressionAlgorithmNative.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E58BF4F2240F98E006FB157 /* CompressionAlgorithmNative.h */; };
0E58BF512240F98F006FB157 /* CompressionAlgorithmNative.h in Headers */ = {isa = PBXBuildFile; fileRef = 0E58BF4F2240F98E006FB157 /* CompressionAlgorithmNative.h */; };
0E58BF532240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E58BF522240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift */; };
0E58BF542240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E58BF522240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift */; };
0E58F1302138AC2F00A49F27 /* DNSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E58F12F2138AC2F00A49F27 /* DNSTests.swift */; };
0E749F5F2178885500BB2701 /* SessionProxy+PIA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E749F5E2178885500BB2701 /* SessionProxy+PIA.swift */; };
0E749F602178885500BB2701 /* SessionProxy+PIA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E749F5E2178885500BB2701 /* SessionProxy+PIA.swift */; };
@ -296,6 +300,8 @@
0E58BF4922405C2F006FB157 /* StandardLZO.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StandardLZO.m; sourceTree = "<group>"; };
0E58BF5522411F37006FB157 /* LZO.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LZO.h; sourceTree = "<group>"; };
0E58BF5822411FEF006FB157 /* LZO.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LZO.m; sourceTree = "<group>"; };
0E58BF4F2240F98E006FB157 /* CompressionAlgorithmNative.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompressionAlgorithmNative.h; sourceTree = "<group>"; };
0E58BF522240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SessionProxy+CompressionAlgorithm.swift"; sourceTree = "<group>"; };
0E58F12F2138AC2F00A49F27 /* DNSTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DNSTests.swift; sourceTree = "<group>"; };
0E6479DD212EAC96008E6888 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0E6479E0212EACD6008E6888 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@ -582,6 +588,7 @@
0EFEB42E2006D3C800F81029 /* Allocation.h */,
0EFEB4462006D3C800F81029 /* Allocation.m */,
0E12B2A421454F7F00B4BAE9 /* BidirectionalState.swift */,
0E58BF4F2240F98E006FB157 /* CompressionAlgorithmNative.h */,
0E245D6B2137F73600B012A2 /* CompressionFramingNative.h */,
0E011F872196E2AB00BA59EE /* ConfigurationParser.swift */,
0E39BCE6214B2AB60035E9DE /* ControlPacket.h */,
@ -625,6 +632,7 @@
0E0C2123212ED29D008AB282 /* SessionError.swift */,
0EFEB43C2006D3C800F81029 /* SessionProxy.swift */,
0EFEB43A2006D3C800F81029 /* SessionProxy+Authenticator.swift */,
0E58BF522240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift */,
0ED9C8632138139000621BA3 /* SessionProxy+CompressionFraming.swift */,
0E0C2124212ED29D008AB282 /* SessionProxy+Configuration.swift */,
0EFEB42A2006D3C800F81029 /* SessionProxy+EncryptionBridge.swift */,
@ -703,6 +711,7 @@
0E58BF3722405410006FB157 /* minilzo.h in Headers */,
0E07596E20EF79B400F38FD8 /* CryptoCBC.h in Headers */,
0E58BF3522405410006FB157 /* lzodefs.h in Headers */,
0E58BF502240F98F006FB157 /* CompressionAlgorithmNative.h in Headers */,
0E07596320EF733F00F38FD8 /* CryptoMacros.h in Headers */,
0EFEB46E2006D3C800F81029 /* TLSBox.h in Headers */,
0E07596B20EF79AB00F38FD8 /* Crypto.h in Headers */,
@ -730,6 +739,7 @@
0E58BF3822405410006FB157 /* minilzo.h in Headers */,
0E07596F20EF79B400F38FD8 /* CryptoCBC.h in Headers */,
0E58BF3622405410006FB157 /* lzodefs.h in Headers */,
0E58BF512240F98F006FB157 /* CompressionAlgorithmNative.h in Headers */,
0E07596420EF733F00F38FD8 /* CryptoMacros.h in Headers */,
0EEC49EA20B5F7F6008FEB91 /* ZeroingData.h in Headers */,
0E07596C20EF79AB00F38FD8 /* Crypto.h in Headers */,
@ -1178,6 +1188,7 @@
0EFEB4782006D3C800F81029 /* TunnelKitProvider+Configuration.swift in Sources */,
0E3E0F212108A8CC00B371C1 /* SessionProxy+PushReply.swift in Sources */,
0EFEB4752006D3C800F81029 /* Errors.m in Sources */,
0E58BF532240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift in Sources */,
0E12B2A521454F7F00B4BAE9 /* BidirectionalState.swift in Sources */,
0EBBF2E52084FE6F00E36B40 /* GenericSocket.swift in Sources */,
0EFEB4762006D3C800F81029 /* DataPath.m in Sources */,
@ -1244,6 +1255,7 @@
0EFEB4A42006D7F300F81029 /* DataPath.m in Sources */,
0EBBF2E62084FE6F00E36B40 /* GenericSocket.swift in Sources */,
0E3E0F222108A8CC00B371C1 /* SessionProxy+PushReply.swift in Sources */,
0E58BF542240FAA6006FB157 /* SessionProxy+CompressionAlgorithm.swift in Sources */,
0E12B2A621454F7F00B4BAE9 /* BidirectionalState.swift in Sources */,
0EFEB4912006D7F300F81029 /* TLSBox.m in Sources */,
0EFEB49D2006D7F300F81029 /* IOInterface.swift in Sources */,

View File

@ -62,6 +62,7 @@ extension TunnelKitProvider {
clientKey: nil,
checksEKU: false,
compressionFraming: .disabled,
compressionAlgorithm: .disabled,
tlsWrap: nil,
keepAliveInterval: nil,
renegotiatesAfter: nil,
@ -178,6 +179,11 @@ extension TunnelKitProvider {
} else {
sessionConfigurationBuilder.compressionFraming = ConfigurationBuilder.defaults.sessionConfiguration.compressionFraming
}
if let compressionAlgorithmValue = providerConfiguration[S.compressionAlgorithm] as? Int, let compressionAlgorithm = SessionProxy.CompressionAlgorithm(rawValue: compressionAlgorithmValue) {
sessionConfigurationBuilder.compressionAlgorithm = compressionAlgorithm
} else {
sessionConfigurationBuilder.compressionAlgorithm = ConfigurationBuilder.defaults.sessionConfiguration.compressionAlgorithm
}
if let tlsWrapData = providerConfiguration[S.tlsWrap] as? Data {
do {
sessionConfigurationBuilder.tlsWrap = try SessionProxy.TLSWrap.deserialized(tlsWrapData)
@ -248,6 +254,8 @@ extension TunnelKitProvider {
static let compressionFraming = "CompressionFraming"
static let compressionAlgorithm = "CompressionAlgorithm"
static let tlsWrap = "TLSWrap"
static let keepAlive = "KeepAlive"
@ -408,6 +416,9 @@ extension TunnelKitProvider {
dict[S.resolvedAddresses] = resolvedAddresses
}
dict[S.compressionFraming] = sessionConfiguration.compressionFraming.rawValue
if let compressionAlgorithm = sessionConfiguration.compressionAlgorithm?.rawValue {
dict[S.compressionAlgorithm] = compressionAlgorithm
}
if let tlsWrapData = sessionConfiguration.tlsWrap?.serialized() {
dict[S.tlsWrap] = tlsWrapData
}
@ -479,6 +490,11 @@ extension TunnelKitProvider {
}
log.info("\tMTU: \(mtu)")
log.info("\tCompression framing: \(sessionConfiguration.compressionFraming)")
if let compressionAlgorithm = sessionConfiguration.compressionAlgorithm, compressionAlgorithm != .disabled {
log.info("\tCompression algorithm: \(compressionAlgorithm)")
} else {
log.info("\tCompression algorithm: disabled")
}
if let keepAliveSeconds = sessionConfiguration.keepAliveInterval, keepAliveSeconds > 0 {
log.info("\tKeep-alive: \(keepAliveSeconds) seconds")
} else {

View File

@ -0,0 +1,32 @@
//
// CompressionFramingNative.h
// TunnelKit
//
// Created by Davide De Rosa on 3/19/19.
// Copyright (c) 2019 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/Foundation.h>
typedef NS_ENUM(NSInteger, CompressionAlgorithmNative) {
CompressionAlgorithmNativeDisabled,
CompressionAlgorithmNativeLZO,
CompressionAlgorithmNativeOther
};

View File

@ -141,6 +141,7 @@ public class ConfigurationParser {
var cipher: SessionProxy.Cipher?
var digest: SessionProxy.Digest?
var compressionFraming: SessionProxy.CompressionFraming = .disabled
var compressionAlgorithm: SessionProxy.CompressionAlgorithm = .disabled
var optCA: CryptoContainer?
var clientCertificate: CryptoContainer?
var clientKey: CryptoContainer?
@ -296,13 +297,18 @@ public class ConfigurationParser {
isHandled = true
compressionFraming = .compLZO
guard let arg = $0.first else {
warning = warning ?? .unsupportedConfiguration(option: line)
return
}
guard arg == "no" else {
unsupportedError = .unsupportedConfiguration(option: line)
return
if !LZOIsSupported() {
guard let arg = $0.first else {
warning = warning ?? .unsupportedConfiguration(option: line)
return
}
guard arg == "no" else {
unsupportedError = .unsupportedConfiguration(option: line)
return
}
} else {
let arg = $0.first
compressionAlgorithm = (arg == "no") ? .disabled : .LZO
}
}
Regex.compress.enumerateArguments(in: line) {
@ -310,6 +316,7 @@ public class ConfigurationParser {
compressionFraming = .compress
guard $0.isEmpty else {
compressionAlgorithm = .other
unsupportedError = .unsupportedConfiguration(option: line)
return
}
@ -412,6 +419,7 @@ public class ConfigurationParser {
sessionBuilder.cipher = cipher ?? .aes128cbc
sessionBuilder.digest = digest ?? .sha1
sessionBuilder.compressionFraming = compressionFraming
sessionBuilder.compressionAlgorithm = compressionAlgorithm
sessionBuilder.tlsWrap = tlsWrap
sessionBuilder.clientCertificate = clientCertificate
sessionBuilder.clientKey = clientKey

View File

@ -51,6 +51,7 @@ NS_ASSUME_NONNULL_BEGIN
decrypter:(id<DataPathDecrypter>)decrypter
peerId:(uint32_t)peerId // 24-bit, discard most significant byte
compressionFraming:(CompressionFramingNative)compressionFraming
compressionAlgorithm:(CompressionAlgorithmNative)compressionAlgorithm
maxPackets:(NSInteger)maxPackets
usesReplayProtection:(BOOL)usesReplayProtection;

View File

@ -82,7 +82,13 @@
return (uint8_t *)addr;
}
- (instancetype)initWithEncrypter:(id<DataPathEncrypter>)encrypter decrypter:(id<DataPathDecrypter>)decrypter peerId:(uint32_t)peerId compressionFraming:(CompressionFramingNative)compressionFraming maxPackets:(NSInteger)maxPackets usesReplayProtection:(BOOL)usesReplayProtection
- (instancetype)initWithEncrypter:(id<DataPathEncrypter>)encrypter
decrypter:(id<DataPathDecrypter>)decrypter
peerId:(uint32_t)peerId
compressionFraming:(CompressionFramingNative)compressionFraming
compressionAlgorithm:(CompressionAlgorithmNative)compressionAlgorithm
maxPackets:(NSInteger)maxPackets
usesReplayProtection:(BOOL)usesReplayProtection
{
NSParameterAssert(encrypter);
NSParameterAssert(decrypter);
@ -111,8 +117,7 @@
[self.decrypter setPeerId:peerId];
[self setCompressionFraming:compressionFraming];
// FIXME: compress according to compression flag, not just framing
if (LZOIsSupported() && (compressionFraming == CompressionFramingNativeCompLZO)) {
if (LZOIsSupported() && (compressionFraming == CompressionFramingNativeCompLZO) && (compressionAlgorithm == CompressionAlgorithmNativeLZO)) {
self.lzo = LZOCreate();
}
}

View File

@ -0,0 +1,66 @@
//
// SessionProxy+CompressionAlgorithm.swift
// TunnelKit
//
// Created by Davide De Rosa on 3/19/19.
// Copyright (c) 2019 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
import __TunnelKitNative
extension SessionProxy {
/// Defines the type of compression algorithm.
public enum CompressionAlgorithm: Int, Codable, CustomStringConvertible {
/// No compression.
case disabled
/// LZO compression.
case LZO
/// Any other compression algorithm (unsupported).
case other
var native: CompressionAlgorithmNative {
guard let val = CompressionAlgorithmNative(rawValue: rawValue) else {
fatalError("Unhandled CompressionAlgorithm bridging")
}
return val
}
// MARK: CustomStringConvertible
/// :nodoc:
public var description: String {
switch self {
case .disabled:
return "disabled"
case .LZO:
return "lzo"
case .other:
return "other"
}
}
}
}

View File

@ -156,6 +156,9 @@ extension SessionProxy {
/// Sets compression framing, disabled by default.
public var compressionFraming: CompressionFraming
/// Sets compression algorithm, disabled by default.
public var compressionAlgorithm: CompressionAlgorithm?
/// The optional TLS wrapping.
public var tlsWrap: TLSWrap?
@ -180,6 +183,7 @@ extension SessionProxy {
clientKey = nil
checksEKU = false
compressionFraming = .disabled
compressionAlgorithm = .disabled
tlsWrap = nil
keepAliveInterval = nil
renegotiatesAfter = nil
@ -201,6 +205,7 @@ extension SessionProxy {
clientKey: clientKey,
checksEKU: checksEKU,
compressionFraming: compressionFraming,
compressionAlgorithm: compressionAlgorithm,
tlsWrap: tlsWrap,
keepAliveInterval: keepAliveInterval,
renegotiatesAfter: renegotiatesAfter,
@ -234,6 +239,9 @@ extension SessionProxy {
/// - Seealso: `SessionProxy.ConfigurationBuilder.compressionFraming`
public let compressionFraming: CompressionFraming
/// - Seealso: `SessionProxy.ConfigurationBuilder.compressionAlgorithm`
public let compressionAlgorithm: CompressionAlgorithm?
/// - Seealso: `SessionProxy.ConfigurationBuilder.tlsWrap`
public var tlsWrap: TLSWrap?
@ -262,6 +270,7 @@ extension SessionProxy {
builder.clientKey = clientKey
builder.checksEKU = checksEKU
builder.compressionFraming = compressionFraming
builder.compressionAlgorithm = compressionAlgorithm
builder.tlsWrap = tlsWrap
builder.keepAliveInterval = keepAliveInterval
builder.renegotiatesAfter = renegotiatesAfter
@ -282,6 +291,7 @@ extension SessionProxy {
(lhs.clientKey == rhs.clientKey) &&
(lhs.checksEKU == rhs.checksEKU) &&
(lhs.compressionFraming == rhs.compressionFraming) &&
(lhs.compressionAlgorithm == rhs.compressionAlgorithm) &&
(lhs.keepAliveInterval == rhs.keepAliveInterval) &&
(lhs.renegotiatesAfter == rhs.renegotiatesAfter) &&
(lhs.usesPIAPatches == rhs.usesPIAPatches) &&

View File

@ -150,8 +150,8 @@ public protocol SessionReply {
/// The optional compression framing.
var compressionFraming: SessionProxy.CompressionFraming? { get }
/// True if uses compression.
var usesCompression: Bool { get }
/// The optional compression algorithm.
var compressionAlgorithm: SessionProxy.CompressionAlgorithm? { get }
/// The optional keep-alive interval.
var ping: Int? { get }
@ -217,7 +217,7 @@ extension SessionProxy {
let compressionFraming: SessionProxy.CompressionFraming?
let usesCompression: Bool
let compressionAlgorithm: SessionProxy.CompressionAlgorithm?
let ping: Int?
@ -246,7 +246,7 @@ extension SessionProxy {
var dnsServers: [String] = []
var compressionFraming: SessionProxy.CompressionFraming?
var usesCompression = false
var compressionAlgorithm: SessionProxy.CompressionAlgorithm?
var ping: Int?
var authToken: String?
var peerId: UInt32?
@ -395,11 +395,19 @@ extension SessionProxy {
switch $0[0] {
case "comp-lzo":
compressionFraming = .compLZO
usesCompression = !(($0.count == 2) && ($0[1] == "no"))
if !(($0.count == 2) && ($0[1] == "no")) {
compressionAlgorithm = .LZO
} else {
compressionAlgorithm = .disabled
}
case "compress":
compressionFraming = .compress
usesCompression = ($0.count > 1)
if $0.count > 1 {
compressionAlgorithm = .other
} else {
compressionAlgorithm = .disabled
}
default:
break
@ -430,7 +438,7 @@ extension SessionProxy {
self.dnsServers = dnsServers
self.compressionFraming = compressionFraming
self.usesCompression = usesCompression
self.compressionAlgorithm = compressionAlgorithm
self.ping = ping
self.authToken = authToken
self.peerId = peerId

View File

@ -912,9 +912,21 @@ public class SessionProxy {
reply = optionalReply
log.debug("Received PUSH_REPLY: \"\(reply.maskedDescription)\"")
if let framing = reply.compressionFraming, reply.usesCompression {
log.error("Server has compression enabled and this is currently unsupported (\(framing))")
throw SessionError.serverCompression
if let framing = reply.compressionFraming, let compression = reply.compressionAlgorithm, compression != .disabled {
switch framing {
case .compress:
log.error("Server has new compression enabled and this is currently unsupported (\(framing))")
throw SessionError.serverCompression
case .compLZO:
if !LZOIsSupported() {
log.error("Server has legacy LZO compression enabled and this was not built into the library (\(framing))")
throw SessionError.serverCompression
}
default:
break
}
}
} catch let e {
deferStop(.shutdown, e)
@ -1021,6 +1033,10 @@ public class SessionProxy {
if let negFraming = pushedFraming {
log.info("\tNegotiated compression framing: \(negFraming)")
}
let pushedCompression = pushReply.compressionAlgorithm
if let negCompression = pushedCompression {
log.info("\tNegotiated compression algorithm: \(negCompression)")
}
if let negPing = pushReply.ping {
log.info("\tNegotiated keep-alive: \(negPing) seconds")
}
@ -1048,6 +1064,7 @@ public class SessionProxy {
decrypter: bridge.decrypter(),
peerId: pushReply.peerId ?? PacketPeerIdDisabled,
compressionFraming: (pushedFraming ?? configuration.compressionFraming).native,
compressionAlgorithm: (pushedCompression ?? configuration.compressionAlgorithm ?? .disabled).native,
maxPackets: link?.packetBufferSize ?? 200,
usesReplayProtection: CoreConfiguration.usesReplayProtection
)

View File

@ -45,6 +45,7 @@ module __TunnelKitNative {
header "ControlPacket.h"
header "ReplayProtector.h"
header "CompressionFramingNative.h"
header "CompressionAlgorithmNative.h"
header "DataPath.h"
header "DataPathCrypto.h"
header "LZO.h"

View File

@ -57,9 +57,11 @@ class ConfigurationParserTests: XCTestCase {
}
func testCompression() throws {
XCTAssertNotNil(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo"]).warning)
// XCTAssertNotNil(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo"]).warning)
XCTAssertNil(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo"]).warning)
XCTAssertNoThrow(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo no"]))
XCTAssertThrowsError(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo yes"]))
XCTAssertNoThrow(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo yes"]))
// XCTAssertThrowsError(try ConfigurationParser.parsed(fromLines: base + ["comp-lzo yes"]))
XCTAssertNoThrow(try ConfigurationParser.parsed(fromLines: base + ["compress"]))
XCTAssertThrowsError(try ConfigurationParser.parsed(fromLines: base + ["compress lzo"]))

View File

@ -92,6 +92,7 @@ class DataPathEncryptionTests: XCTestCase {
decrypter: dec,
peerId: peerId ?? PacketPeerIdDisabled,
compressionFraming: .disabled,
compressionAlgorithm: .disabled,
maxPackets: 1000,
usesReplayProtection: false
)

View File

@ -59,6 +59,7 @@ class DataPathPerformanceTests: XCTestCase {
decrypter: decrypter,
peerId: PacketPeerIdDisabled,
compressionFraming: .disabled,
compressionAlgorithm: .disabled,
maxPackets: 200,
usesReplayProtection: false
)

View File

@ -28,8 +28,8 @@ import XCTest
private extension SessionReply {
func debug() {
print("Compression framing: \(dnsServers)")
print("Compression: \(usesCompression)")
print("Compression framing: \(compressionFraming?.description ?? "none")")
print("Compression algorithm: \(compressionAlgorithm?.description ?? "none")")
print("IPv4: \(ipv4?.description ?? "none")")
print("IPv6: \(ipv6?.description ?? "none")")
print("DNS: \(dnsServers)")
@ -109,27 +109,27 @@ class PushTests: XCTestCase {
reply = try! SessionProxy.PushReply(message: msg.appending(",comp-lzo no"))!
reply.debug()
XCTAssertEqual(reply.compressionFraming, .compLZO)
XCTAssertFalse(reply.usesCompression)
XCTAssertEqual(reply.compressionAlgorithm, .disabled)
reply = try! SessionProxy.PushReply(message: msg.appending(",comp-lzo"))!
reply.debug()
XCTAssertEqual(reply.compressionFraming, .compLZO)
XCTAssertTrue(reply.usesCompression)
XCTAssertEqual(reply.compressionAlgorithm, .LZO)
reply = try! SessionProxy.PushReply(message: msg.appending(",comp-lzo yes"))!
reply.debug()
XCTAssertEqual(reply.compressionFraming, .compLZO)
XCTAssertTrue(reply.usesCompression)
XCTAssertEqual(reply.compressionAlgorithm, .LZO)
reply = try! SessionProxy.PushReply(message: msg.appending(",compress"))!
reply.debug()
XCTAssertEqual(reply.compressionFraming, .compress)
XCTAssertFalse(reply.usesCompression)
XCTAssertEqual(reply.compressionAlgorithm, .disabled)
reply = try! SessionProxy.PushReply(message: msg.appending(",compress lz4"))!
reply.debug()
XCTAssertEqual(reply.compressionFraming, .compress)
XCTAssertTrue(reply.usesCompression)
XCTAssertEqual(reply.compressionAlgorithm, .other)
}
func testNCP() {