Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: select ssh server address #12

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ Server
Usage: quicssh-rs server [OPTIONS]

Options:
-l, --listen <LISTEN> Address to listen on [default: 0.0.0.0:4433]
-h, --help Print help
-V, --version Print version
-l, --listen <LISTEN> Address to listen on [default: 0.0.0.0:4433]
-p, --proxy-to <PROXY_TO> Address of the ssh server [default: 127.0.0.1:22]
-h, --help Print help
-V, --version Print version
```
9 changes: 6 additions & 3 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub struct Opt {
/// Address to listen on
#[clap(long = "listen", short = 'l', default_value = "0.0.0.0:4433")]
listen: SocketAddr,
/// Address of the ssh server
#[clap(long = "proxy-to", short = 'p', default_value = "127.0.0.1:22")]
proxy_to: SocketAddr,
}

/// Returns default server configuration along with its certificate.
Expand Down Expand Up @@ -65,14 +68,14 @@ pub async fn run(options: Opt) -> Result<(), Box<dyn Error>> {
conn.remote_address()
);
tokio::spawn(async move {
handle_connection(conn).await;
handle_connection(options.proxy_to, conn).await;
});
// Dropping all handles associated with a connection implicitly closes it
}
}

async fn handle_connection(connection: quinn::Connection) {
let ssh_stream = TcpStream::connect("127.0.0.1:22").await;
async fn handle_connection(proxy_for: SocketAddr, connection: quinn::Connection) {
let ssh_stream = TcpStream::connect(proxy_for).await;
let ssh_conn = match ssh_stream {
Ok(conn) => conn,
Err(e) => {
Expand Down
Loading