Fix: keep zlib compression and host sharing mutually exclusive
The wire compression mode is a machine-wide setting (settings\compress), so a zlib switch is inherited by share instances and by the sub-connections they open later. A share peer that only speaks zstd (the Go server has no zlib path) then loses the link on the next connect. A shared instance could also rewrite the host's setting on behalf of the sharing master. The client now refuses COMMAND_SET_COMPRESS on a non-main instance, refuses a switch to zlib while share_list is non-empty (zstd stays allowed), and refuses a new share while the configured mode is zlib. The share check reads settings\compress rather than the current connection's m_useZlib: parallel-mode links can diverge from the machine-wide value the new share instance will read. Refusals answer with a ClientMsg so the operator sees why. Verified: Debug x64 ghost and Release x64 ServerDll build with only the pre-existing warnings; review flagged the live-flag divergence, fixed. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
c9a18856e5
commit
1bd7fa5b2d
3 files changed
+40
No files matched your search
@@ -1154,6 +1154,23 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
Mprintf("[compress-switch] unsupported mode '%s', ignored\n", mode.c_str());
|
||||
break;
|
||||
}
|
||||
// 分享实例不能改写整机的线缆压缩配置:它跑的是同一个 OnReceive,放行的话
|
||||
// 分享目标主控就能改掉主机连归属方的模式,主机下次重启会按别家的选择连回来。
|
||||
if (!m_ClientApp || !m_ClientApp->IsMainInstance()) {
|
||||
Mprintf("[compress-switch] refused: not the main instance\n");
|
||||
ClientMsg msg("线缆压缩", "Compression switch refused: only the owning master may switch");
|
||||
SendData((LPBYTE)&msg, sizeof(msg));
|
||||
break;
|
||||
}
|
||||
// 存在分享链路时只允许切回 zstd。压缩模式是整机配置(settings\compress),
|
||||
// 分享实例及后续子连接都会继承;对端若只支持 zstd(如 Go 服务端),切到
|
||||
// zlib 会让分享链路在下次建连后失联。zstd 对所有对端都兼容。
|
||||
if (mode == "zlib" && m_cfg && !m_cfg->GetStr("settings", "share_list").empty()) {
|
||||
Mprintf("[compress-switch] refused zlib: share links present\n");
|
||||
ClientMsg msg("线缆压缩", "Compression switch refused: this host has share links; cancel sharing before switching to zlib");
|
||||
SendData((LPBYTE)&msg, sizeof(msg));
|
||||
break;
|
||||
}
|
||||
if (m_cfg)
|
||||
m_cfg->SetStr("settings", "compress", mode);
|
||||
Mprintf("[compress-switch] set to %s, reconnecting\n", mode.c_str());
|
||||
@@ -1470,6 +1487,17 @@ VOID CKernelManager::OnReceive(PBYTE szBuffer, ULONG ulLength)
|
||||
SendData((LPBYTE)&msg, sizeof(msg));
|
||||
break;
|
||||
}
|
||||
// 主机当前走 zlib 时不接受分享:分享实例构造时会读整机 compress
|
||||
// 配置,带着 zlib 去连分享目标;对端若只支持 zstd(如 Go 服务端),
|
||||
// 这条分享链路一建就连不上。先切回 zstd 再分享。
|
||||
// 按配置判断而非当前连接:并行上线时当前连接的模式可能已不是新实例
|
||||
// 将要使用的模式(配置由收到切换命令的那条连接写入,是整机共享的)。
|
||||
if (IOCPClient::ConfiguredWireZlib()) {
|
||||
Mprintf("Share ignored: client uses zlib wire compression\n");
|
||||
ClientMsg msg("分享主机", "Client uses zlib wire compression, switch it back to zstd before sharing");
|
||||
SendData((LPBYTE)&msg, sizeof(msg));
|
||||
break;
|
||||
}
|
||||
if (targetKey.empty())
|
||||
break;
|
||||
auto share = targetKey;
|
||||
|
||||
Reference in new issue
Block a user