diff --git a/core/services/encrypted_proxy/hysteria_service.py b/core/services/encrypted_proxy/hysteria_service.py index 1a93d8e..855091f 100644 --- a/core/services/encrypted_proxy/hysteria_service.py +++ b/core/services/encrypted_proxy/hysteria_service.py @@ -1,20 +1,18 @@ from pathlib import Path +from core.Constants import Constants from core.utils.encrypted_proxy.net import get_real_ip, verify_ip from core.utils.encrypted_proxy.singbox import SingboxRunner import socket - def _resolve(host: str) -> str: return socket.gethostbyname(host) - def _get_hy2_domain(server_host: str) -> str: parts = server_host.split(".", 1) if len(parts) == 2: return f"hy2.{parts[1]}" return server_host - def build_hysteria_config(username: str, password: str, server_host: str, socks5_port: int) -> dict: hy2_domain = _get_hy2_domain(server_host) @@ -73,17 +71,14 @@ def build_hysteria_config(username: str, password: str, }, } - def enable_hysteria(username: str, password: str, server_host: str, config_dir: Path, socks5_port: int, observer=None) -> bool: real_ip = get_real_ip() runner = SingboxRunner() runner.stop() - - config_path = config_dir / f"{username}-sing-box.json" + config_path = Path(Constants.HV_DATA_HOME) / f"{username}-sing-box.json" config = build_hysteria_config(username, password, server_host, socks5_port) - try: runner.write_config(config_path, config) ok = runner.start(config_path) @@ -91,12 +86,10 @@ def enable_hysteria(username: str, password: str, server_host: str, if observer: observer.notify("error", str(e)) return False - if not ok: if observer: observer.notify("error", "sing-box not active after start") return False - proxy_ip = verify_ip(socks5_port) if observer: observer.notify("connected", { @@ -106,9 +99,8 @@ def enable_hysteria(username: str, password: str, server_host: str, }) return True - def disable_hysteria(observer=None) -> bool: SingboxRunner().stop() if observer: observer.notify("disconnected", {}) - return True + return True \ No newline at end of file