From d0fca054854bdccc036eaebc8a5d8504f1ce3670 Mon Sep 17 00:00:00 2001 From: kixelated Date: Mon, 16 Oct 2023 14:31:12 +0900 Subject: [PATCH] Fix a panic when --fingerprint was not provided, and rename it to --dev (#96) --- README.md | 2 +- dev/relay | 2 +- moq-relay/src/config.rs | 2 +- moq-relay/src/main.rs | 16 ++++++++++------ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f259b17..43cc663 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Notable arguments: - `--listen ` Listen on this address, default: `[::]:4443` - `--cert ` Use the certificate file at this path - `--key ` Use the private key at this path -- `--fingerprint` Listen via HTTPS as well, serving the `/fingerprint` of the self-signed certificate. (dev only) +- `--dev` Listen via HTTPS as well, serving the `/fingerprint` of the self-signed certificate. (dev only) This listens for WebTransport connections on `UDP https://localhost:4443` by default. You need a client to connect to that address, to both publish and consume media. diff --git a/dev/relay b/dev/relay index 175f871..e8f707f 100755 --- a/dev/relay +++ b/dev/relay @@ -34,4 +34,4 @@ fi echo "Publish URL: https://quic.video/publish/?server=localhost:${PORT}" # Run the relay and forward any arguments -cargo run --bin moq-relay -- --listen "$LISTEN" --cert "$CERT" --key "$KEY" --fingerprint $ARGS -- "$@" +cargo run --bin moq-relay -- --listen "$LISTEN" --cert "$CERT" --key "$KEY" --dev $ARGS -- "$@" diff --git a/moq-relay/src/config.rs b/moq-relay/src/config.rs index c70c663..e8accf8 100644 --- a/moq-relay/src/config.rs +++ b/moq-relay/src/config.rs @@ -26,7 +26,7 @@ pub struct Config { /// Listen on HTTPS and serve /fingerprint, for self-signed certificates #[arg(long, action)] - pub fingerprint: bool, + pub dev: bool, /// Optional: Use the moq-api via HTTP to store origin information. #[arg(long)] diff --git a/moq-relay/src/main.rs b/moq-relay/src/main.rs index 1e13725..8239d7e 100644 --- a/moq-relay/src/main.rs +++ b/moq-relay/src/main.rs @@ -35,13 +35,17 @@ async fn main() -> anyhow::Result<()> { .await .context("failed to create server")?; - // Create the web server if the --fingerprint flag was set. + // Create the web server if the --dev flag was set. // This is currently only useful in local development so it's not enabled by default. - let web = config.fingerprint.then(|| Web::new(config, tls)); + if config.dev { + let web = Web::new(config, tls); - // Run all of the above - tokio::select! { - res = quic.serve() => res.context("failed to run server"), - res = web.unwrap().serve(), if web.is_some() => res.context("failed to run HTTP server"), + // Unfortunately we can't use preconditions because Tokio still executes the branch; just ignore the result + tokio::select! { + res = quic.serve() => res.context("failed to run quic server"), + res = web.serve() => res.context("failed to run web server"), + } + } else { + quic.serve().await.context("failed to run quic server") } }