Skip to content

Commit

Permalink
feat: select ssh server address (#12)
Browse files Browse the repository at this point in the history
* feat: specify addr of ssh server

* docs: update README.md

* refactor: rename `--proxy-for` to `--proxy-to`
  • Loading branch information
JyJyJcr authored Feb 14, 2024
1 parent f056247 commit 29c2b5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
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

0 comments on commit 29c2b5b

Please sign in to comment.