You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let listener = TcpListener::bind("0.0.0.0:60000").await?;println!("Listening on port 60000");loop{// Accept incoming connectionslet(mut socket, addr) = listener.accept().await?;println!("Accepted connection from {:?}", addr);let jump_host = jump_host.clone();let target_host = target_host.clone();let jump_host_user = jump_host_user.cloned();let jump_host_pwd = jump_host_pwd.cloned();// Spawn a new task to handle the connection
tokio::spawn(asyncmove{// Configure the SSH clientletmut config = client::Config::default();
config.inactivity_timeout = Some(std::time::Duration::from_secs(3600*60));let config = Arc::new(config);let sh = Client{};// Connect to the SSH serverlet addr:Vec<SocketAddr> =
tokio::net::lookup_host(format!("{}:{}", jump_host, jump_host_port)).await?
.collect();letmut jump_handle = client::connect(config.clone(), addr.as_slice(), sh).await?;if jump_host_user.is_some() && jump_host_pwd.is_some(){// Authenticatelet is_authenticated = jump_handle
.authenticate_password(jump_host_user.unwrap(), jump_host_pwd.unwrap()).await?;if !is_authenticated {bail!("failed to authenticate");}else{info!("authenticated");}}else{bail!("TODO: authentication other than password");}letmut buffer = [0;1024];let(mut reader,mut writer) = socket.split();letmut channel = jump_handle
.channel_open_direct_tcpip(target_host, target_host_port,"localhost", local_port).await?
.into_stream();loop{
tokio::select! {
_ = tokio::io::copy(&mut reader, &mut channel) => {},
_ = tokio::io::copy(&mut channel, &mut writer) => {}, ///cannot borrow `channel` as mutable more than once at a time};});}}
I am trying to write a simple program that listens on local port 60000 and forwards ssh traffic to target_host through jump_host.
At a high level, I knew I needed to listen to local socket traffic and handle read/write from connection to jump_host.
However, I feel like I completely misunderstood how to implement local port forwarding by using this library since this library API design does allow me to do it this way.
Does anyone can enlighten me on how to achieve this goal? (maybe I need to set up russh server to listen port and then forward traffic? )
The text was updated successfully, but these errors were encountered:
I am trying to write a simple program that listens on local port 60000 and forwards ssh traffic to target_host through jump_host.
At a high level, I knew I needed to listen to local socket traffic and handle read/write from connection to jump_host.
However, I feel like I completely misunderstood how to implement local port forwarding by using this library since this library API design does allow me to do it this way.
Does anyone can enlighten me on how to achieve this goal? (maybe I need to set up russh server to listen port and then forward traffic? )
The text was updated successfully, but these errors were encountered: