Fix a panic when --fingerprint was not provided, and rename it to --dev (#96)

This commit is contained in:
kixelated 2023-10-16 14:31:12 +09:00 committed by GitHub
parent 9a25143694
commit d0fca05485
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 9 deletions

View File

@ -31,7 +31,7 @@ Notable arguments:
- `--listen <ADDR>` Listen on this address, default: `[::]:4443`
- `--cert <CERT>` Use the certificate file at this path
- `--key <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.

View File

@ -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 -- "$@"

View File

@ -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)]

View File

@ -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
// 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 server"),
res = web.unwrap().serve(), if web.is_some() => res.context("failed to run HTTP server"),
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")
}
}