diff --git a/IVPNClient/Managers/ConnectionManager.swift b/IVPNClient/Managers/ConnectionManager.swift index 66a4530ca..45d6d80c4 100644 --- a/IVPNClient/Managers/ConnectionManager.swift +++ b/IVPNClient/Managers/ConnectionManager.swift @@ -100,6 +100,14 @@ class ConnectionManager { self.evaluateCloseApp() } } + DispatchQueue.delay(2.5) { + if V2RayCore.shared.isV2ray && !V2RayCore.shared.reconnectWithV2ray { + V2RayCore.shared.reconnectWithV2ray = true + self.reconnect() + } else { + V2RayCore.shared.reconnectWithV2ray = false + } + } } else { self.connected = false } @@ -247,7 +255,22 @@ class ConnectionManager { return } - self.vpnManager.connect(tunnelType: self.settings.connectionProtocol.tunnelType()) + if V2RayCore.shared.isV2ray && V2RayCore.shared.reconnectWithV2ray { + DispatchQueue.global(qos: .userInitiated).async { + let error = V2RayCore.shared.start() + if error != nil { + log(.error, message: error?.localizedDescription ?? "") + } else { + log(.info, message: "V2Ray start OK") + } + } + + DispatchQueue.delay(2) { + self.vpnManager.connect(tunnelType: self.settings.connectionProtocol.tunnelType()) + } + } else { + self.vpnManager.connect(tunnelType: self.settings.connectionProtocol.tunnelType()) + } } } @@ -263,6 +286,17 @@ class ConnectionManager { } } } + + if V2RayCore.shared.isV2ray { + DispatchQueue.global(qos: .userInitiated).async { + let error = V2RayCore.shared.close() + if error != nil { + log(.error, message: error?.localizedDescription ?? "") + } else { + log(.info, message: "V2Ray stop OK") + } + } + } } func installOnDemandRules() { diff --git a/IVPNClient/Models/V2Ray/V2RayCore.swift b/IVPNClient/Models/V2Ray/V2RayCore.swift index 35d1b9a7f..644e850dd 100644 --- a/IVPNClient/Models/V2Ray/V2RayCore.swift +++ b/IVPNClient/Models/V2Ray/V2RayCore.swift @@ -30,6 +30,8 @@ class V2RayCore { static let shared = V2RayCore() var instance: V2rayControlInstance? + var isV2ray = true + var reconnectWithV2ray = false // MARK: - Methods - diff --git a/IVPNClient/Utilities/Extensions/NETunnelProviderProtocol+Ext.swift b/IVPNClient/Utilities/Extensions/NETunnelProviderProtocol+Ext.swift index d78a235f3..1202eaa15 100644 --- a/IVPNClient/Utilities/Extensions/NETunnelProviderProtocol+Ext.swift +++ b/IVPNClient/Utilities/Extensions/NETunnelProviderProtocol+Ext.swift @@ -146,8 +146,7 @@ extension NETunnelProviderProtocol { KeyChain.wgIpv6Host = ipv6.localIP } - // If V2Ray is enabled - if (false) { + if V2RayCore.shared.isV2ray && V2RayCore.shared.reconnectWithV2ray { endpoint = Peer.endpoint(host: Config.v2rayHost, port: Config.v2rayPort) v2raySettings?.inboundIp = v2rayInboundIp v2raySettings?.inboundPort = v2rayInboundPort