Commit 712e4fd2 authored by Thomas Gatzweiler's avatar Thomas Gatzweiler
Browse files

Implement connection threads

parent 3f23c157
......@@ -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;
......
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(())
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment