Skip to content

Commit 93c5b1f

Browse files
committed
feat: Add compatability for v2ray core >=v5, Change default downloaded version to v5.37.0
1 parent cf47019 commit 93c5b1f

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

v2ray2proxy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from .base import V2RayCore, V2RayProxy, V2RayPool
66

7-
VERSION = "0.2.5"
7+
VERSION = "0.2.6"
88

99
print(f"v2ray2proxy version {VERSION}")
1010

v2ray2proxy/base.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class V2RayCore:
6767
"""Represents executable of V2Ray core."""
6868

6969
def __init__(self):
70-
self.release_tag_url = os.environ.get("V2RAY_RELASE_TAG_URL") or "https://github.com/v2fly/v2ray-core/releases/download/v4.45.2"
70+
self.release_tag_url = os.environ.get("V2RAY_RELASE_TAG_URL") or "https://github.com/v2fly/v2ray-core/releases/download/v5.37.0"
7171
if os.environ.get("V2RAY_EXECUTABLE_DIR"):
7272
self.executable_dir = os.environ["V2RAY_EXECUTABLE_DIR"]
7373
self.executable = os.path.join(self.executable_dir, "v2ray.exe" if os.name == "nt" else "v2ray")
@@ -81,7 +81,7 @@ def __init__(self):
8181

8282
def _download_executables(self):
8383
"""Download and set up V2Ray executables for the current platform."""
84-
import platform
84+
import platform
8585
import zipfile
8686
import urllib.request
8787
import stat
@@ -94,19 +94,13 @@ def _download_executables(self):
9494

9595
# Determine the executable name based on OS
9696
system = platform.system().lower()
97-
if system == "windows":
98-
executable_name = "v2ray.exe"
99-
ctl_name = "v2ctl.exe"
100-
else:
101-
executable_name = "v2ray"
102-
ctl_name = "v2ctl"
103-
97+
executable_name = "v2ray"
98+
10499
# Check if the executable and v2ctl already exist
105-
v2ray_executable = v2ray_dir / executable_name
106-
v2ctl_executable = v2ray_dir / ctl_name
100+
v2ray_executable = v2ray_dir / (executable_name + (".exe" if system == "windows" else ""))
107101

108-
if v2ray_executable.exists() and v2ctl_executable.exists():
109-
logging.info(f"V2Ray executables already exist at {v2ray_dir}")
102+
if v2ray_executable.exists():
103+
logging.info(f"V2Ray executables found at {v2ray_dir}")
110104
return str(v2ray_dir)
111105

112106
# Determine the current OS and architecture
@@ -212,13 +206,10 @@ def _download_executables(self):
212206
# Verify main executables exist
213207
if not v2ray_executable.exists():
214208
raise RuntimeError(f"Could not find {executable_name} in the extracted files")
215-
216-
if not v2ctl_executable.exists():
217-
logging.warning(f"Could not find {ctl_name} in the extracted files, V2Ray may not function correctly")
218-
209+
219210
# Make the files executable on Unix systems
220211
if system != "windows":
221-
for exe in [v2ray_executable, v2ctl_executable]:
212+
for exe in [v2ray_executable]:
222213
if exe.exists():
223214
exe.chmod(exe.stat().st_mode | stat.S_IEXEC)
224215

@@ -554,7 +545,8 @@ def start(self):
554545
config_path = self.create_config_file()
555546

556547
# Verify executable exists and is accessible
557-
v2ray_exe = V2RayCore().executable
548+
core = V2RayCore()
549+
v2ray_exe = core.executable
558550
if not os.path.isfile(v2ray_exe):
559551
raise FileNotFoundError(f"V2Ray executable not found at {v2ray_exe}")
560552

@@ -563,6 +555,16 @@ def start(self):
563555

564556
# Prepare command and environment
565557
cmd = [v2ray_exe, "-config", config_path]
558+
559+
# Perform a quick check to find out the version of v2ray core
560+
files = os.listdir(core.executable_dir)
561+
if "v2ctl" in files or "v2ctl.exe" in files:
562+
logging.info(f"Detected v2ctl in {core.executable_dir}, assuming v2ray core is <v5.0")
563+
else:
564+
# If v2ctl is not found, assume v2ray core is >=v5.0
565+
# Insert "run" command for compatibility
566+
cmd.insert(1, "run")
567+
566568
logging.info(f"Starting V2Ray with command: {' '.join(cmd)}")
567569

568570
# Set up process creation flags for better process management

0 commit comments

Comments
 (0)