Skip to content

Commit

Permalink
Merge branch 'feature/v2ray' into staging-2.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajhilje committed Oct 11, 2023
2 parents 4b1857e + 25094f9 commit 673e9e0
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 8 deletions.
11 changes: 7 additions & 4 deletions IVPNClient/Scenes/ViewControllers/AdvancedViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ class AdvancedViewController: UITableViewController {
@IBAction func selectV2rayProtocol(_ sender: UISegmentedControl) {
let v2rayProtocol = sender.selectedSegmentIndex == 1 ? "tcp" : "quic"
UserDefaults.shared.set(v2rayProtocol, forKey: UserDefaults.Key.v2rayProtocol)
evaluateReconnect(sender: sender as UIView)

if UserDefaults.shared.isV2ray {
evaluateReconnect(sender: sender as UIView)
}
}

@IBAction func toggleAskToReconnect(_ sender: UISwitch) {
Expand Down Expand Up @@ -207,15 +210,15 @@ class AdvancedViewController: UITableViewController {
extension AdvancedViewController {

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.section == 2 && indexPath.row == 0 {
if indexPath.section == 3 && indexPath.row == 0 {
return 60
}

return UITableView.automaticDimension
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 2 && indexPath.row == 1 {
if indexPath.section == 3 && indexPath.row == 1 {
tableView.deselectRow(at: indexPath, animated: true)
sendLogs()
}
Expand All @@ -228,7 +231,7 @@ extension AdvancedViewController {
var urlString = ""
switch section {
case 1:
urlString = "https://www.ivpn.net/"
urlString = "https://www.ivpn.net/knowledgebase/ios/v2ray/"
default:
urlString = "https://www.ivpn.net/knowledgebase/ios/known-issues-with-native-ios-kill-switch/"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ extension ProtocolViewController {

cell.setup(connectionProtocol: connectionProtocol, isSettings: indexPath.section > 0)

if !validateMultiHop(connectionProtocol: connectionProtocol) || !validateCustomDNS(connectionProtocol: connectionProtocol) || !validateAntiTracker(connectionProtocol: connectionProtocol) || !validateSecureDNS(connectionProtocol: connectionProtocol) || !validateKillSwitch(connectionProtocol: connectionProtocol) {
if !validateMultiHop(connectionProtocol: connectionProtocol) || !validateCustomDNS(connectionProtocol: connectionProtocol) || !validateAntiTracker(connectionProtocol: connectionProtocol) || !validateSecureDNS(connectionProtocol: connectionProtocol) || !validateKillSwitch(connectionProtocol: connectionProtocol) || !validateV2ray(connectionProtocol: connectionProtocol) {
cell.protocolLabel.textColor = UIColor.init(named: Theme.ivpnLabel6)
} else {
cell.protocolLabel.textColor = UIColor.init(named: Theme.ivpnLabelPrimary)
Expand Down
63 changes: 60 additions & 3 deletions V2RayControl/ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,55 @@ package v2rayControl

import (
"fmt"
"sync"

core "github.com/v2fly/v2ray-core/v5"
_ "github.com/v2fly/v2ray-core/v5/main/distro/all" // required for loading configuration loaders (we use only "JSON")

// Mandatory features
_ "github.com/v2fly/v2ray-core/v5/app/dispatcher"
_ "github.com/v2fly/v2ray-core/v5/app/proxyman/inbound"
_ "github.com/v2fly/v2ray-core/v5/app/proxyman/outbound"

// Inbound and outbound proxies
_ "github.com/v2fly/v2ray-core/v5/proxy/blackhole"
_ "github.com/v2fly/v2ray-core/v5/proxy/dns"
_ "github.com/v2fly/v2ray-core/v5/proxy/dokodemo"
_ "github.com/v2fly/v2ray-core/v5/proxy/freedom"
_ "github.com/v2fly/v2ray-core/v5/proxy/http"
_ "github.com/v2fly/v2ray-core/v5/proxy/shadowsocks"
_ "github.com/v2fly/v2ray-core/v5/proxy/socks"
_ "github.com/v2fly/v2ray-core/v5/proxy/trojan"
_ "github.com/v2fly/v2ray-core/v5/proxy/vless/inbound"
_ "github.com/v2fly/v2ray-core/v5/proxy/vless/outbound"
_ "github.com/v2fly/v2ray-core/v5/proxy/vmess/inbound"
_ "github.com/v2fly/v2ray-core/v5/proxy/vmess/outbound"

// Transport headers
_ "github.com/v2fly/v2ray-core/v5/transport/internet/headers/http"
_ "github.com/v2fly/v2ray-core/v5/transport/internet/headers/noop"
_ "github.com/v2fly/v2ray-core/v5/transport/internet/headers/srtp"
_ "github.com/v2fly/v2ray-core/v5/transport/internet/headers/tls"
_ "github.com/v2fly/v2ray-core/v5/transport/internet/headers/utp"
_ "github.com/v2fly/v2ray-core/v5/transport/internet/headers/wechat"
_ "github.com/v2fly/v2ray-core/v5/transport/internet/headers/wireguard"

// JSON, TOML, YAML config support
_ "github.com/v2fly/v2ray-core/v5/main/formats"
)

type Instance struct {
server *core.Instance
}

var (
locker sync.Mutex
v2rayInstance *Instance
)

func Start(jsonConfig string) (*Instance, error) {
locker.Lock()
defer locker.Unlock()

config, err := core.LoadConfig("json", []byte(jsonConfig))
if err != nil {
return nil, err
Expand All @@ -27,13 +66,31 @@ func Start(jsonConfig string) (*Instance, error) {
return nil, err
}

return &Instance{server: server}, nil
v2rayInstance = &Instance{server: server}

return v2rayInstance, nil
}

func Stop(instance *Instance) error {
locker.Lock()
defer locker.Unlock()

if instance.server == nil {
return fmt.Errorf("server instance is nil")
}

return instance.server.Close()
if v2rayInstance != nil {
v2rayInstance.server.Close()
v2rayInstance = nil
}

if instance != nil {
err := instance.server.Close()
if err != nil {
return err
}
instance = nil
}

return nil
}

0 comments on commit 673e9e0

Please sign in to comment.