Skip to content

Commit

Permalink
feat: update ConnectionManager.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajhilje committed Sep 22, 2023
1 parent a61b72f commit 0891041
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
36 changes: 35 additions & 1 deletion IVPNClient/Managers/ConnectionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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())
}
}
}

Expand All @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions IVPNClient/Models/V2Ray/V2RayCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class V2RayCore {

static let shared = V2RayCore()
var instance: V2rayControlInstance?
var isV2ray = true
var reconnectWithV2ray = false

// MARK: - Methods -

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0891041

Please sign in to comment.