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 {
func socketDidTimeout(_ socket: GenericSocket)
func socketShouldChangeProtocol(_ socket: GenericSocket) -> Bool
func socketDidBecomeActive(_ socket: GenericSocket)
func socket(_ socket: GenericSocket, didShutdownWithFailure failure: Bool)

View File

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

View File

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