From 2341e0fdd33425b44baa3ee76f4c8373011d087b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Ri=C3=9Fe?= Date: Sat, 25 Oct 2025 11:42:29 +0200 Subject: [PATCH] feat: add generate-ticket command This is at least useful to git-annex p2p which requires to know about the connection string on the p2p network before it serves connections on it. --- src/main.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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,