Feature: switch hosts to the experimental UDP and KCP transports

The switch only offered direct TCP, WS and WSS; UDP and KCP are now
experimental menu entries, and the radio item follows the real transport.

The server maps ghost/UDPOption to real listeners (a "UDP;KCP" setup
used to collapse to one UDP port). A switch sends the master address and
that transport's port, refused behind an upper-level FRP. The client
persists the override, recreates its connection object when the transport
changes, and disconnects an unacknowledged switch after 60 s so the 300 s
revert can run. TCP/WS/WSS behaviour is unchanged.

Reconnecting a KCP client reused the same object: a fresh std::thread
over the old one aborted the process and leaked the ikcp session;
ConnectServer now joins the update thread and releases the session first,
and the UDP one also clears the stale login-ack flag. KCP contexts no
longer touch the shared listener socket: CancelIO is a no-op, Disconnect
looks up by IP:port and defers deletion behind the receive thread's
reference, COMMAND_BYE leaves the socket alone, and Disconnect stays
silent like UDP's. Oversized messages are delivered in chunks.

A datagram host has no disconnect event, so a new login for the same id
was parked as standby for up to 120 s while the client gave up after
60 s; a UDP/KCP or different-transport login now replaces it immediately.

The new labels, prompts and settings hint are translated in the
en_US/de_DE/zh_TW packs; UDPOption also accepts 0/1 in port order.
Verified: Debug build; switch directions plus KCP delete/reconnect/file-transfer tested.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-29 20:34:08 +01:00
1 parent 914553ab4e
commit dfac2b5179
21 files changed
+534 -91

No files matched your search

+6 -1
View File
@@ -153,6 +153,7 @@ inline int isValid_10s()
#define CLIENT_CAP_PRIVACY_OVERLAY 0x10000 // 屏幕子连接处理 COMMAND_SCREEN_BLOCK_INPUT / COMMAND_SCREEN_BLANK(Android 用无障碍全屏 overlay 实现;Windows 一直支持锁定键鼠但不声明这个位)
#define CLIENT_CAP_PROCESS 0x20000 // 主连接处理 COMMAND_SYSTEM(系统子连接:COMMAND_PSLIST / COMMAND_KILLPROCESS;Linux/macOS 声明,Windows 一直支持但不声明)
#define CLIENT_CAP_COMPRESS_SWITCH 0x40000 // 支持服务端远程切换线缆压缩(COMMAND_SET_COMPRESS,仅 Windows)
#define CLIENT_CAP_PROTO_SWITCH_EXP 0x80000 // 支持切到实验传输 UDP/KCP(COMMAND_SET_PROTO 携带 PROTO_UDP/KCP,仅新版 Windows)
// TOKEN_WEBCAM_DIB 帧头里的 fccHandler(第 3~6 字节):Android 客户端直接发 JPEG,
// 服务端识别这个 FOURCC 后用 turbojpeg 解码,不依赖系统安装 VFW 编解码器。
@@ -444,7 +445,9 @@ enum {
// 信任锚时附带——客户端写入后重建 TLS 上下文,随后按新入口重连即走 WSS。
#pragma pack(push, 1)
struct ProtoSwitchPacket {
uint8_t proto; // PROTO_TCP / PROTO_WS / PROTO_WSS
uint8_t proto; // PROTO_TCP / PROTO_WS / PROTO_WSS / PROTO_UDP / PROTO_KCP
// UDP/KCP 是实验协议:host=主控地址、port=该传输的监听端口
//(ghost/UDPOption 平行列表里对应位),不需要反代入口。
char host[100]; // 反向代理域名(SNI / Host 头),空 = 还原
char port[8]; // 反向代理端口,空 = 还原
uint32_t certLen; // 随后附带的信任锚 PEM 字节数(0 = 不下发)
@@ -1343,6 +1346,8 @@ typedef struct LOGIN_INFOR {
caps |= CLIENT_CAP_C2C_PATHS;
// 协议切换(COMMAND_SET_PROTO)只有 Windows 客户端实现了命令处理与入口持久化。
caps |= CLIENT_CAP_PROTO_SWITCH;
// 实验传输切换(UDP/KCP):同一条命令,新增接受 PROTO_UDP/PROTO_KCP。
caps |= CLIENT_CAP_PROTO_SWITCH_EXP;
// 线缆压缩切换(COMMAND_SET_COMPRESS):Windows 客户端同时携带 zlib/zstd。
caps |= CLIENT_CAP_COMPRESS_SWITCH;
// 多显示器远程控制:抓整个虚拟桌面,截图与注入共用同一坐标系。