feat(ssh): Add ScpState state machine for SCP file transfer (Phase 8.3 init)
Some checks failed
Test / test (push) Has been cancelled
Test / build (push) Has been cancelled

This commit is contained in:
Warren
2026-06-20 12:53:25 +08:00
parent cdfe227704
commit cc30a8e9b1
2 changed files with 20 additions and 0 deletions

Binary file not shown.

View File

@@ -178,6 +178,7 @@ impl ChannelManager {
exec_process: None, // Phase 14: 交互式exec exec_process: None, // Phase 14: 交互式exec
sftp_input_buffer: Vec::new(), // ⭐⭐⭐⭐⭐ Phase 14.2修复SFTP packet累积 sftp_input_buffer: Vec::new(), // ⭐⭐⭐⭐⭐ Phase 14.2修复SFTP packet累积
scp_input_buffer: Vec::new(), // ⭐⭐⭐⭐⭐ Phase 14.4修复SCP packet累积 scp_input_buffer: Vec::new(), // ⭐⭐⭐⭐⭐ Phase 14.4修复SCP packet累积
scp_state: ScpState::Idle, // ⭐⭐⭐⭐⭐ Phase 8.3: SCP state machine
direct_tcpip: None, direct_tcpip: None,
forwarded_tcpip: None, forwarded_tcpip: None,
}; };
@@ -255,6 +256,7 @@ impl ChannelManager {
exec_process: None, exec_process: None,
sftp_input_buffer: Vec::new(), sftp_input_buffer: Vec::new(),
scp_input_buffer: Vec::new(), scp_input_buffer: Vec::new(),
scp_state: ScpState::Idle, // ⭐⭐⭐⭐⭐ Phase 8.3: SCP state machine
direct_tcpip: Some(direct_tcpip), direct_tcpip: Some(direct_tcpip),
forwarded_tcpip: None, forwarded_tcpip: None,
}; };
@@ -329,6 +331,7 @@ impl ChannelManager {
exec_process: None, // Phase 14: 交互式exec exec_process: None, // Phase 14: 交互式exec
sftp_input_buffer: Vec::new(), // ⭐⭐⭐⭐⭐ Phase 14.2修复 sftp_input_buffer: Vec::new(), // ⭐⭐⭐⭐⭐ Phase 14.2修复
scp_input_buffer: Vec::new(), // ⭐⭐⭐⭐⭐ Phase 14.4修复 scp_input_buffer: Vec::new(), // ⭐⭐⭐⭐⭐ Phase 14.4修复
scp_state: ScpState::Idle, // ⭐⭐⭐⭐⭐ Phase 8.3: SCP state machine
direct_tcpip: None, direct_tcpip: None,
forwarded_tcpip: Some(forwarded_tcpip), forwarded_tcpip: Some(forwarded_tcpip),
}; };
@@ -1945,6 +1948,8 @@ struct Channel {
sftp_input_buffer: Vec<u8>, // Phase 14.2修复累积不完整的SFTP packets sftp_input_buffer: Vec<u8>, // Phase 14.2修复累积不完整的SFTP packets
// ⭐⭐⭐⭐⭐ Phase 14.4SCP packet累积buffer // ⭐⭐⭐⭐⭐ Phase 14.4SCP packet累积buffer
scp_input_buffer: Vec<u8>, // Phase 14.4修复累积不完整的SCP packets scp_input_buffer: Vec<u8>, // Phase 14.4修复累积不完整的SCP packets
// ⭐⭐⭐⭐⭐ Phase 8.3: SCP file transfer state machine
scp_state: ScpState, // Phase 8.3: SCP state tracking
// Phase 13.3: 端口转发相关字段 // Phase 13.3: 端口转发相关字段
direct_tcpip: Option<DirectTcpipChannel>, // direct-tcpip channelRemote forwarding direct_tcpip: Option<DirectTcpipChannel>, // direct-tcpip channelRemote forwarding
forwarded_tcpip: Option<ForwardedTcpipChannel>, // forwarded-tcpip channelLocal forwarding forwarded_tcpip: Option<ForwardedTcpipChannel>, // forwarded-tcpip channelLocal forwarding
@@ -1957,6 +1962,21 @@ enum ChannelState {
Closed, Closed,
} }
/// ⭐⭐⭐⭐⭐ Phase 8.3: SCP file transfer state machine
/// Reference: OpenSSH scp.c: sink() (destination mode)
#[derive(Debug, Clone)]
enum ScpState {
Idle,
FileCommandReceived {
size: u64,
filename: String,
remaining: u64,
},
DirectoryCreated {
dirname: String,
},
}
/// SSH string读取辅助函数 /// SSH string读取辅助函数
fn read_ssh_string<R: std::io::Read>(reader: &mut R) -> Result<String> { fn read_ssh_string<R: std::io::Read>(reader: &mut R) -> Result<String> {
let length = reader.read_u32::<BigEndian>()?; let length = reader.read_u32::<BigEndian>()?;