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

+20 -3
View File
@@ -108,6 +108,14 @@ BOOL CSettingDlg::OnInitDialog()
SetDlgItemText(IDC_GROUP_SET_DESKTOP, _TR("桌面管理"));
SetDlgItemText(IDC_GROUP_SET_PARAMS, _TR("参数设置"));
// UDP 协议参数与监听端口是按顺序一一对应的,提示行放不下说明,用悬浮提示讲格式。
if (m_tip.Create(this)) {
m_tip.Activate(TRUE);
m_tip.AddTool(&m_EditUdpOption,
_TR("UDP 协议参数与监听端口按顺序一一对应:例如监听端口填 6543;7543,这里就填 UDP;KCP。"));
m_tip.SetMaxTipWidth(480);
}
// 设置对话框标题和控件文本(解决英语系统乱码问题)
SetWindowText(_TR("设置"));
SetDlgItemText(IDOK, _TR("确定"));
@@ -151,9 +159,10 @@ BOOL CSettingDlg::OnInitDialog()
}
m_sOriginalMaster = m_sPublicIP; // 缓存原始值,用于检测修改
std::string nPort = THIS_CFG.GetStr("settings", "ghost", "6543");
std::map<std::string, std::string> udpMap = { {"UDP", "UDP"}, {"KCP", "KCP"} };
std::string method = THIS_CFG.GetStr("settings", "UDPOption", "UDP").c_str();
m_sUdpOption = udpMap.find(method) == udpMap.end() ? "UDP" : udpMap[method].c_str();
// UDPOption 与 ghost 是平行的分号列表("UDP;KCP" 对应 "6543;7543")。这里原样
// 显示、原样写回;不要做"UDP/KCP 二选一"的归一化,否则打开设置点确定就会把
// KCP 端口条目抹掉(本次新增的多端口实验传输依赖它)。
m_sUdpOption = THIS_CFG.GetStr("settings", "UDPOption", "UDP").c_str();
int DXGI = THIS_CFG.GetInt("settings", "DXGI");
@@ -361,3 +370,11 @@ void CSettingDlg::OnEnKillfocusEditPublicIp()
}
}
}
BOOL CSettingDlg::PreTranslateMessage(MSG* pMsg)
{
if (m_tip.GetSafeHwnd()) {
m_tip.RelayEvent(pMsg);
}
return __super::PreTranslateMessage(pMsg);
}