ev3_runner/
server.rs

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