//! SSH server implementation using russh. #[cfg(test)] mod backpressure_test; pub(crate) mod git; pub(crate) mod handler; pub(crate) mod sftp; pub(crate) mod terminal; use std::net::SocketAddr; use std::path::PathBuf; use std::sync::Arc; use crate::api::MnwApiClient; use crate::rate_limit::AuthRateLimiter; /// SSH server that spawns a new handler per connection. pub(crate) struct MnwServer { api: MnwApiClient, staging_dir: Arc, git_user: Arc, rate_limiter: Arc, } impl MnwServer { pub(crate) fn new( api: MnwApiClient, staging_dir: Arc, git_user: String, rate_limiter: Arc, ) -> Self { Self { api, staging_dir, git_user: Arc::from(git_user), rate_limiter, } } } impl russh::server::Server for MnwServer { type Handler = handler::MnwHandler; fn new_client(&mut self, peer_addr: Option) -> Self::Handler { tracing::info!(?peer_addr, "new SSH connection"); handler::MnwHandler::new( self.api.clone(), peer_addr, Arc::clone(&self.staging_dir), Arc::clone(&self.git_user), Arc::clone(&self.rate_limiter), ) } }