diff --git a/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider.swift b/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider.swift index 1b85c55..eb9f586 100644 --- a/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider.swift +++ b/TunnelKit/Sources/Protocols/OpenVPN/AppExtension/OpenVPNTunnelProvider.swift @@ -579,6 +579,18 @@ extension OpenVPNTunnelProvider: OpenVPNSessionDelegate { public func sessionDidStop(_: OpenVPNSession, shouldReconnect: Bool) { 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 refreshDataCount() diff --git a/TunnelKit/Sources/Protocols/OpenVPN/OpenVPNSession.swift b/TunnelKit/Sources/Protocols/OpenVPN/OpenVPNSession.swift index d781147..5234336 100644 --- a/TunnelKit/Sources/Protocols/OpenVPN/OpenVPNSession.swift +++ b/TunnelKit/Sources/Protocols/OpenVPN/OpenVPNSession.swift @@ -59,6 +59,11 @@ public protocol OpenVPNSessionDelegate: class { - Seealso: `OpenVPNSession.reconnect(...)` */ 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. @@ -1275,13 +1280,15 @@ public class OpenVPNSession: Session { } private func doShutdown(error: Error?) { + stopError = error + if let error = error { log.error("Trigger shutdown (error: \(error))") + delegate?.sessionFailed(self, error: error) } else { log.info("Trigger shutdown on request") + delegate?.sessionDidStop(self, shouldReconnect: false) } - stopError = error - delegate?.sessionDidStop(self, shouldReconnect: false) } private func doReconnect(error: Error?) {