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