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:
1 parent
d7accf1d30
commit
9ce1a58bc3
7 files changed
+1790
-71
No files matched your search
+16
-14
@@ -73,11 +73,12 @@ type Server struct {
|
||||
// locks serialises device operations; sem bounds the global in-flight
|
||||
// tools/call count. Both are non-blocking: contention is -32003, not a
|
||||
// queue, so a slow call cannot pile up requests behind it (design §9).
|
||||
locks *deviceLocks
|
||||
sem chan struct{}
|
||||
sessions *sessionTable
|
||||
previews *previewTable // in-flight get_screenshot requests, keyed by device
|
||||
files *fileTable // in-flight list_files requests, keyed by device
|
||||
locks *deviceLocks
|
||||
sem chan struct{}
|
||||
sessions *sessionTable
|
||||
previews *previewTable // in-flight get_screenshot requests, keyed by device
|
||||
files *fileTable // in-flight list_files requests, keyed by device
|
||||
transfers *transferTable // in-flight read_file V2 transfers, keyed by device
|
||||
|
||||
// stop ends the idle reaper and reaperDone reports that it returned;
|
||||
// closeOnce makes Close idempotent (tests call it both explicitly and from
|
||||
@@ -110,15 +111,16 @@ func New(cfg Config) *Server {
|
||||
cfg.Log = logger.New(logger.Config{Level: logger.LevelError})
|
||||
}
|
||||
s := &Server{
|
||||
cfg: cfg,
|
||||
log: cfg.Log,
|
||||
tools: buildToolSet(toolsJSON),
|
||||
handlers: make(map[string]toolFunc),
|
||||
locks: newDeviceLocks(),
|
||||
sem: make(chan struct{}, cfg.MaxConcurrency),
|
||||
previews: newPreviewTable(),
|
||||
files: newFileTable(),
|
||||
stop: make(chan struct{}),
|
||||
cfg: cfg,
|
||||
log: cfg.Log,
|
||||
tools: buildToolSet(toolsJSON),
|
||||
handlers: make(map[string]toolFunc),
|
||||
locks: newDeviceLocks(),
|
||||
sem: make(chan struct{}, cfg.MaxConcurrency),
|
||||
previews: newPreviewTable(),
|
||||
files: newFileTable(),
|
||||
transfers: newTransferTable(),
|
||||
stop: make(chan struct{}),
|
||||
}
|
||||
if cfg.Hub != nil {
|
||||
s.sessions = newSessionTable(cfg.Hub)
|
||||
|
||||
Reference in new issue
Block a user