1mod handler;
2mod hash;
3mod run;
4mod upload;
5
6use crate::cli::Server;
7use crate::hash::Hasher;
8use handler::ClientHandler;
9use std::{
10 io::{self},
11 net::TcpListener,
12};
13use tracing::{info, warn};
14
15pub fn server(config: Server) -> io::Result<()> {
16 let listener = TcpListener::bind(format!("0.0.0.0:{}", config.server_port))?;
17 info!("Server listening on port {}", config.server_port);
18
19 let password_hash = Hasher::hash_password(&config.password);
20 info!("Password hash calculated");
21
22 loop {
23 let (socket, addr) = listener.accept()?;
24 info!("Accepted connection from {addr}");
25
26 let mut client_handler = ClientHandler::new(socket, password_hash);
27 if let Err(e) = client_handler.handle_client() {
28 warn!("Error while handling connection: {e}");
29 }
30 }
31}