zapret-kvn/xray_fluent/application/protocol_core.py
loop-uh 64f4ee714e Xray owns VMess and Trojan: sidecar path, XHTTP, TLS and masking follow
Owner decision 2026-11-16: VLESS, VMess and Trojan run on the official Xray core;
sing-box stays the gasket (TUN, routing, DNS, protected sockets) and only keeps
Shadowsocks, SOCKS, HTTP and the rest. sing-box had no XHTTP transport for VMess and
Trojan and only approximated the other transports, while Xray runs any of its protocols
over any transport.

- protocol_core: VMess/Trojan in Xray's JSON shape go to Xray; a raw sing-box JSON
  outbound pasted by the user (type key) stays with sing-box.
- link_parser: xray_only for VMess/Trojan (allowInsecure without a pin is dropped like
  VLESS, Xray 26.x has none), TLS validation for all three, VMess alterId > 0 refused,
  vmess:// carries XHTTP mode and extra, WebSocket/HTTPUpgrade drop h2/h3 from alpn.
- masking: VMess/Trojan are Xray servers (shape, presets); sing-box fragment keeps
  AnyTLS, HTTP, ShadowTLS.
- config_builder: dead VMess/Trojan/transport conversion removed.
- tests flipped to Shadowsocks where they need a sing-box server; new
  tests/test_xray_owns_vmess_trojan.py; docs updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 09:44:27 -05:00

32 lines
1.2 KiB
Python

"""Fixed protocol ownership shared by planning, pools and runtime modules."""
from enum import Enum
class ProtocolCore(str, Enum):
SINGBOX = "sing-box"
XRAY = "xray"
HYSTERIA = "hysteria"
AMNEZIA = "amnezia"
# Protocols whose complete native implementation is Xray-core (VLESS is handled first, by name).
XRAY_NATIVE_PROTOCOLS = frozenset({"vmess", "trojan"})
def protocol_core(node) -> ProtocolCore:
outbound = node.outbound or {}
protocol = str(outbound.get("protocol", outbound.get("type", node.scheme))).lower()
if protocol == "vless":
return ProtocolCore.XRAY
# VMess and Trojan are native Xray protocols (owner decision 2026-11-16): sing-box has no XHTTP
# transport for them and only approximates the rest. A node pasted as a raw sing-box outbound
# (`type` key, no Xray `protocol` key) is the user's own sing-box JSON and stays with sing-box.
if protocol in XRAY_NATIVE_PROTOCOLS and "protocol" in outbound:
return ProtocolCore.XRAY
if protocol in {"wireguard", "awg"}:
return ProtocolCore.AMNEZIA
# The official v2 client cannot consume Hysteria v1 configurations.
if protocol in {"hy2", "hysteria2"}:
return ProtocolCore.HYSTERIA
return ProtocolCore.SINGBOX