Feature: Make Linux a copy_files_c2c destination
The C2C file transfer tool required both ends to be Windows clients. A Linux client can already land the files: the Windows source worker builds every entry name by plain string concatenation of dst_dir and the relative path, so a POSIX dst_dir such as /tmp/recv arrives as "/tmp/recv\sub\file", which the POSIX receiver normalizes to "/" and writes below an absolute path. What was missing was the server gate and any way to tell whether the writes succeeded. The server now accepts LNX/MAC destinations instead of rejecting them, and validates dst_dir by destination type: an absolute Windows path for Windows targets, an absolute POSIX path without backslashes for POSIX targets. The paths and dst_dir arguments also reject embedded NULs, and a POSIX dst_dir is converted to CP936 exactly so unencodable characters fail loudly instead of silently becoming '?'. To make receiver_ack meaningful, a Linux client that receives a C2C transfer now reports what it wrote. It tracks the outcome per transferID, counting a directory entry, the last chunk of a file and the completion packet of an empty file as the three ways an item is settled, with done sets so that source retries and the trailing completion packet never double count. When every item is settled it sends one C2CSendResultPacket back on its main connection under the new TOKEN_C2C_RECV_RESULT (176), with the first errno in the win32err field and the mapped FEV2_* status. A dedicated token is used instead of reusing 175 because a host can be the destination of one transfer while being the source of another, and a destination result must never latch the source side's done flag. The server waits up to five seconds for that acknowledgement after the source reports success, and only for destinations advertising the new CLIENT_CAP_C2C_RECV_ACK capability bit (Linux only, macOS reports nothing). A failed acknowledgement becomes -32011 with the status, errno and received file count; a missing acknowledgement stays an error only for transfers that actually moved bytes, since a transfer of empty files alone gives the receiver nothing to learn totalFiles from. Windows destinations are unchanged and skip the wait entirely. Verified on the debug instance: Windows to Linux (WSL Ubuntu 24.04) with subdirectories, an empty directory, a Chinese file name and a 3 MB binary lands with matching SHA-256 and receiver_ack true; a Windows-style dst_dir returns -32602; an unwritable POSIX destination returns -32011; the existing Windows to Windows cases still pass with receiver_ack false and the same latency. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
4c0e86dcc5
commit
4146c73657
11 files changed
+384
-48
No files matched your search
+4
-3
@@ -840,8 +840,9 @@ Debug 实例(`Bin\Yama_x64d.exe`,临时端口)实测:`list_all_hosts`
|
||||
|
||||
第 54 个工具:把文件从一台客户端**直接**发到另一台,服务端只做包中继,不落盘。复用 V2 文件传输的 C2C 通道(`FileChunkPacketV2.dstClientID != 0`),新增协议号 `COMMAND_C2C_SEND_FILES=174`(服务端给源端下路径清单)、`TOKEN_C2C_SEND_RESULT=175`(源端回传发送结果),以及能力位 `CLIENT_CAP_C2C_PATHS=0x0008`(老客户端因此被提前拒绝并提示升级)。
|
||||
|
||||
- 工具契约:`src_id` / `dst_id` / `paths[]` / `dst_dir` / 可选 `timeout_ms`;返回 `transfer_id` / `file_count` / `total_bytes` / `receiver_ack`(恒为 `false`,V2 的完成校验在接收方做但没有回执)。
|
||||
- 工具契约:`src_id` / `dst_id` / `paths[]` / `dst_dir` / 可选 `timeout_ms`;返回 `transfer_id` / `file_count` / `total_bytes` / `receiver_ack`。
|
||||
- 开关:`McpFileTransfer=1 && McpReadonly=0`(会写远程),注解登记为破坏性 + 非只读,`McpInternal` 的 gating 表同步。
|
||||
- 两端都必须是 Windows 客户端(`-32005`):目标端也限制,是因为 `dst_dir` 由源端拼进 V2 块的文件名,非 Windows 接收端拿不到目标目录会写到错误位置。
|
||||
- 源端必须是 Windows 客户端(`-32005`);目标端可以是 Windows / Linux / macOS(2026-10-27 起)。POSIX 目标给绝对 POSIX `dst_dir`(`/tmp/recv`),服务端在建会话前校验形态,非法 `-32602`。
|
||||
- `receiver_ack`:Linux 目标端落盘后会回一包 `TOKEN_C2C_RECV_RESULT=176`(能力位 `CLIENT_CAP_C2C_RECV_ACK=0x0010`),`true` 表示目标端确认写入、`total_bytes` 是实收值;写入失败统一 `-32011`(带 status/errno)。Windows/macOS 目标端不回执,仍为 `false`,需 `list_files` 复核。
|
||||
- 实施中一个坑:服务端既有的 C2C 中继分支会在源端子连接上挂进度对话框,而 `NotifyProc` 对挂了 `hDlg` 的连接会把后续包交给对话框——源端最后那包结果就被当 V1 文件块吃掉,工具只能超时。现按「该 host 是否有 MCP 的 C2C 会话」跳过对话框,MFC 手动 C2C 不变。
|
||||
- 协议细节、落盘路径语义(`dst_dir` + 相对公共父目录)、错误码映射、限制与实测见 [Mcp_FileTransfer_Design.md](./Mcp_FileTransfer_Design.md) §14。
|
||||
- 协议细节、落盘路径语义(`dst_dir` + 相对公共父目录,Windows 与 POSIX 两种目标端)、回执与错误码映射(含 `-32011`)、限制与实测见 [Mcp_FileTransfer_Design.md](./Mcp_FileTransfer_Design.md) §14。
|
||||
Reference in new issue
Block a user