Rearrange shutdown code rationally

This commit is contained in:
Davide De Rosa 2018-09-07 22:43:52 +02:00
parent 8adb9871c3
commit 891c72caa1
1 changed files with 15 additions and 4 deletions

View File

@ -422,18 +422,27 @@ extension TunnelKitProvider: GenericSocketDelegate {
log.debug("Link failures so far: \(linkFailures) (max = \(maxLinkFailures))")
}
// neg timeout?
let didTimeoutNegotiation = (proxy.stopError as? SessionError == .negotiationTimeout)
// only try upgrade on network errors
var upgradedSocket: GenericSocket? = nil
if shutdownError as? SessionError == nil {
upgradedSocket = socket.upgraded()
}
// clean up
finishTunnelDisconnection(error: shutdownError)
// treat negotiation timeout as socket timeout, UDP is connection-less
if proxy.stopError as? SessionError == SessionError.negotiationTimeout {
socketShouldChangeProtocol(socket)
if didTimeoutNegotiation {
guard socketShouldChangeProtocol(socket) else {
// disposeTunnel
return
}
}
finishTunnelDisconnection(error: shutdownError)
// reconnect?
if reasserting {
guard (linkFailures < maxLinkFailures) else {
log.debug("Too many link failures (\(linkFailures)), tunnel will die now")
@ -447,6 +456,8 @@ extension TunnelKitProvider: GenericSocketDelegate {
}
return
}
// shut down
disposeTunnel(error: shutdownError)
}