diff --git a/src/lib.rs b/src/lib.rs index 7d78d8e..a72004d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,13 +73,14 @@ async fn pump_write( // ---------------------------------------------------------------------------- // Server -struct ServerConnection { +struct Connection { + connected: Option>, data: mpsc::Sender, } #[derive(Clone)] struct ServerConnectionTable { - connections: Arc>>, + connections: Arc>>, } impl ServerConnectionTable { @@ -91,7 +92,13 @@ impl ServerConnectionTable { fn add(self: &mut Self, id: u64, data: mpsc::Sender) { let mut connections = self.connections.lock().unwrap(); - connections.insert(id, ServerConnection { data }); + connections.insert( + id, + Connection { + connected: None, + data, + }, + ); } async fn receive(self: &Self, id: u64, buf: Bytes) { @@ -230,18 +237,6 @@ async fn server_main( } } -async fn spawn_ssh(server: &str) -> Result { - let mut cmd = process::Command::new("ssh"); - cmd.arg("-T").arg(server).arg("fwd").arg("--server"); - - cmd.stdout(std::process::Stdio::piped()); - cmd.stdin(std::process::Stdio::piped()); - match cmd.spawn() { - Ok(t) => Ok(t), - Err(e) => Err(Error::IO(e)), - } -} - async fn client_sync(reader: &mut T) -> Result<(), Error> { eprintln!("> Waiting for synchronization marker..."); let mut seen = 0; @@ -255,14 +250,9 @@ async fn client_sync(reader: &mut T) -> Result<(), Error> Ok(()) } -struct ClientConnection { - connected: Option>, - data: mpsc::Sender, -} - struct ClientConnectionTableState { next_id: u64, - connections: HashMap, + connections: HashMap, } #[derive(Clone)] @@ -286,7 +276,7 @@ impl ClientConnectionTable { tbl.next_id += 1; tbl.connections.insert( id, - ClientConnection { + Connection { connected: Some(connected), data, }, @@ -532,6 +522,18 @@ pub async fn run_server() { } } +async fn spawn_ssh(server: &str) -> Result { + let mut cmd = process::Command::new("ssh"); + cmd.arg("-T").arg(server).arg("fwd").arg("--server"); + + cmd.stdout(std::process::Stdio::piped()); + cmd.stdin(std::process::Stdio::piped()); + match cmd.spawn() { + Ok(t) => Ok(t), + Err(e) => Err(Error::IO(e)), + } +} + pub async fn run_client(remote: &str) { // TODO: Drive a reconnect loop let mut child = spawn_ssh(remote).await.expect("failed to spawn");