Reconnect with current manager and configuration

This commit is contained in:
Davide De Rosa 2022-07-23 09:58:48 +02:00
parent 36ed23ccc4
commit e2aaffc06f
3 changed files with 26 additions and 1 deletions

View File

@ -47,6 +47,10 @@ public class MockVPN: VPN {
notifyStatus(.disconnected) notifyStatus(.disconnected)
} }
public func reconnect(after: DispatchTimeInterval) async throws {
notifyStatus(.connected)
}
public func reconnect( public func reconnect(
_ tunnelBundleIdentifier: String, _ tunnelBundleIdentifier: String,
configuration: NetworkExtensionConfiguration, configuration: NetworkExtensionConfiguration,

View File

@ -68,6 +68,18 @@ public class NetworkExtensionVPN: VPN {
) )
} }
public func reconnect(after: DispatchTimeInterval) async throws {
let managers = try await lookupAll()
guard let manager = managers.first else {
return
}
if manager.connection.status != .disconnected {
manager.connection.stopVPNTunnel()
try await Task.sleep(nanoseconds: after.nanoseconds)
}
try manager.connection.startVPNTunnel()
}
public func reconnect( public func reconnect(
_ tunnelBundleIdentifier: String, _ tunnelBundleIdentifier: String,
configuration: NetworkExtensionConfiguration, configuration: NetworkExtensionConfiguration,

View File

@ -50,7 +50,16 @@ public protocol VPN {
) async throws ) async throws
/** /**
Reconnects to the VPN. Reconnects to the VPN with current configuration.
- Parameter after: The reconnection delay.
**/
func reconnect(
after: DispatchTimeInterval
) async throws
/**
Reconnects to the VPN installing a new configuration.
- Parameter tunnelBundleIdentifier: The bundle identifier of the tunnel extension. - Parameter tunnelBundleIdentifier: The bundle identifier of the tunnel extension.
- Parameter configuration: The configuration to install. - Parameter configuration: The configuration to install.