Skip to content

Commit d78922c

Browse files
authored
Merge pull request #86 from matrss/add-generate-ticket-command
feat: add generate-ticket command
2 parents 8c88b29 + 2341e0f commit d78922c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/main.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ pub struct Args {
4242

4343
#[derive(Subcommand, Debug)]
4444
pub enum Commands {
45+
/// Generate a short endpoint ticket. This ticket can be used to later connect to a
46+
/// listener that is using the same secret key again.
47+
///
48+
/// This command only really makes sense when you are providing dumbpipe with a
49+
/// secret key.
50+
GenerateTicket(GenerateTicketArgs),
51+
4552
/// Listen on an endpoint and forward stdin/stdout to the first incoming
4653
/// bidi stream.
4754
///
@@ -148,6 +155,12 @@ fn parse_alpn(alpn: &str) -> Result<Vec<u8>> {
148155
})
149156
}
150157

158+
#[derive(Parser, Debug)]
159+
pub struct GenerateTicketArgs {
160+
#[clap(flatten)]
161+
pub common: CommonArgs,
162+
}
163+
151164
#[derive(Parser, Debug)]
152165
pub struct ListenArgs {
153166
/// Immediately close our sending side, indicating that we will not transmit any data
@@ -823,11 +836,23 @@ async fn connect_unix(args: ConnectUnixArgs) -> Result<()> {
823836
Ok(())
824837
}
825838

839+
async fn generate_ticket(args: GenerateTicketArgs) -> Result<()> {
840+
let secret_key = get_or_create_secret()?;
841+
let endpoint = create_endpoint(secret_key, &args.common, vec![args.common.alpn()?]).await?;
842+
// wait for the endpoint to figure out its home relay and addresses before making a ticket
843+
endpoint.online().await;
844+
let addr = endpoint.addr();
845+
let short = create_short_ticket(&addr);
846+
println!("{}", short);
847+
Ok(())
848+
}
849+
826850
#[tokio::main]
827851
async fn main() -> Result<()> {
828852
tracing_subscriber::fmt::init();
829853
let args = Args::parse();
830854
let res = match args.command {
855+
Commands::GenerateTicket(args) => generate_ticket(args).await,
831856
Commands::Listen(args) => listen_stdio(args).await,
832857
Commands::ListenTcp(args) => listen_tcp(args).await,
833858
Commands::Connect(args) => connect_stdio(args).await,

0 commit comments

Comments
 (0)