diff --git a/Sources/TunnelKitManager/MockVPN.swift b/Sources/TunnelKitManager/MockVPN.swift index baad68d..1bee04f 100644 --- a/Sources/TunnelKitManager/MockVPN.swift +++ b/Sources/TunnelKitManager/MockVPN.swift @@ -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, diff --git a/Sources/TunnelKitManager/NetworkExtensionVPN.swift b/Sources/TunnelKitManager/NetworkExtensionVPN.swift index 919abe7..12d31ef 100644 --- a/Sources/TunnelKitManager/NetworkExtensionVPN.swift +++ b/Sources/TunnelKitManager/NetworkExtensionVPN.swift @@ -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, diff --git a/Sources/TunnelKitManager/VPN.swift b/Sources/TunnelKitManager/VPN.swift index 60e477e..3991718 100644 --- a/Sources/TunnelKitManager/VPN.swift +++ b/Sources/TunnelKitManager/VPN.swift @@ -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.