Skip to content

Commit

Permalink
Adjusted callback API
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr. Brandon Wiley committed Jan 11, 2018
1 parent 4c5ffad commit 1bfcf07
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
13 changes: 3 additions & 10 deletions Sources/Transport/PacketTunnelProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,14 @@ import Foundation
import NetworkExtension

extension NEPacketTunnelProvider: PacketTunnelProvider {
public func createTCPConnectionThroughTunnel(to remoteEndpoint: NWEndpoint, enableTLS: Bool, tlsParameters TLSParameters: NWTLSParameters?, delegate: Any?, stateCallback: @escaping (NWTCPConnectionState, Error?) -> Void) -> TCPConnection? {
let tunnel = createTCPConnectionThroughTunnel(to: remoteEndpoint, enableTLS: enableTLS, tlsParameters: TLSParameters, delegate: delegate)
let _ = tunnel.observe(\NWTCPConnection.state) {
(conn, change) in

stateCallback(change.newValue!, nil)
}
return tunnel
public func createTCPConnectionThroughTunnel(to remoteEndpoint: NWEndpoint, enableTLS: Bool, tlsParameters TLSParameters: NWTLSParameters?, delegate: Any?) -> TCPConnection? {
return createTCPConnectionThroughTunnel(to: remoteEndpoint, enableTLS: enableTLS, tlsParameters: TLSParameters, delegate: delegate)
}
}

public protocol PacketTunnelProvider {
func createTCPConnectionThroughTunnel(to remoteEndpoint: NWEndpoint,
enableTLS: Bool,
tlsParameters TLSParameters: NWTLSParameters?,
delegate: Any?,
stateCallback: @escaping (NWTCPConnectionState, Error?) -> Void) -> TCPConnection?
delegate: Any?) -> TCPConnection?
}
32 changes: 32 additions & 0 deletions Sources/Transport/UDPSession.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// UDPSession.swift
// Transport
//
// Created by Brandon Wiley on 1/11/18.
//

import Foundation
import NetworkExtension

extension NWUDPSession: UDPSession {}

public protocol UDPSession {
var state: NWUDPSessionState { get }
var isViable: Bool { get }

var resolvedEndpoint: NWEndpoint? { get }
func tryNextResolvedEndpoint()

func setReadHandler(_ handler: @escaping ([Data]?, Error?) -> Void,
maxDatagrams: Int)
func writeDatagram(_ datagram: Data,
completionHandler: @escaping (Error?) -> Void)
func writeMultipleDatagrams(_ datagramArray: [Data],
completionHandler: @escaping (Error?) -> Void)
var maximumDatagramLength: Int { get }

func cancel()

var hasBetterPath: Bool { get }
init(upgradeFor session: NWUDPSession)
}

0 comments on commit 1bfcf07

Please sign in to comment.