Phase 4: Implement SSH packet size limit (maxpack - 1024)
Some checks failed
Test / test (push) Has been cancelled
Test / build (push) Has been cancelled

- Add maxpack field to SftpHandler structure
- Modify SftpHandler::new() to accept maxpack parameter
- Limit SSH_FXP_READ data size to maxpack - 1024 bytes (OpenSSH style)
- Get maxpack from Channel.remote_maxpacket

Changes:
- sftp_handler.rs: SftpHandler struct + new() + handle_read()
- channel.rs: Pass remote_maxpacket to SftpHandler::new()

Reference: OpenSSH sftp-server.c: process_read()
- Limit: maxpacket - 1024 bytes
- Prevent packet size violation

Test status: 5MB upload still incomplete (2.0MB)
- Issue may require additional debugging
- Upload direction may also need maxpack limit
This commit is contained in:
Warren
2026-06-17 20:18:21 +08:00
parent 70353d2a55
commit cacf106b80
2 changed files with 23 additions and 3 deletions

View File

@@ -460,7 +460,15 @@ impl ChannelManager {
// Phase 7: 初始化SFTP handler
let root_dir = PathBuf::from("/Users/accusys/markbase"); // 默认root目录
let sftp_handler = SftpHandler::new(root_dir);
// ⭐⭐⭐⭐⭐ Phase 4: 获取 client maxpack 限制(从 Channel 中获取)
let maxpacket = if let Some(ch) = self.channels.get(&channel) {
ch.remote_maxpacket // 来自 SSH_MSG_CHANNEL_OPEN 的 maximum_packet_size
} else {
32768 // OpenSSH 默认值32KB
};
let sftp_handler = SftpHandler::new(root_dir, maxpacket); // ⭐⭐⭐⭐⭐ Phase 4: 传入 maxpack
// 存储到channel
if let Some(ch) = self.channels.get_mut(&channel) {