Call cancelTunnelWithError(_:) if a connection fails and won't be retried

This commit is contained in:
Robert Patchett 2019-10-28 14:01:13 +01:00 committed by Davide De Rosa
parent 12ba6f34b7
commit 1cd00f9459
2 changed files with 21 additions and 2 deletions

View File

@ -579,6 +579,18 @@ extension OpenVPNTunnelProvider: OpenVPNSessionDelegate {
public func sessionDidStop(_: OpenVPNSession, shouldReconnect: Bool) { public func sessionDidStop(_: OpenVPNSession, shouldReconnect: Bool) {
log.info("Session did stop") log.info("Session did stop")
stopSession(shouldReconnect: shouldReconnect)
}
/// :nodoc:
public func sessionFailed(_: OpenVPNSession, error: Error) {
log.info("Session failed")
cancelTunnelWithError(error)
stopSession(shouldReconnect: false)
}
private func stopSession(shouldReconnect: Bool) {
isCountingData = false isCountingData = false
refreshDataCount() refreshDataCount()

View File

@ -59,6 +59,11 @@ public protocol OpenVPNSessionDelegate: class {
- Seealso: `OpenVPNSession.reconnect(...)` - Seealso: `OpenVPNSession.reconnect(...)`
*/ */
func sessionDidStop(_: OpenVPNSession, shouldReconnect: Bool) func sessionDidStop(_: OpenVPNSession, shouldReconnect: Bool)
/**
Called after a session failed to start.
*/
func sessionFailed(_: OpenVPNSession, error: Error)
} }
/// Provides methods to set up and maintain an OpenVPN session. /// Provides methods to set up and maintain an OpenVPN session.
@ -1275,13 +1280,15 @@ public class OpenVPNSession: Session {
} }
private func doShutdown(error: Error?) { private func doShutdown(error: Error?) {
stopError = error
if let error = error { if let error = error {
log.error("Trigger shutdown (error: \(error))") log.error("Trigger shutdown (error: \(error))")
delegate?.sessionFailed(self, error: error)
} else { } else {
log.info("Trigger shutdown on request") log.info("Trigger shutdown on request")
delegate?.sessionDidStop(self, shouldReconnect: false)
} }
stopError = error
delegate?.sessionDidStop(self, shouldReconnect: false)
} }
private func doReconnect(error: Error?) { private func doReconnect(error: Error?) {