Take shouldChangeProtocol out of GenericSocket

Behavior is not exactly similar in UDP and TCP.
This commit is contained in:
Davide De Rosa 2018-10-24 09:29:39 +02:00
parent 8b59fe6f4c
commit 91349fd780
3 changed files with 16 additions and 12 deletions

View File

@ -44,8 +44,6 @@ protocol LinkProducer {
protocol GenericSocketDelegate: class { protocol GenericSocketDelegate: class {
func socketDidTimeout(_ socket: GenericSocket) func socketDidTimeout(_ socket: GenericSocket)
func socketShouldChangeProtocol(_ socket: GenericSocket) -> Bool
func socketDidBecomeActive(_ socket: GenericSocket) func socketDidBecomeActive(_ socket: GenericSocket)
func socket(_ socket: GenericSocket, didShutdownWithFailure failure: Bool) func socket(_ socket: GenericSocket, didShutdownWithFailure failure: Bool)

View File

@ -79,7 +79,6 @@ class NETCPSocket: NSObject, GenericSocket {
return return
} }
guard _self.isActive else { guard _self.isActive else {
_ = _self.delegate?.socketShouldChangeProtocol(_self)
_self.delegate?.socketDidTimeout(_self) _self.delegate?.socketDidTimeout(_self)
return return
} }

View File

@ -400,14 +400,14 @@ extension TunnelKitProvider: GenericSocketDelegate {
log.debug("Socket timed out waiting for activity, cancelling...") log.debug("Socket timed out waiting for activity, cancelling...")
reasserting = true reasserting = true
socket.shutdown() socket.shutdown()
}
func socketShouldChangeProtocol(_ socket: GenericSocket) -> Bool { // fallback: TCP connection timeout suggests falling back
guard strategy.tryNextProtocol() else { if let _ = socket as? NETCPSocket {
disposeTunnel(error: ProviderError.exhaustedProtocols) guard tryNextProtocol() else {
return false // disposeTunnel
return
}
} }
return true
} }
func socketDidBecomeActive(_ socket: GenericSocket) { func socketDidBecomeActive(_ socket: GenericSocket) {
@ -448,9 +448,9 @@ extension TunnelKitProvider: GenericSocketDelegate {
// clean up // clean up
finishTunnelDisconnection(error: shutdownError) finishTunnelDisconnection(error: shutdownError)
// treat negotiation timeout as socket timeout, UDP is connection-less // fallback: UDP is connection-less, treat negotiation timeout as socket timeout
if didTimeoutNegotiation { if didTimeoutNegotiation {
guard socketShouldChangeProtocol(socket) else { guard tryNextProtocol() else {
// disposeTunnel // disposeTunnel
return return
} }
@ -574,6 +574,13 @@ extension TunnelKitProvider: SessionProxyDelegate {
} }
extension TunnelKitProvider { extension TunnelKitProvider {
private func tryNextProtocol() -> Bool {
guard strategy.tryNextProtocol() else {
disposeTunnel(error: ProviderError.exhaustedProtocols)
return false
}
return true
}
// MARK: Logging // MARK: Logging