Feature: query the remote SHA-256 before previewing

When the main connection advertises CLIENT_CAP_FILE_HASH, double-click
sends COMMAND_FILE_HASH first and continues from the async
TOKEN_FILE_HASH response (posted to the UI thread). A matching SHA-256
opens the cached copy without a transfer, including content found under
a different remote path; the new path is added to the index. Too-large
and error responses are handled, and a 5 second timeout falls back to the
P1 size/mtime path.

The response parser is based on FileHashResponseHeader and the echoed
request path; pending state is cleared on close and the hash timer is
killed with the dialog.

Verified with the Debug server and client: a 1 MiB file was hashed,
transferred and cached under its SHA-256; an identical copy at a second
path hit the cache with no new transfer or stream connection.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-12-05 15:43:12 +01:00
1 parent ea5d69d1c0
commit 6cb779ef70
7 files changed
+168 -5

No files matched your search

+12
View File
@@ -21,6 +21,18 @@ class CONTEXT_OBJECT;
// 预览完成/失败:lParam 是 new 出来的 CFilePreviewMgr::Result,由对话框 delete。
#define WM_PREVIEW_RESULT (WM_USER + 0x306)
// 哈希查询响应:lParam 是 new 出来的 FilePreviewHashResult,由对话框 delete。
#define WM_PREVIEW_HASH_RESP (WM_USER + 0x307)
// COMMAND_FILE_HASH 响应的解析结果(对话框 UI 线程消费)。
struct FilePreviewHashResult {
std::string path; // 请求里原样回显的路径(GBK)
uint32_t status = 0;
uint32_t err = 0;
uint64_t size = 0;
uint64_t mtimeMs = 0;
std::string sha256; // 64 位小写十六进制;status != FILE_HASH_OK 时为空
};
// 设备级文件传输闸门:预览与 MCP 的 download/read、upload、C2C 都在同一临界区认领设备。
// C2C 需要原子认领 src+dst 两个键。owner 只用于释放校验,避免旧会话误放新会话。