Commit bcceea42 authored by Jose Blaya's avatar Jose Blaya
Browse files

forceDisconnect flag to disconnect the VPN before reconnect if needed

parent d5651dff
......@@ -99,9 +99,10 @@ public protocol VPNProvider: class {
Reconnects to the VPN.
- Parameter delay: The delay in milliseconds after which the reconnection is issue.
- Parameter forceDisconnect: Boolean to indicate if we want to disconnect the VPN before reconnect..
- Parameter callback: Returns `nil` on success.
*/
func reconnect(after delay: Int?, _ callback: SuccessLibraryCallback?)
func reconnect(after delay: Int?, forceDisconnect: Bool, _ callback: SuccessLibraryCallback?)
/**
Submits the debug log associated with the current VPN connection.
......@@ -118,6 +119,12 @@ public protocol VPNProvider: class {
func dataUsage(_ callback: LibraryCallback<Usage>?)
}
public extension VPNProvider {
public func reconnect(after delay: Int?, forceDisconnect: Bool = false, _ callback: SuccessLibraryCallback?) {
return reconnect(after: delay, forceDisconnect: forceDisconnect, callback)
}
}
extension VPNProvider {
/// Shortcut for `(vpnStatus == .connected)`.
......
......@@ -207,7 +207,7 @@ class DefaultVPNProvider: VPNProvider, ConfigurationAccess, DatabaseAccess, Pref
activeProfile.updatePreferences(callback)
}
func reconnect(after delay: Int?, _ callback: SuccessLibraryCallback?) {
func reconnect(after delay: Int?, forceDisconnect: Bool = false, _ callback: SuccessLibraryCallback?) {
guard accessedProviders.accountProvider.isLoggedIn else {
preconditionFailure()
}
......@@ -215,8 +215,21 @@ class DefaultVPNProvider: VPNProvider, ConfigurationAccess, DatabaseAccess, Pref
preconditionFailure()
}
let fallbackDelay = delay ?? accessedConfiguration.vpnReconnectionDelay
Macros.dispatch(after: .milliseconds(fallbackDelay)) {
activeProfile.connect(withConfiguration: self.vpnClientConfiguration(), callback)
if forceDisconnect {
activeProfile.disconnect { (error) in
if let _ = error {
callback?(error)
return
}
Macros.dispatch(after: .milliseconds(fallbackDelay)) {
activeProfile.connect(withConfiguration: self.vpnClientConfiguration(), callback)
}
}
} else {
Macros.dispatch(after: .milliseconds(fallbackDelay)) {
activeProfile.connect(withConfiguration: self.vpnClientConfiguration(), callback)
}
}
}
......
......@@ -111,7 +111,7 @@ public class MockVPNProvider: VPNProvider, ConfigurationAccess, DatabaseAccess {
}
/// :nodoc:
public func reconnect(after delay: Int?, _ callback: SuccessLibraryCallback?) {
public func reconnect(after delay: Int?, forceDisconnect: Bool = false, _ callback: SuccessLibraryCallback?) {
let disconnectionDelay: Int
// if (vpnStatus == .changingServer) {
// disconnectionDelay = 1000
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment