diff --git a/src/main.rs b/src/main.rs index e51c357..53956ef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,6 +42,13 @@ pub struct Args { #[derive(Subcommand, Debug)] pub enum Commands { + /// Generate a short endpoint ticket. This ticket can be used to later connect to a + /// listener that is using the same secret key again. + /// + /// This command only really makes sense when you are providing dumbpipe with a + /// secret key. + GenerateTicket(GenerateTicketArgs), + /// Listen on an endpoint and forward stdin/stdout to the first incoming /// bidi stream. /// @@ -148,6 +155,12 @@ fn parse_alpn(alpn: &str) -> Result> { }) } +#[derive(Parser, Debug)] +pub struct GenerateTicketArgs { + #[clap(flatten)] + pub common: CommonArgs, +} + #[derive(Parser, Debug)] pub struct ListenArgs { /// Immediately close our sending side, indicating that we will not transmit any data @@ -823,11 +836,23 @@ async fn connect_unix(args: ConnectUnixArgs) -> Result<()> { Ok(()) } +async fn generate_ticket(args: GenerateTicketArgs) -> Result<()> { + let secret_key = get_or_create_secret()?; + let endpoint = create_endpoint(secret_key, &args.common, vec![args.common.alpn()?]).await?; + // wait for the endpoint to figure out its home relay and addresses before making a ticket + endpoint.online().await; + let addr = endpoint.addr(); + let short = create_short_ticket(&addr); + println!("{}", short); + Ok(()) +} + #[tokio::main] async fn main() -> Result<()> { tracing_subscriber::fmt::init(); let args = Args::parse(); let res = match args.command { + Commands::GenerateTicket(args) => generate_ticket(args).await, Commands::Listen(args) => listen_stdio(args).await, Commands::ListenTcp(args) => listen_tcp(args).await, Commands::Connect(args) => connect_stdio(args).await,