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)
}
public func reconnect(after: DispatchTimeInterval) async throws {
notifyStatus(.connected)
}
public func reconnect(
_ tunnelBundleIdentifier: String,
configuration: NetworkExtensionConfiguration,

View File

@ -67,6 +67,18 @@ public class NetworkExtensionVPN: VPN {
extra: extra
)
}
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(
_ tunnelBundleIdentifier: String,

View File

@ -50,7 +50,16 @@ public protocol VPN {
) 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 configuration: The configuration to install.