From c4b0964c3c7a1b12137be96e6471940302ec6b7c Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Fri, 24 Aug 2018 12:44:17 +0200 Subject: [PATCH] Improve split naming *Socket + *Link --- .../AppExtension/ConnectionStrategy.swift | 4 ++-- .../Transport/NETCPInterface.swift | 20 +++++++++---------- .../Transport/NEUDPInterface.swift | 20 +++++++++---------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/TunnelKit/Sources/AppExtension/ConnectionStrategy.swift b/TunnelKit/Sources/AppExtension/ConnectionStrategy.swift index 1b6769e..5c7c31b 100644 --- a/TunnelKit/Sources/AppExtension/ConnectionStrategy.swift +++ b/TunnelKit/Sources/AppExtension/ConnectionStrategy.swift @@ -116,11 +116,11 @@ private extension NEProvider { switch endpointProtocol.socketType { case .udp: let impl = createUDPSession(to: endpoint, from: nil) - return NEUDPInterface(impl: impl) + return NEUDPSocket(impl: impl) case .tcp: let impl = createTCPConnection(to: endpoint, enableTLS: false, tlsParameters: nil, delegate: nil) - return NETCPInterface(impl: impl) + return NETCPSocket(impl: impl) } } } diff --git a/TunnelKit/Sources/AppExtension/Transport/NETCPInterface.swift b/TunnelKit/Sources/AppExtension/Transport/NETCPInterface.swift index 62943b7..95977f9 100644 --- a/TunnelKit/Sources/AppExtension/Transport/NETCPInterface.swift +++ b/TunnelKit/Sources/AppExtension/Transport/NETCPInterface.swift @@ -12,7 +12,7 @@ import SwiftyBeaver private let log = SwiftyBeaver.self -class NETCPInterface: NSObject, GenericSocket { +class NETCPSocket: NSObject, GenericSocket { private static var linkContext = 0 private let impl: NWTCPConnection @@ -55,13 +55,13 @@ class NETCPInterface: NSObject, GenericSocket { return } } - impl.addObserver(self, forKeyPath: #keyPath(NWTCPConnection.state), options: [.initial, .new], context: &NETCPInterface.linkContext) - impl.addObserver(self, forKeyPath: #keyPath(NWTCPConnection.hasBetterPath), options: .new, context: &NETCPInterface.linkContext) + impl.addObserver(self, forKeyPath: #keyPath(NWTCPConnection.state), options: [.initial, .new], context: &NETCPSocket.linkContext) + impl.addObserver(self, forKeyPath: #keyPath(NWTCPConnection.hasBetterPath), options: .new, context: &NETCPSocket.linkContext) } func unobserve() { - impl.removeObserver(self, forKeyPath: #keyPath(NWTCPConnection.state), context: &NETCPInterface.linkContext) - impl.removeObserver(self, forKeyPath: #keyPath(NWTCPConnection.hasBetterPath), context: &NETCPInterface.linkContext) + impl.removeObserver(self, forKeyPath: #keyPath(NWTCPConnection.state), context: &NETCPSocket.linkContext) + impl.removeObserver(self, forKeyPath: #keyPath(NWTCPConnection.hasBetterPath), context: &NETCPSocket.linkContext) } func shutdown() { @@ -73,17 +73,17 @@ class NETCPInterface: NSObject, GenericSocket { guard impl.hasBetterPath else { return nil } - return NETCPInterface(impl: NWTCPConnection(upgradeFor: impl)) + return NETCPSocket(impl: NWTCPConnection(upgradeFor: impl)) } func link(withMTU mtu: Int) -> LinkInterface { - return NETCPLinkInterface(impl: impl) + return NETCPLink(impl: impl) } // MARK: Connection KVO (any queue) override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { - guard (context == &NETCPInterface.linkContext) else { + guard (context == &NETCPSocket.linkContext) else { super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context) return } @@ -147,7 +147,7 @@ class NETCPInterface: NSObject, GenericSocket { } } -class NETCPLinkInterface: LinkInterface { +class NETCPLink: LinkInterface { private let impl: NWTCPConnection private let maxPacketSize: Int @@ -219,7 +219,7 @@ class NETCPLinkInterface: LinkInterface { } } -extension NETCPInterface { +extension NETCPSocket { override var description: String { guard let hostEndpoint = impl.endpoint as? NWHostEndpoint else { return impl.endpoint.description diff --git a/TunnelKit/Sources/AppExtension/Transport/NEUDPInterface.swift b/TunnelKit/Sources/AppExtension/Transport/NEUDPInterface.swift index 8f37c05..20814df 100644 --- a/TunnelKit/Sources/AppExtension/Transport/NEUDPInterface.swift +++ b/TunnelKit/Sources/AppExtension/Transport/NEUDPInterface.swift @@ -12,7 +12,7 @@ import SwiftyBeaver private let log = SwiftyBeaver.self -class NEUDPInterface: NSObject, GenericSocket { +class NEUDPSocket: NSObject, GenericSocket { private static var linkContext = 0 private let impl: NWUDPSession @@ -55,13 +55,13 @@ class NEUDPInterface: NSObject, GenericSocket { return } } - impl.addObserver(self, forKeyPath: #keyPath(NWUDPSession.state), options: [.initial, .new], context: &NEUDPInterface.linkContext) - impl.addObserver(self, forKeyPath: #keyPath(NWUDPSession.hasBetterPath), options: .new, context: &NEUDPInterface.linkContext) + impl.addObserver(self, forKeyPath: #keyPath(NWUDPSession.state), options: [.initial, .new], context: &NEUDPSocket.linkContext) + impl.addObserver(self, forKeyPath: #keyPath(NWUDPSession.hasBetterPath), options: .new, context: &NEUDPSocket.linkContext) } func unobserve() { - impl.removeObserver(self, forKeyPath: #keyPath(NWUDPSession.state), context: &NEUDPInterface.linkContext) - impl.removeObserver(self, forKeyPath: #keyPath(NWUDPSession.hasBetterPath), context: &NEUDPInterface.linkContext) + impl.removeObserver(self, forKeyPath: #keyPath(NWUDPSession.state), context: &NEUDPSocket.linkContext) + impl.removeObserver(self, forKeyPath: #keyPath(NWUDPSession.hasBetterPath), context: &NEUDPSocket.linkContext) } func shutdown() { @@ -72,17 +72,17 @@ class NEUDPInterface: NSObject, GenericSocket { guard impl.hasBetterPath else { return nil } - return NEUDPInterface(impl: NWUDPSession(upgradeFor: impl)) + return NEUDPSocket(impl: NWUDPSession(upgradeFor: impl)) } func link(withMTU mtu: Int) -> LinkInterface { - return NEUDPLinkInterface(impl: impl, mtu: mtu) + return NEUDPLink(impl: impl, mtu: mtu) } // MARK: Connection KVO (any queue) override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { - guard (context == &NEUDPInterface.linkContext) else { + guard (context == &NEUDPSocket.linkContext) else { super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context) return } @@ -149,7 +149,7 @@ class NEUDPInterface: NSObject, GenericSocket { } } -class NEUDPLinkInterface: LinkInterface { +class NEUDPLink: LinkInterface { private let impl: NWUDPSession private let maxDatagrams: Int @@ -204,7 +204,7 @@ class NEUDPLinkInterface: LinkInterface { } } -extension NEUDPInterface { +extension NEUDPSocket { override var description: String { guard let hostEndpoint = impl.endpoint as? NWHostEndpoint else { return impl.endpoint.description