Feature: update zlib to 1.4 and pick wire compression at runtime

The client selected zlib or zstd for the wire protocol at compile time
(USING_ZLIB), so changing the mode required a rebuild, and the vendored
zlib was still 1.3.2.

Vendored zlib is now 1.4 (headers and both static libs rebuilt from the
upstream source root). The client links zlib and zstd together and reads
settings\compress from its own registry key when a connection is
created: "zlib" selects zlib, anything else keeps the zstd default.
Every connection reads it once, so sub-connections follow the main link.

The online list context menu gains "Experimental -> Wire compression:
ZSTD / ZLIB". It sends COMMAND_SET_COMPRESS (181) only to hosts that
declare CLIENT_CAP_COMPRESS_SWITCH; the client persists the choice and
restarts its connection thread, so the new mode applies in about two
seconds without restarting the process. The online-info tooltip now
marks the negotiated algorithm with [ZSTD] / [ZLIB] / [NONE].

Also fixes zlib buffer sizing on both ends: 1.001n+12 is one byte short
of compressBound for packets under about 1 KB, which silently dropped
small commands.

Verified: both modes connect and receive MasterSettings; menu switching
to zlib and back reconnects in each mode; Debug/Release x64, Release
x86, ServerDll and server builds pass.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-23 17:46:36 +01:00
1 parent 340fb20518
commit 0e20e0bbdb
20 files changed
+303 -84

No files matched your search

+49 -1
View File
@@ -1177,6 +1177,8 @@ BEGIN_MESSAGE_MAP(CMy2015RemoteDlg, CDialogEx)
ON_COMMAND(ID_EXPERIMENT_DRAWING_BOARD, &CMy2015RemoteDlg::OnExperimentDrawingBoard)
ON_COMMAND(ID_EXPERIMENT_TLS_ENABLE, &CMy2015RemoteDlg::OnExperimentTlsEnable)
ON_COMMAND(ID_EXPERIMENT_TLS_DISABLE, &CMy2015RemoteDlg::OnExperimentTlsDisable)
ON_COMMAND(ID_EXPERIMENT_COMPRESS_ZSTD, &CMy2015RemoteDlg::OnExperimentCompressZstd)
ON_COMMAND(ID_EXPERIMENT_COMPRESS_ZLIB, &CMy2015RemoteDlg::OnExperimentCompressZlib)
ON_COMMAND(ID_PROTO_SWITCH_TCP, &CMy2015RemoteDlg::OnProtoSwitchTcp)
ON_COMMAND(ID_PROTO_SWITCH_WS, &CMy2015RemoteDlg::OnProtoSwitchWs)
ON_COMMAND(ID_PROTO_SWITCH_WSS, &CMy2015RemoteDlg::OnProtoSwitchWss)
@@ -4979,6 +4981,13 @@ void CMy2015RemoteDlg::OnNMRClickOnline(NMHDR *pNMHDR, LRESULT *pResult)
pExperimentMenu->DeleteMenu(ID_EXPERIMENT_TLS_ENABLE, MF_BYCOMMAND);
if (SHOULD_HIDE_CTX(HIDE_CTX_EXPERIMENT_TLS_DISABLE, CF_EXPERIMENT_TLS_DISABLE))
pExperimentMenu->DeleteMenu(ID_EXPERIMENT_TLS_DISABLE, MF_BYCOMMAND);
// 线缆压缩切换:放在实验功能末尾。仅当该组仍有可见项时追加——被功能位整组
// 隐藏时既不泄露,也不影响下面「空组摘除」的逻辑。
if (!IsPopupEmptyOfItems(pExperimentMenu)) {
pExperimentMenu->AppendMenu(MF_SEPARATOR);
pExperimentMenu->AppendMenuL(MF_STRING, ID_EXPERIMENT_COMPRESS_ZSTD, "线缆压缩:ZSTD");
pExperimentMenu->AppendMenuL(MF_STRING, ID_EXPERIMENT_COMPRESS_ZLIB, "线缆压缩:ZLIB");
}
for (UINT i = 0; i < SubMenu->GetMenuItemCount(); i++) {
if (SubMenu->GetSubMenu(i) == pExperimentMenu) {
protoInsertPos = (int)i + 1;
@@ -5326,6 +5335,36 @@ void CMy2015RemoteDlg::OnExperimentTlsDisable()
SendSelectedCommand(&bToken, sizeof(BYTE));
}
// ---- 线缆压缩切换(在线列表右键 → 实验功能 → 线缆压缩:ZSTD / ZLIB)----
void CMy2015RemoteDlg::OnExperimentCompressZstd() { SwitchSelectedCompression("zstd"); }
void CMy2015RemoteDlg::OnExperimentCompressZlib() { SwitchSelectedCompression("zlib"); }
VOID CMy2015RemoteDlg::SwitchSelectedCompression(const char* mode)
{
// 老客户端不认识 COMMAND_SET_COMPRESS,收到只会丢弃;先按能力位过滤。
int selected = 0, unsupported = 0;
EnterCriticalSection(&m_cs);
for (context* ctx : ResolveCommandTargets()) {
if (!ctx->IsLogin()) continue;
++selected;
if (!ctx->SupportsCompressSwitch()) ++unsupported;
}
LeaveCriticalSection(&m_cs);
if (selected == 0) return;
if (unsupported > 0) {
MessageBoxL(_T("选中的主机里有客户端版本不支持线缆压缩切换(需要新版 Windows 客户端)"),
_T("提示"), MB_ICONWARNING);
return;
}
// 载荷 [cmd]["zstd"|"zlib"]。客户端写入 settings\compress 后重启 StartClient 线程,
// 新连接按新模式重连;服务端按每个连接的首包自动识别算法,不影响其它主机。
std::string pkt(1, (char)COMMAND_SET_COMPRESS);
pkt += mode;
Mprintf("[compress-switch] send %s to %d host(s)\n", mode, selected);
SendSelectedCommand((PBYTE)&pkt[0], (ULONG)pkt.size());
}
// ---- 协议切换(在线列表右键 → 协议切换 → 直连 TCP / WS / WSS)----
//
// 服务端只负责下发目标入口和协议:客户端把入口写进本机配置后断开重连,在线升级换 DLL
@@ -10357,6 +10396,15 @@ void CMy2015RemoteDlg::OnListClick(NMHDR* pNMHDR, LRESULT* pResult)
{FLAG_WINOS, "WinOS"}, {FLAG_UNKNOWN, "Unknown"}, {FLAG_SHINE, "Shine"},
{FLAG_FUCK, "FUCK"}, {FLAG_HELLO, "Hello"}, {FLAG_HELL, "HELL"},
};
// 压缩算法标注:服务端按连接自动识别(首个压缩包解压时定型),追加在加密协议后面。
// 不改 FormatL 的格式串,避免影响多语言翻译 key。
CString typeText = typMap[type].c_str();
switch (ctx->GetCompressMethod()) {
case COMPRESS_ZSTD: typeText += " [ZSTD]"; break;
case COMPRESS_ZLIB: typeText += " [ZLIB]"; break;
case COMPRESS_NONE: typeText += " [NONE]"; break;
default: break; // COMPRESS_UNKNOWN:不标注
}
CString processInfo;
if (!res[RES_PID].IsEmpty() || !res[RES_FILESIZE].IsEmpty()) {
processInfo.FormatL("\r\n进程 PID: %s %s", res[RES_PID].IsEmpty() ? "" : res[RES_PID], res[RES_FILESIZE].IsEmpty() ? "" : res[RES_FILESIZE]);
@@ -10377,7 +10425,7 @@ void CMy2015RemoteDlg::OnListClick(NMHDR* pNMHDR, LRESULT* pResult)
res[RES_PROGRAM_BITS].IsEmpty() ? "" : res[RES_PROGRAM_BITS] + _L(" 位 "), res[RES_FILE_PATH], res[RES_EXE_VERSION], processInfo,
res[RES_SYSTEM_BITS], res[RES_SYSTEM_CPU], res[RES_SYSTEM_MEM], res[RES_RESOLUTION], startTime, expired.c_str(),
res[RES_USERNAME], res[RES_ISADMIN] == "1" ? _L("[管理员]") : res[RES_ISADMIN].IsEmpty() ? "" : _L("[非管理员]"), elapsed,
ctx->GetProtocol().c_str(), ctx->GetServerPort(), typMap[type].c_str(), ctx->GetMasterID().c_str(), res[RES_CLIENT_ID]);
ctx->GetProtocol().c_str(), ctx->GetServerPort(), typeText.GetString(), ctx->GetMasterID().c_str(), res[RES_CLIENT_ID]);
// 地理信息只在加载了本地 IP 库(QQWry/ip2region)时才查询并展示。
// 未装库时 m_IPConverter 是网络版 GetGeoLocation(同步外网 HTTP,可达数秒),
// 且结果不会被显示——跳过可消除双击浮窗的弹出延时。