Feature(Go): read_file over the V2 stream receiver

read_file reuses the list_files handshake: COMMAND_LIST_DRIVE opens the
file-manager sub-conn, which then gets
[CMD_DOWN_FILES_V2][targetDir\0][path\0][\0] and streams
COMMAND_SEND_FILE_V2 chunks plus a COMMAND_FILE_COMPLETE_V2 carrying the
whole-file SHA-256. Windows clients open a fresh authenticated sub-conn
for the chunks; POSIX clients stream on the file-manager conn itself, so
that conn is retired when the call ends rather than right after the
request. TOKEN_DOWNLOAD_ERROR on the file-manager conn maps to -32009 /
-32010 / -32000 like the Win32 server.

Bytes land only in a per-call os.MkdirTemp dir; the client name is
checked against the target dir (separator-normalised, path.Clean, so
..\.., absolute, UNC and mixed separators are refused) as
defence-in-depth, never used as a path. First chunk enforces the size
gate (ReadMax) and rejects multi-file batches, so an expanded directory
fails with -32602 instead of returning its first file. Chunks from a
sub-conn opened for an earlier call are dropped by connection ID, data
sub-conns are closed when the call ends, and a closed sub-conn fails the
call fast instead of waiting for the stall watchdog.

Text windowing, encoding detection (BOM / UTF-8 / GBK / explicit /
latin1) and EOL handling mirror McpServer.cpp. Verified with the Debug
ghost on Windows 11 and the WSL Ubuntu ghost: .env text plus newline is
byte-identical, sha256 equals SHA-256 over the file, windows/GBK/empty/
max_bytes/directory/size-gate/missing-path/POSIX-path cases all pass.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-12 23:04:35 +01:00
1 parent d7accf1d30
commit 9ce1a58bc3
7 files changed
+1790 -71

No files matched your search

+12 -7
View File
@@ -23,11 +23,12 @@ type fileWire struct {
}
type fileRig struct {
t *testing.T
s *Server
h *hub.Hub
main *connection.Context
w chan fileWire
t *testing.T
s *Server
h *hub.Hub
main *connection.Context
w chan fileWire
connID uint64 // sub-connections get increasing IDs, like connection.Manager
}
func newFileRig(t *testing.T) *fileRig {
@@ -50,7 +51,7 @@ func newFileRig(t *testing.T) *fileRig {
}
return nil
})
h.Register(&hub.Device{ID: "1001", PeerIP: "10.0.0.1"}, main)
h.Register(&hub.Device{ID: "1001", PeerIP: "10.0.0.1", Capability: "1"}, main)
rig.s = New(Config{Token: testToken, Hub: h})
t.Cleanup(rig.s.Close)
return rig
@@ -62,7 +63,11 @@ func (r *fileRig) newSub() *connection.Context {
r.t.Helper()
c1, c2 := net.Pipe()
r.t.Cleanup(func() { _ = c1.Close(); _ = c2.Close() })
ctx := &connection.Context{Conn: c1, RemoteAddr: "10.0.0.1:4100"}
// Real contexts are numbered monotonically at accept time; read_file uses
// that to tell a data sub-conn opened for this call from one left over by an
// earlier call, so the fake ones have to be numbered too.
r.connID++
ctx := &connection.Context{ID: r.connID, Conn: c1, RemoteAddr: "10.0.0.1:4100"}
ctx.Info.ClientID = "1001"
return ctx
}