diff --git a/src/main.rs b/src/main.rs index 1de688e..b19ab5e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -124,6 +124,10 @@ fn parse_alpn(alpn: &str) -> Result> { #[derive(Parser, Debug)] pub struct ListenArgs { + /// Immediately close our sending side, indicating that we will not transmit any data + #[clap(long)] + pub recv_only: bool, + #[clap(flatten)] pub common: CommonArgs, } @@ -157,6 +161,10 @@ pub struct ConnectArgs { /// The node to connect to pub ticket: NodeTicket, + /// Immediately close our sending side, indicating that we will not transmit any data + #[clap(long)] + pub recv_only: bool, + #[clap(flatten)] pub common: CommonArgs, } @@ -322,8 +330,13 @@ async fn listen_stdio(args: ListenArgs) -> Result<()> { r.read_exact(&mut buf).await.e()?; snafu::ensure_whatever!(buf == dumbpipe::HANDSHAKE, "invalid handshake"); } - tracing::info!("forwarding stdin/stdout to {}", remote_node_id); - forward_bidi(tokio::io::stdin(), tokio::io::stdout(), r, s).await?; + if args.recv_only { + tracing::info!("forwarding stdout to {} (ignoring stdin)", remote_node_id); + forward_bidi(tokio::io::empty(), tokio::io::stdout(), r, s).await?; + } else { + tracing::info!("forwarding stdin/stdout to {}", remote_node_id); + forward_bidi(tokio::io::stdin(), tokio::io::stdout(), r, s).await?; + } // stop accepting connections after the first successful one break; } @@ -356,8 +369,13 @@ async fn connect_stdio(args: ConnectArgs) -> Result<()> { // on stdin, so just write a handshake. s.write_all(&dumbpipe::HANDSHAKE).await.e()?; } - tracing::info!("forwarding stdin/stdout to {}", remote_node_id); - forward_bidi(tokio::io::stdin(), tokio::io::stdout(), r, s).await?; + if args.recv_only { + tracing::info!("forwarding stdout to {} (ignoring stdin)", remote_node_id); + forward_bidi(tokio::io::empty(), tokio::io::stdout(), r, s).await?; + } else { + tracing::info!("forwarding stdin/stdout to {}", remote_node_id); + forward_bidi(tokio::io::stdin(), tokio::io::stdout(), r, s).await?; + } tokio::io::stdout().flush().await.e()?; Ok(()) }