Skip to main content

max / makenotwork

1.3 KB · 55 lines History Blame Raw
1 //! SSH server implementation using russh.
2
3 #[cfg(test)]
4 mod backpressure_test;
5 pub(crate) mod git;
6 pub(crate) mod handler;
7 pub(crate) mod sftp;
8 pub(crate) mod terminal;
9
10 use std::net::SocketAddr;
11 use std::path::PathBuf;
12 use std::sync::Arc;
13
14 use crate::api::MnwApiClient;
15 use crate::rate_limit::AuthRateLimiter;
16
17 /// SSH server that spawns a new handler per connection.
18 pub(crate) struct MnwServer {
19 api: MnwApiClient,
20 staging_dir: Arc<PathBuf>,
21 git_user: Arc<str>,
22 rate_limiter: Arc<AuthRateLimiter>,
23 }
24
25 impl MnwServer {
26 pub(crate) fn new(
27 api: MnwApiClient,
28 staging_dir: Arc<PathBuf>,
29 git_user: String,
30 rate_limiter: Arc<AuthRateLimiter>,
31 ) -> Self {
32 Self {
33 api,
34 staging_dir,
35 git_user: Arc::from(git_user),
36 rate_limiter,
37 }
38 }
39 }
40
41 impl russh::server::Server for MnwServer {
42 type Handler = handler::MnwHandler;
43
44 fn new_client(&mut self, peer_addr: Option<SocketAddr>) -> Self::Handler {
45 tracing::info!(?peer_addr, "new SSH connection");
46 handler::MnwHandler::new(
47 self.api.clone(),
48 peer_addr,
49 Arc::clone(&self.staging_dir),
50 Arc::clone(&self.git_user),
51 Arc::clone(&self.rate_limiter),
52 )
53 }
54 }
55