Shut down on server-initiated HARD_RESET

Session is stale and not recoverable (lame duck).
This commit is contained in:
Davide De Rosa 2018-10-24 11:02:08 +02:00
parent 0b79ce4194
commit b1a79d6451
3 changed files with 12 additions and 8 deletions

View File

@ -652,7 +652,7 @@ extension TunnelKitProvider {
}
} else if let se = error as? SessionError {
switch se {
case .negotiationTimeout, .pingTimeout:
case .negotiationTimeout, .pingTimeout, .staleSession:
return .timeout
case .badCredentials:

View File

@ -67,6 +67,9 @@ public enum SessionError: String, Error {
/// The server couldn't ping back before timeout.
case pingTimeout
/// The session reached a stale state and can't be recovered.
case staleSession
}
extension Error {

View File

@ -326,12 +326,6 @@ public class SessionProxy {
private func start() {
loopLink()
hardReset()
guard !keys.isEmpty else {
fatalError("Main loop must follow hard reset, keys are empty!")
}
loopNegotiation()
}
private func loopNegotiation() {
@ -466,7 +460,10 @@ public class SessionProxy {
// deferStop(.shutdown, e)
// return
}
if (code == .softResetV1) && (negotiationKey.state != .softReset) {
if (code == .hardResetServerV2) && (negotiationKey.state != .hardReset) {
deferStop(.shutdown, SessionError.staleSession)
return
} else if (code == .softResetV1) && (negotiationKey.state != .softReset) {
softReset(isServerInitiated: true)
}
@ -560,6 +557,10 @@ public class SessionProxy {
let payload = hardResetPayload() ?? Data()
negotiationKey.state = .hardReset
guard !keys.isEmpty else {
fatalError("Main loop must follow hard reset, keys are empty!")
}
loopNegotiation()
enqueueControlPackets(code: .hardResetClientV2, key: UInt8(negotiationKeyIdx), payload: payload)
}