1
0
Fork 0
mirror of https://gitlab.redox-os.org/CoffeeCode/redox-ssh.git synced 2025-12-28 15:22:18 +01:00

Implement connection threads

This commit is contained in:
Thomas Gatzweiler 2017-07-19 08:50:06 +02:00
parent 3f23c15783
commit 712e4fd208
2 changed files with 16 additions and 11 deletions

View file

@ -7,7 +7,7 @@ mod ed25519;
pub use self::ed25519::ED25519;
pub trait KeyPair {
pub trait KeyPair: Sync + Send {
fn system(&self) -> &'static CryptoSystem;
fn has_private(&self) -> bool;

View file

@ -1,6 +1,7 @@
use std::io;
use std::net::TcpListener;
use std::sync::Arc;
use std::thread;
use connection::{Connection, ConnectionType};
use public_key::KeyPair;
@ -25,21 +26,25 @@ impl Server {
TcpListener::bind((&*self.config.host, self.config.port))?;
loop {
let (mut stream, addr) = listener.accept()?;
let (stream, addr) = listener.accept()?;
let config = self.config.clone();
debug!("Incoming connection from {}", addr);
let mut read_stream = stream.try_clone()?;
thread::spawn(move || {
let mut read_stream = stream.try_clone().unwrap();
let mut connection = Connection::new(
ConnectionType::Server(self.config.clone()),
Box::new(stream),
);
let mut connection = Connection::new(
ConnectionType::Server(config),
Box::new(stream),
);
let result = connection.run(&mut read_stream);
if let Some(error) = result.err() {
println!("sshd: {}", error)
}
let result = connection.run(&mut read_stream);
if let Some(error) = result.err() {
println!("sshd: {}", error)
}
});
}
Ok(())