mirror of
https://gitlab.redox-os.org/CoffeeCode/redox-ssh.git
synced 2025-12-28 20:22:18 +01:00
- Remove enum suffixes (`enum_variant_names`) - Match de-/referencing (`match_ref_pats`) - Unused lifetime parameter (`extra_unused_lifetimes`) - Rename `to_raw` to `into_raw` to match convention (`wrong_self_convention`) All remaining warnings are in regards to unused variables, methods, enum variants, fields, or unreachable patterns. Also, unit result error types (`Result<u8, ()>`) remain (`result_unit_err`).
46 lines
1.1 KiB
Rust
46 lines
1.1 KiB
Rust
use std::io;
|
|
use std::net::TcpListener;
|
|
use std::sync::Arc;
|
|
use std::thread;
|
|
|
|
use crate::connection::{Connection, ConnectionType};
|
|
use crate::public_key::KeyPair;
|
|
|
|
pub struct ServerConfig {
|
|
pub host: String,
|
|
pub port: u16,
|
|
pub key: Box<dyn KeyPair>,
|
|
}
|
|
|
|
pub struct Server {
|
|
config: Arc<ServerConfig>,
|
|
}
|
|
|
|
impl Server {
|
|
pub fn with_config(config: ServerConfig) -> Server {
|
|
Server { config: Arc::new(config) }
|
|
}
|
|
|
|
pub fn run(&self) -> io::Result<()> {
|
|
let listener =
|
|
TcpListener::bind((&*self.config.host, self.config.port))?;
|
|
|
|
loop {
|
|
let (mut stream, addr) = listener.accept()?;
|
|
let config = self.config.clone();
|
|
|
|
debug!("Incoming connection from {}", addr);
|
|
|
|
thread::spawn(move || {
|
|
let mut connection =
|
|
Connection::new(ConnectionType::Server(config));
|
|
|
|
let result = connection.run(&mut stream);
|
|
|
|
if let Some(error) = result.err() {
|
|
println!("sshd: {}", error)
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|