From e6211754475e59cfe9c3ec7d2d9ccdc463279f79 Mon Sep 17 00:00:00 2001 From: zhuhaow Date: Tue, 18 Sep 2018 14:40:34 +0800 Subject: [PATCH] Update for Xcode 10 --- CHANGELOG.md | 5 +++ Cartfile | 8 ++-- Cartfile.private | 4 +- Cartfile.resolved | 12 +++--- NEKit.xcodeproj/project.pbxproj | 38 +++++++++---------- src/Crypto/CryptoHelper.swift | 3 +- src/Crypto/Libsodium.swift | 2 +- src/Crypto/SodiumStreamCrypto.swift | 12 +++--- src/Event/ObserverFactory.swift | 2 +- src/GeoIP/GeoIP.swift | 4 +- src/IPStack/DNS/DNSMessage.swift | 16 ++++---- src/IPStack/DNS/DNSResolver.swift | 2 +- src/IPStack/DNS/DNSServer.swift | 2 +- src/IPStack/DNS/DNSSession.swift | 2 +- src/IPStack/Packet/IPPacket.swift | 16 ++++---- src/IPStack/TCPStack.swift | 2 +- src/ProxyServer/GCDHTTPProxyServer.swift | 2 +- src/ProxyServer/GCDSOCKS5ProxyServer.swift | 2 +- src/ProxyServer/ProxyServer.swift | 6 +-- src/RawSocket/RawSocketFactory.swift | 4 +- src/RawSocket/RawTCPSocketProtocol.swift | 2 +- src/ResponseGenerator.swift | 2 +- src/Rule/CountryRule.swift | 4 +- src/Rule/RuleManager.swift | 2 +- .../Factory/RejectAdapterFactory.swift | 2 +- src/Socket/AdapterSocket/RejectAdapter.swift | 2 +- .../Shadowsocks/StreamObfuscater.swift | 3 +- src/Socket/SocketProtocol.swift | 2 +- src/Utils.swift | 3 +- src/Utils/Checksum.swift | 8 ++-- src/Utils/IPAddress.swift | 3 +- src/Utils/UInt128.swift | 4 +- 32 files changed, 97 insertions(+), 84 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e89d61af0..49c632c08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. I will do my best to guarantee that this project adheres to [Semantic Versioning](http://semver.org/) after 1.0.0, but please do read change log before updating. +## 0.13.0 + +### Fixed +- Build on Xcode 10 + ## 0.12.7 ### Fixed diff --git a/Cartfile b/Cartfile index 7523e60df..b7aac03bd 100644 --- a/Cartfile +++ b/Cartfile @@ -1,7 +1,7 @@ -github "robbiehanson/CocoaAsyncSocket" ~> 7.6.2 -github "CocoaLumberjack/CocoaLumberjack" ~> 3.2.1 -github "lexrus/MMDB-Swift" "0.2.8" +github "robbiehanson/CocoaAsyncSocket" ~> 7.6.3 +github "CocoaLumberjack/CocoaLumberjack" ~> 3.4.2 +github "lexrus/MMDB-Swift" "0.2.9" github "zhuhaow/Sodium-framework" "v1.0.10.1" -github "zhuhaow/YamlSwift" "master" +github "behrang/YamlSwift" "3.4.3" github "zhuhaow/tun2socks" ~> 0.6.0 github "zhuhaow/Resolver" ~> 0.1.3 diff --git a/Cartfile.private b/Cartfile.private index eb1cf0a5f..e50e460aa 100644 --- a/Cartfile.private +++ b/Cartfile.private @@ -1,2 +1,2 @@ -github "Quick/Quick" "v1.1.0" -github "Quick/Nimble" "v7.0.1" +github "Quick/Quick" "v1.3.1" +github "Quick/Nimble" "v7.3.0" diff --git a/Cartfile.resolved b/Cartfile.resolved index 681696325..ef6d9a1ca 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,9 +1,9 @@ -github "CocoaLumberjack/CocoaLumberjack" "3.4.0" -github "Quick/Nimble" "v7.0.1" -github "Quick/Quick" "v1.1.0" -github "lexrus/MMDB-Swift" "0.2.7" -github "robbiehanson/CocoaAsyncSocket" "7.6.2" +github "CocoaLumberjack/CocoaLumberjack" "3.4.2" +github "Quick/Nimble" "v7.3.0" +github "Quick/Quick" "v1.3.1" +github "behrang/YamlSwift" "3.4.3" +github "lexrus/MMDB-Swift" "0.2.9" +github "robbiehanson/CocoaAsyncSocket" "7.6.3" github "zhuhaow/Resolver" "0.1.3" github "zhuhaow/Sodium-framework" "v1.0.10.1" -github "zhuhaow/YamlSwift" "3e880fee0e68653f8304392cf0a9b7fc4b376a38" github "zhuhaow/tun2socks" "0.6.1" diff --git a/NEKit.xcodeproj/project.pbxproj b/NEKit.xcodeproj/project.pbxproj index af4985ea4..07e5020da 100644 --- a/NEKit.xcodeproj/project.pbxproj +++ b/NEKit.xcodeproj/project.pbxproj @@ -1227,24 +1227,24 @@ TargetAttributes = { 362347121D7D44E700A047DE = { CreatedOnToolsVersion = 7.3.1; - LastSwiftMigration = 0810; + LastSwiftMigration = 1000; }; 362347211D7D458E00A047DE = { CreatedOnToolsVersion = 7.3.1; - LastSwiftMigration = 0900; + LastSwiftMigration = ""; }; 36463A2F1CDCD5EB0040579C = { CreatedOnToolsVersion = 7.3; - LastSwiftMigration = 0810; + LastSwiftMigration = 1000; ProvisioningStyle = Automatic; }; 36A719971D5EEB4900DC35F5 = { CreatedOnToolsVersion = 7.3.1; - LastSwiftMigration = 0810; + LastSwiftMigration = 1000; }; 36C48D4C1CF88DED0071804F = { CreatedOnToolsVersion = 7.3.1; - LastSwiftMigration = 0900; + LastSwiftMigration = ""; ProvisioningStyle = Automatic; }; }; @@ -1693,7 +1693,7 @@ PRODUCT_BUNDLE_IDENTIFIER = me.zhuhaow.NEKit.Test; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -1711,7 +1711,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = me.zhuhaow.NEKit.Test; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -1732,8 +1732,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -1753,8 +1752,7 @@ PRODUCT_BUNDLE_IDENTIFIER = me.zhuhaow.NEKit.Test; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; VALIDATE_PRODUCT = YES; }; name = Release; @@ -1916,7 +1914,8 @@ PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -1944,7 +1943,8 @@ PRODUCT_BUNDLE_IDENTIFIER = me.zhuhaow.NEKit; PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -1963,7 +1963,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = me.zhuhaow.osx.NEKitDemo; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -1982,7 +1983,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = me.zhuhaow.osx.NEKitDemo; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -2015,8 +2017,7 @@ SDKROOT = iphoneos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -2046,8 +2047,7 @@ PRODUCT_NAME = "$(PROJECT_NAME)"; SDKROOT = iphoneos; SKIP_INSTALL = YES; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; diff --git a/src/Crypto/CryptoHelper.swift b/src/Crypto/CryptoHelper.swift index 1b14fca5d..d8d4bc92c 100644 --- a/src/Crypto/CryptoHelper.swift +++ b/src/Crypto/CryptoHelper.swift @@ -20,8 +20,9 @@ public struct CryptoHelper { public static func getIV(_ methodType: CryptoAlgorithm) -> Data { var IV = Data(count: getIVLength(methodType)) + let c = IV.count _ = IV.withUnsafeMutableBytes { - SecRandomCopyBytes(kSecRandomDefault, IV.count, $0) + SecRandomCopyBytes(kSecRandomDefault, c, $0) } return IV } diff --git a/src/Crypto/Libsodium.swift b/src/Crypto/Libsodium.swift index 4733f5456..2cf4262ae 100644 --- a/src/Crypto/Libsodium.swift +++ b/src/Crypto/Libsodium.swift @@ -3,7 +3,7 @@ import Sodium open class Libsodium { /// This must be accessed at least once before Libsodium is used. - open static let initialized: Bool = { + public static let initialized: Bool = { // this is loaded lasily and also thread-safe _ = sodium_init() return true diff --git a/src/Crypto/SodiumStreamCrypto.swift b/src/Crypto/SodiumStreamCrypto.swift index 7c636daf8..8542d7961 100644 --- a/src/Crypto/SodiumStreamCrypto.swift +++ b/src/Crypto/SodiumStreamCrypto.swift @@ -6,9 +6,9 @@ open class SodiumStreamCrypto: StreamCryptoProtocol { case chacha20, salsa20 } - open let key: Data - open let iv: Data - open let algorithm: Alogrithm + public let key: Data + public let iv: Data + public let algorithm: Alogrithm var counter = 0 @@ -38,19 +38,21 @@ open class SodiumStreamCrypto: StreamCryptoProtocol { switch algorithm { case .chacha20: + let c = UInt64(outputData.count) _ = outputData.withUnsafeMutableBytes { outputPtr in iv.withUnsafeBytes { ivPtr in key.withUnsafeBytes { keyPtr in - crypto_stream_chacha20_xor_ic(outputPtr, outputPtr, UInt64(outputData.count), ivPtr, UInt64(counter/blockSize), keyPtr) + crypto_stream_chacha20_xor_ic(outputPtr, outputPtr, c, ivPtr, UInt64(counter/blockSize), keyPtr) } } } case .salsa20: + let c = UInt64(outputData.count) _ = outputData.withUnsafeMutableBytes { outputPtr in iv.withUnsafeBytes { ivPtr in key.withUnsafeBytes { keyPtr in - crypto_stream_salsa20_xor_ic(outputPtr, outputPtr, UInt64(outputData.count), ivPtr, UInt64(counter/blockSize), keyPtr) + crypto_stream_salsa20_xor_ic(outputPtr, outputPtr, c, ivPtr, UInt64(counter/blockSize), keyPtr) } } } diff --git a/src/Event/ObserverFactory.swift b/src/Event/ObserverFactory.swift index 54fdcc425..2eefd5a2f 100644 --- a/src/Event/ObserverFactory.swift +++ b/src/Event/ObserverFactory.swift @@ -1,7 +1,7 @@ import Foundation open class ObserverFactory { - open static var currentFactory: ObserverFactory? + public static var currentFactory: ObserverFactory? public init() {} diff --git a/src/GeoIP/GeoIP.swift b/src/GeoIP/GeoIP.swift index 35d4ad36b..63376f45f 100644 --- a/src/GeoIP/GeoIP.swift +++ b/src/GeoIP/GeoIP.swift @@ -2,9 +2,9 @@ import Foundation import MMDB open class GeoIP { - open static let database = MMDB()! + public static let database = MMDB()! - open static func LookUp(_ ipAddress: String) -> MMDBCountry? { + public static func LookUp(_ ipAddress: String) -> MMDBCountry? { return GeoIP.database.lookup(ipAddress) } } diff --git a/src/IPStack/DNS/DNSMessage.swift b/src/IPStack/DNS/DNSMessage.swift index 831801832..2c3d358c5 100644 --- a/src/IPStack/DNS/DNSMessage.swift +++ b/src/IPStack/DNS/DNSMessage.swift @@ -229,9 +229,9 @@ open class DNSMessage { } open class DNSQuery { - open let name: String - open let type: DNSType - open let klass: DNSClass + public let name: String + public let type: DNSType + public let klass: DNSClass let nameBytesLength: Int init(name: String, type: DNSType = .a, klass: DNSClass = .internet) { @@ -267,12 +267,12 @@ open class DNSQuery { } open class DNSResource { - open let name: String - open let type: DNSType - open let klass: DNSClass - open let TTL: UInt32 + public let name: String + public let type: DNSType + public let klass: DNSClass + public let TTL: UInt32 let dataLength: UInt16 - open let data: Data + public let data: Data let nameBytesLength: Int diff --git a/src/IPStack/DNS/DNSResolver.swift b/src/IPStack/DNS/DNSResolver.swift index 06e38be74..80a720ed3 100644 --- a/src/IPStack/DNS/DNSResolver.swift +++ b/src/IPStack/DNS/DNSResolver.swift @@ -1,7 +1,7 @@ import Foundation public protocol DNSResolverProtocol: class { - weak var delegate: DNSResolverDelegate? { get set } + var delegate: DNSResolverDelegate? { get set } func resolve(session: DNSSession) func stop() } diff --git a/src/IPStack/DNS/DNSServer.swift b/src/IPStack/DNS/DNSServer.swift index 5e4b04e85..362d11aa1 100644 --- a/src/IPStack/DNS/DNSServer.swift +++ b/src/IPStack/DNS/DNSServer.swift @@ -9,7 +9,7 @@ open class DNSServer: DNSResolverDelegate, IPStackProtocol { /// Current DNS server. /// /// - warning: There is at most one DNS server running at the same time. If a DNS server is registered to `TUNInterface` then it must also be set here. - open static var currentServer: DNSServer? + public static var currentServer: DNSServer? /// The address of DNS server. let serverAddress: IPAddress diff --git a/src/IPStack/DNS/DNSSession.swift b/src/IPStack/DNS/DNSSession.swift index dcdfb358b..aae3c9348 100644 --- a/src/IPStack/DNS/DNSSession.swift +++ b/src/IPStack/DNS/DNSSession.swift @@ -2,7 +2,7 @@ import Foundation import CocoaLumberjackSwift open class DNSSession { - open let requestMessage: DNSMessage + public let requestMessage: DNSMessage var requestIPPacket: IPPacket? open var realIP: IPAddress? open var fakeIP: IPAddress? diff --git a/src/IPStack/Packet/IPPacket.swift b/src/IPStack/Packet/IPPacket.swift index 4600de9be..6c314fc86 100644 --- a/src/IPStack/Packet/IPPacket.swift +++ b/src/IPStack/Packet/IPPacket.swift @@ -20,7 +20,7 @@ open class IPPacket { - returns: The version of the packet. Returns `nil` if failed to parse the packet. */ - open static func peekIPVersion(_ data: Data) -> IPVersion? { + public static func peekIPVersion(_ data: Data) -> IPVersion? { guard data.count >= 20 else { return nil } @@ -36,7 +36,7 @@ open class IPPacket { - returns: The protocol of the packet. Returns `nil` if failed to parse the packet. */ - open static func peekProtocol(_ data: Data) -> TransportProtocol? { + public static func peekProtocol(_ data: Data) -> TransportProtocol? { guard data.count >= 20 else { return nil } @@ -51,7 +51,7 @@ open class IPPacket { - returns: The source IP address of the packet. Returns `nil` if failed to parse the packet. */ - open static func peekSourceAddress(_ data: Data) -> IPAddress? { + public static func peekSourceAddress(_ data: Data) -> IPAddress? { guard data.count >= 20 else { return nil } @@ -66,7 +66,7 @@ open class IPPacket { - returns: The destination IP address of the packet. Returns `nil` if failed to parse the packet. */ - open static func peekDestinationAddress(_ data: Data) -> IPAddress? { + public static func peekDestinationAddress(_ data: Data) -> IPAddress? { guard data.count >= 20 else { return nil } @@ -83,7 +83,7 @@ open class IPPacket { - note: Only TCP and UDP packet has port field. */ - open static func peekSourcePort(_ data: Data) -> Port? { + public static func peekSourcePort(_ data: Data) -> Port? { guard let proto = peekProtocol(data) else { return nil } @@ -111,7 +111,7 @@ open class IPPacket { - note: Only TCP and UDP packet has port field. */ - open static func peekDestinationPort(_ data: Data) -> Port? { + public static func peekDestinationPort(_ data: Data) -> Port? { guard let proto = peekProtocol(data) else { return nil } @@ -242,7 +242,7 @@ open class IPPacket { } self.protocolParser = parser default: - DDLogError("Can not parse packet header of type \(transportProtocol) yet") + DDLogError("Can not parse packet header of type \(String(describing: transportProtocol)) yet") return nil } } @@ -261,7 +261,7 @@ open class IPPacket { } func buildPacket() { - packetData = NSMutableData(length: Int(headerLength) + protocolParser.bytesLength) as Data! + packetData = NSMutableData(length: Int(headerLength) + protocolParser.bytesLength) as Data? // set header setPayloadWithUInt8(headerLength / 4 + version.rawValue << 4, at: 0) diff --git a/src/IPStack/TCPStack.swift b/src/IPStack/TCPStack.swift index 356b07aaa..2631b53aa 100644 --- a/src/IPStack/TCPStack.swift +++ b/src/IPStack/TCPStack.swift @@ -5,7 +5,7 @@ import CocoaLumberjackSwift /// This class wraps around tun2socks to build a TCP only IP stack. open class TCPStack: TSIPStackDelegate, IPStackProtocol { /// The `TCPStack` singleton instance. - open static var stack: TCPStack { + public static var stack: TCPStack { TSIPStack.stack.delegate = _stack TSIPStack.stack.processQueue = QueueFactory.getQueue() return _stack diff --git a/src/ProxyServer/GCDHTTPProxyServer.swift b/src/ProxyServer/GCDHTTPProxyServer.swift index b157989d8..30873797c 100644 --- a/src/ProxyServer/GCDHTTPProxyServer.swift +++ b/src/ProxyServer/GCDHTTPProxyServer.swift @@ -17,7 +17,7 @@ public final class GCDHTTPProxyServer: GCDProxyServer { - parameter socket: The accepted socket. */ - override open func handleNewGCDSocket(_ socket: GCDTCPSocket) { + override public func handleNewGCDSocket(_ socket: GCDTCPSocket) { let proxySocket = HTTPProxySocket(socket: socket) didAcceptNewSocket(proxySocket) } diff --git a/src/ProxyServer/GCDSOCKS5ProxyServer.swift b/src/ProxyServer/GCDSOCKS5ProxyServer.swift index 979db361e..eb6bd730c 100644 --- a/src/ProxyServer/GCDSOCKS5ProxyServer.swift +++ b/src/ProxyServer/GCDSOCKS5ProxyServer.swift @@ -17,7 +17,7 @@ public final class GCDSOCKS5ProxyServer: GCDProxyServer { - parameter socket: The accepted socket. */ - override open func handleNewGCDSocket(_ socket: GCDTCPSocket) { + override public func handleNewGCDSocket(_ socket: GCDTCPSocket) { let proxySocket = SOCKS5ProxySocket(socket: socket) didAcceptNewSocket(proxySocket) } diff --git a/src/ProxyServer/ProxyServer.swift b/src/ProxyServer/ProxyServer.swift index 8e2816c09..adae16a0b 100644 --- a/src/ProxyServer/ProxyServer.swift +++ b/src/ProxyServer/ProxyServer.swift @@ -11,15 +11,15 @@ open class ProxyServer: NSObject, TunnelDelegate { typealias TunnelArray = [Tunnel] /// The port of proxy server. - open let port: Port + public let port: Port /// The address of proxy server. - open let address: IPAddress? + public let address: IPAddress? /// The type of the proxy server. /// /// This can be set to anything describing the proxy server. - open let type: String + public let type: String /// The description of proxy server. open override var description: String { diff --git a/src/RawSocket/RawSocketFactory.swift b/src/RawSocket/RawSocketFactory.swift index 64ee2fc17..c786b2ca0 100644 --- a/src/RawSocket/RawSocketFactory.swift +++ b/src/RawSocket/RawSocketFactory.swift @@ -16,7 +16,7 @@ open class RawSocketFactory { /// Current active `NETunnelProvider` which creates `NWTCPConnection` instance. /// /// - note: Must set before any connection is created if `NWTCPSocket` or `NWUDPSocket` is used. - open static weak var TunnelProvider: NETunnelProvider? + public static weak var TunnelProvider: NETunnelProvider? /** Return `RawTCPSocket` instance. @@ -25,7 +25,7 @@ open class RawSocketFactory { - returns: The created socket instance. */ - open static func getRawSocket(_ type: SocketBaseType? = nil) -> RawTCPSocketProtocol { + public static func getRawSocket(_ type: SocketBaseType? = nil) -> RawTCPSocketProtocol { switch type { case .some(.nw): return NWTCPSocket() diff --git a/src/RawSocket/RawTCPSocketProtocol.swift b/src/RawSocket/RawTCPSocketProtocol.swift index ee76bf726..a746256d3 100644 --- a/src/RawSocket/RawTCPSocketProtocol.swift +++ b/src/RawSocket/RawTCPSocketProtocol.swift @@ -7,7 +7,7 @@ import Foundation /// - warning: It is expected that the instance is accessed on the specific queue only. public protocol RawTCPSocketProtocol : class { /// The `RawTCPSocketDelegate` instance. - weak var delegate: RawTCPSocketDelegate? { get set } + var delegate: RawTCPSocketDelegate? { get set } /// If the socket is connected. var isConnected: Bool { get } diff --git a/src/ResponseGenerator.swift b/src/ResponseGenerator.swift index 2f35a8741..33a3f72ed 100644 --- a/src/ResponseGenerator.swift +++ b/src/ResponseGenerator.swift @@ -1,7 +1,7 @@ import Foundation open class ResponseGenerator { - open let session: ConnectSession + public let session: ConnectSession public init(withSession session: ConnectSession) { self.session = session diff --git a/src/Rule/CountryRule.swift b/src/Rule/CountryRule.swift index 772e5658a..bf0140d78 100644 --- a/src/Rule/CountryRule.swift +++ b/src/Rule/CountryRule.swift @@ -6,10 +6,10 @@ open class CountryRule: Rule { fileprivate let adapterFactory: AdapterFactory /// The ISO code of the country. - open let countryCode: String + public let countryCode: String /// The rule should match the session which matches the country or not. - open let match: Bool + public let match: Bool open override var description: String { return "" diff --git a/src/Rule/RuleManager.swift b/src/Rule/RuleManager.swift index 298dc9f00..bd540625e 100644 --- a/src/Rule/RuleManager.swift +++ b/src/Rule/RuleManager.swift @@ -5,7 +5,7 @@ open class RuleManager { /// The current used `RuleManager`, there is only one manager should be used at a time. /// /// - note: This should be set before any DNS or connect sessions. - open static var currentManager: RuleManager = RuleManager(fromRules: [], appendDirect: true) + public static var currentManager: RuleManager = RuleManager(fromRules: [], appendDirect: true) /// The rule list. var rules: [Rule] = [] diff --git a/src/Socket/AdapterSocket/Factory/RejectAdapterFactory.swift b/src/Socket/AdapterSocket/Factory/RejectAdapterFactory.swift index 75b53f4ab..3032cef2e 100644 --- a/src/Socket/AdapterSocket/Factory/RejectAdapterFactory.swift +++ b/src/Socket/AdapterSocket/Factory/RejectAdapterFactory.swift @@ -1,7 +1,7 @@ import Foundation open class RejectAdapterFactory: AdapterFactory { - open let delay: Int + public let delay: Int public init(delay: Int = Opt.RejectAdapterDefaultDelay) { self.delay = delay diff --git a/src/Socket/AdapterSocket/RejectAdapter.swift b/src/Socket/AdapterSocket/RejectAdapter.swift index ee3fe4dd7..8a61e3dfe 100644 --- a/src/Socket/AdapterSocket/RejectAdapter.swift +++ b/src/Socket/AdapterSocket/RejectAdapter.swift @@ -1,7 +1,7 @@ import Foundation public class RejectAdapter: AdapterSocket { - open let delay: Int + public let delay: Int public init(delay: Int) { self.delay = delay diff --git a/src/Socket/AdapterSocket/Shadowsocks/StreamObfuscater.swift b/src/Socket/AdapterSocket/Shadowsocks/StreamObfuscater.swift index 8d00265a6..c90e86446 100644 --- a/src/Socket/AdapterSocket/Shadowsocks/StreamObfuscater.swift +++ b/src/Socket/AdapterSocket/Shadowsocks/StreamObfuscater.swift @@ -144,8 +144,9 @@ extension ShadowsocksAdapter { var kc = Data(count: writeIV!.count + MemoryLayout.size(ofValue: count)) kc.replaceSubrange(0.. UInt16 { + public static func computeChecksum(_ data: Data, from start: Int = 0, to end: Int? = nil, withPseudoHeaderChecksum initChecksum: UInt32 = 0) -> UInt16 { return toChecksum(computeChecksumUnfold(data, from: start, to: end, withPseudoHeaderChecksum: initChecksum)) } - open static func validateChecksum(_ payload: Data, from start: Int = 0, to end: Int? = nil) -> Bool { + public static func validateChecksum(_ payload: Data, from start: Int = 0, to end: Int? = nil) -> Bool { let cs = computeChecksumUnfold(payload, from: start, to: end) return toChecksum(cs) == 0 } - open static func computeChecksumUnfold(_ data: Data, from start: Int = 0, to end: Int? = nil, withPseudoHeaderChecksum initChecksum: UInt32 = 0) -> UInt32 { + public static func computeChecksumUnfold(_ data: Data, from start: Int = 0, to end: Int? = nil, withPseudoHeaderChecksum initChecksum: UInt32 = 0) -> UInt32 { let scanner = BinaryDataScanner(data: data, littleEndian: true) scanner.skip(to: start) var result: UInt32 = initChecksum @@ -34,7 +34,7 @@ open class Checksum { return result } - open static func toChecksum(_ checksum: UInt32) -> UInt16 { + public static func toChecksum(_ checksum: UInt32) -> UInt16 { var result = checksum while (result) >> 16 != 0 { result = result >> 16 + result & 0xFFFF diff --git a/src/Utils/IPAddress.swift b/src/Utils/IPAddress.swift index 59e797a7a..01db364a0 100644 --- a/src/Utils/IPAddress.swift +++ b/src/Utils/IPAddress.swift @@ -181,9 +181,10 @@ public func < (lhs: IPAddress, rhs: IPAddress) -> Bool { case (.IPv4(let addrl), .IPv4(let addrr)): return addrl.s_addr.byteSwapped < addrr.s_addr.byteSwapped case (.IPv6(var addrl), .IPv6(var addrr)): + let ms = MemoryLayout.size(ofValue: addrl) return (withUnsafeBytes(of: &addrl) { ptrl in withUnsafeBytes(of: &addrr) { ptrr in - return memcmp(ptrl.baseAddress!, ptrr.baseAddress!, MemoryLayout.size(ofValue: addrl)) + return memcmp(ptrl.baseAddress!, ptrr.baseAddress!, ms) } }) < 0 case (.IPv4, .IPv6): diff --git a/src/Utils/UInt128.swift b/src/Utils/UInt128.swift index f4ed94655..9ca3ece8b 100644 --- a/src/Utils/UInt128.swift +++ b/src/Utils/UInt128.swift @@ -106,6 +106,8 @@ public struct UInt128 { // MARK: - FixedWidthInteger Conformance extension UInt128 : FixedWidthInteger { + public static var bitWidth : Int { return 128 } + // MARK: Instance Properties public var nonzeroBitCount: Int { @@ -435,7 +437,7 @@ extension UInt128 : FixedWidthInteger { extension UInt128 : BinaryInteger { // MARK: Instance Properties - public static var bitWidth : Int { return 128 } + public var bitWidth : Int { return 128 } // MARK: Instance Methods