Merge origin SMB fixes with local Phase 21-22 features
Origin changes merged: - SMB performance optimization (pread/pwrite, tokio Mutex) - macOS SMB mount fix (AAPL caps, credit grant) - Compound request integration tests - CTDB architecture analysis Local changes preserved: - upload_path config (deployed, tested stable) - delete_file + preview_file routes (MyFiles UI) - SSH async I/O (cipher.rs, packet.rs, server.rs) - auth.sqlite (86016 bytes, important user data) - Admin WebDAV + CorsLayer - api/admin.rs + api/config.rs (new endpoints) Conflicts resolved: - myfiles.rs: kept upload_path + OnceLock static - auth.sqlite: preserved local version (important data) Test results: 393 passed, 5 auth tests failed - PG tests require external PostgreSQL - Auth tests expect specific password hashes - auth.sqlite preserved with actual user credentials
This commit is contained in:
@@ -17,10 +17,10 @@ use crate::ssh_server::version::VersionExchange;
|
||||
use anyhow::{anyhow, Result};
|
||||
use log::{error, info, warn};
|
||||
use std::io::{Read, Write};
|
||||
use std::net::{TcpListener, TcpStream};
|
||||
use std::net::TcpStream;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::thread;
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
pub struct SshServerConfig {
|
||||
pub port: u16,
|
||||
@@ -71,11 +71,11 @@ impl SshServer {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(&self) -> Result<()> {
|
||||
pub async fn run(&self) -> Result<()> {
|
||||
let bind_addr = format!("{}:{}", self.config.bind_address, self.config.port);
|
||||
let listener = TcpListener::bind(&bind_addr)?;
|
||||
let listener = TcpListener::bind(&bind_addr).await?;
|
||||
|
||||
info!("MarkBaseSSH server listening on {}", bind_addr);
|
||||
info!("MarkBaseSSH server listening on {} (async tokio)", bind_addr);
|
||||
info!("Implementation: Complete SSH/SFTP + Port Forwarding (Phase 1-13)");
|
||||
info!(
|
||||
"Security config: GatewayPorts={}, PermitOpen={:?}, MaxSessions={}",
|
||||
@@ -88,23 +88,30 @@ impl SshServer {
|
||||
let pg_conn = self.config.pg_conn.clone();
|
||||
let upload_hook_config = self.config.upload_hook_config.clone();
|
||||
|
||||
for stream in listener.incoming() {
|
||||
match stream {
|
||||
Ok(stream) => {
|
||||
let client_addr = stream.peer_addr()?;
|
||||
info!("New SSH connection from {}", client_addr);
|
||||
loop {
|
||||
match listener.accept().await {
|
||||
Ok((stream, addr)) => {
|
||||
info!("New SSH connection from {}", addr);
|
||||
|
||||
let security_config_clone = security_config.clone();
|
||||
let pg_conn_clone = pg_conn.clone();
|
||||
let upload_hook_config_clone = upload_hook_config.clone();
|
||||
|
||||
thread::spawn(move || {
|
||||
if let Err(e) = handle_connection_complete(
|
||||
stream,
|
||||
security_config_clone,
|
||||
pg_conn_clone,
|
||||
upload_hook_config_clone,
|
||||
)
|
||||
// ⭐⭐⭐⭐⭐ Convert tokio TcpStream to std TcpStream for blocking handler
|
||||
// Set blocking explicitly since into_std() may preserve non-blocking mode
|
||||
let std_stream = stream.into_std()?;
|
||||
std_stream.set_nonblocking(false)?;
|
||||
|
||||
tokio::spawn(async move {
|
||||
// Run the existing sync connection handler in a blocking thread
|
||||
if let Err(e) = tokio::task::spawn_blocking(move || {
|
||||
handle_connection_complete(
|
||||
std_stream,
|
||||
security_config_clone,
|
||||
pg_conn_clone,
|
||||
upload_hook_config_clone,
|
||||
)
|
||||
}).await.unwrap_or(Err(anyhow!("Task join error")))
|
||||
{
|
||||
error!("SSH connection error: {}", e);
|
||||
}
|
||||
@@ -115,8 +122,6 @@ impl SshServer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -787,7 +792,7 @@ fn extract_username_from_auth_request(
|
||||
}
|
||||
|
||||
/// SSH服务器CLI入口
|
||||
pub fn run_ssh_server(port: Option<u16>, pg_conn: Option<&str>) -> Result<()> {
|
||||
pub async fn run_ssh_server(port: Option<u16>, pg_conn: Option<&str>) -> Result<()> {
|
||||
let config = SshServerConfig {
|
||||
port: port.unwrap_or(2024),
|
||||
bind_address: "0.0.0.0".to_string(), // ⭐⭐⭐⭐⭐ Phase 8.3: Allow Docker container access
|
||||
@@ -797,5 +802,5 @@ pub fn run_ssh_server(port: Option<u16>, pg_conn: Option<&str>) -> Result<()> {
|
||||
};
|
||||
|
||||
let server = SshServer::new(config);
|
||||
server.run()
|
||||
server.run().await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user