Update zlib to 1.4 and pick wire compression at runtime #9

Merged
yuanyuanxiang merged 2 commits from review/zlib-runtime-compress into main 2026-11-24 09:39:59 +00:00
Owner

概要

单个提交 0e20e0b — Feature: update zlib to 1.4 and pick wire compression at runtime

变更内容

  • zlib 1.3.2 → 1.4:头文件与两个静态库(x86/x64)同步更新,版本字符串已核对一致(deflate/inflate 1.4)
  • 运行期选择线缆压缩:删除编译期 USING_ZLIB 开关,Windows 客户端同时链接 zlib+zstd;每个连接实例构造时读 settings\compress(默认 zstd,"zlib" 大小写不敏感),子连接跟随主链路
  • 远程切换:在线列表右键 → 实验功能 → 线缆压缩 ZSTD/ZLIB;仅对声明 CLIENT_CAP_COMPRESS_SWITCH(0x40000)的主机下发 COMMAND_SET_COMPRESS(181);客户端写配置后置 S_CLIENT_UPDATE 重建连接对象(StartClientApp 重进 → NewNetClient 新实例重读配置),约 2 秒生效无需重启进程
  • 服务端首包自动识别(既有逻辑):先 zstd、失败回退 zlib 并定型,无需握手;在线信息 tooltip 追加 [ZSTD]/[ZLIB]/[NONE] 标注,不改 FormatL 格式串(保多语言 key)
  • 缓冲区修复(两端):compressBound(n) 替换 1.001n+12——后者对 <~1KB 的包少 1 字节,Z_BUF_ERROR 静默丢小包(心跳 ACK、控制命令)

兼容性

  • 默认仍 zstd,线缆行为与旧版一致;LOGIN_INFOR 结构大小未变
  • 老客户端不声明能力位 → 服务端菜单过滤并提示,不盲发;老服务端忽略新能力位
  • POSIX 客户端 CLIENT_HAS_ZLIB=0 恒走 zstd,不受影响

审查状态

静态审查通过,无阻塞问题。非阻塞观察:

  1. COMMAND_SET_COMPRESS 无 IsShared() 守卫(SET_PROTO 有):分享实例也会写进程级配置键,主实例下次重连继承该模式;服务端按连接自动识别,功能上不坏
  2. if (m_cfg) 为空时仍重启但不落盘(理论路径,m_cfg 构造时必建)

测试计划

  • 静态审查(重启链路、配置读写同库、能力位/命令号无冲突、zlib 头/库版本一致)
  • 提交说明已验证:两种模式连接并收到 MasterSettings;菜单来回切换重连;Debug/Release x64、Release x86、ServerDll、server 构建通过
  • 分享实例场景下的切换行为实测(观察项 1)
## 概要 单个提交 `0e20e0b` — Feature: update zlib to 1.4 and pick wire compression at runtime ### 变更内容 - **zlib 1.3.2 → 1.4**:头文件与两个静态库(x86/x64)同步更新,版本字符串已核对一致(deflate/inflate 1.4) - **运行期选择线缆压缩**:删除编译期 `USING_ZLIB` 开关,Windows 客户端同时链接 zlib+zstd;每个连接实例构造时读 `settings\compress`(默认 zstd,"zlib" 大小写不敏感),子连接跟随主链路 - **远程切换**:在线列表右键 → 实验功能 → 线缆压缩 ZSTD/ZLIB;仅对声明 `CLIENT_CAP_COMPRESS_SWITCH`(0x40000)的主机下发 `COMMAND_SET_COMPRESS`(181);客户端写配置后置 `S_CLIENT_UPDATE` 重建连接对象(StartClientApp 重进 → NewNetClient 新实例重读配置),约 2 秒生效无需重启进程 - **服务端首包自动识别**(既有逻辑):先 zstd、失败回退 zlib 并定型,无需握手;在线信息 tooltip 追加 [ZSTD]/[ZLIB]/[NONE] 标注,不改 FormatL 格式串(保多语言 key) - **缓冲区修复(两端)**:`compressBound(n)` 替换 `1.001n+12`——后者对 <~1KB 的包少 1 字节,`Z_BUF_ERROR` 静默丢小包(心跳 ACK、控制命令) ### 兼容性 - 默认仍 zstd,线缆行为与旧版一致;`LOGIN_INFOR` 结构大小未变 - 老客户端不声明能力位 → 服务端菜单过滤并提示,不盲发;老服务端忽略新能力位 - POSIX 客户端 `CLIENT_HAS_ZLIB=0` 恒走 zstd,不受影响 ## 审查状态 静态审查通过,无阻塞问题。非阻塞观察: 1. `COMMAND_SET_COMPRESS` 无 `IsShared()` 守卫(SET_PROTO 有):分享实例也会写进程级配置键,主实例下次重连继承该模式;服务端按连接自动识别,功能上不坏 2. `if (m_cfg)` 为空时仍重启但不落盘(理论路径,m_cfg 构造时必建) ## 测试计划 - [x] 静态审查(重启链路、配置读写同库、能力位/命令号无冲突、zlib 头/库版本一致) - [x] 提交说明已验证:两种模式连接并收到 MasterSettings;菜单来回切换重连;Debug/Release x64、Release x86、ServerDll、server 构建通过 - [ ] 分享实例场景下的切换行为实测(观察项 1)
yuanyuanxiang added 1 commit 2026-11-23 17:03:09 +00:00
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
yuanyuanxiang added 1 commit 2026-11-24 09:38:01 +00:00
Switching wire compression used to set g_bExit = S_CLIENT_UPDATE and
disconnect. Standalone clients restart fine, but the in-process test
client (ServerDll loaded with MemoryModule) only restarts AutoRun on
S_SERVER_EXIT; S_CLIENT_UPDATE made TestRun return and AutoRun exit, so
the host went offline for good and the "Run Test Program" menu stayed
disabled.

The command handler now disconnects and calls
IOCPClient::SetWireCompression() on the existing connection object.
The reconnect loop reuses it with the new mode; sub-connections are
rebuilt from the saved config after the main link reconnects. g_bExit
is no longer touched.

The experimental menu gains two 16x16 icons (blue Z for zstd, orange L
for zlib) and grays the algorithm the selected hosts already use
(all-zstd grays ZSTD, all-zlib grays ZLIB, mixed leaves both enabled,
unsupported clients gray both). The new strings are translated in the
en_US, de_DE and zh_TW packs (the German pack also gained the missing
"Experimental" group title).

Verified: with an isolated Debug server, the in-process test client
switches zstd -> zlib -> zstd, reconnects in about 3 s each time and
keeps receiving MasterSettings; the menu reports the expected gray
state and icons in a captured screenshot.

Co-Authored-By: deepseek-flash
yuanyuanxiang merged commit e6a3255a2b into main 2026-11-24 09:39:59 +00:00
yuanyuanxiang deleted branch review/zlib-runtime-compress 2026-11-24 09:39:59 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: yuanyuanxiang/SimpleRemoter#9