From 73f450aa912856c5aa94c91911307f5eeb0a6a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zafer=20G=C3=BCrel?= Date: Thu, 7 Sep 2023 22:59:49 +0300 Subject: [PATCH] moq-pub: Avoid namespace conflict (#66) namespace as a command line argument or assign a unique (uuid4) value. --------- Co-authored-by: Zafer Gurel --- Cargo.lock | 23 +++++++++++++++++++++++ moq-pub/Cargo.toml | 8 ++++++++ moq-pub/src/cli.rs | 3 +++ moq-pub/src/main.rs | 11 ++++++++--- moq-pub/src/media.rs | 3 +-- 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6ed9c03..2e25ce5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -958,6 +958,7 @@ dependencies = [ "rustls-pemfile", "serde_json", "tokio", + "uuid", "webtransport-generic", "webtransport-quinn", ] @@ -1890,6 +1891,28 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +[[package]] +name = "uuid" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" +dependencies = [ + "getrandom", + "rand", + "uuid-macro-internal", +] + +[[package]] +name = "uuid-macro-internal" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7e1ba1f333bd65ce3c9f27de592fcbc256dafe3af2717f56d7c87761fbaccf4" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "value-bag" version = "1.4.1" diff --git a/moq-pub/Cargo.toml b/moq-pub/Cargo.toml index 7d75245..cf0b343 100644 --- a/moq-pub/Cargo.toml +++ b/moq-pub/Cargo.toml @@ -46,3 +46,11 @@ rfc6381-codec = "0.1.0" http = "0.2.9" clap = { version = "4.0", features = ["derive"] } clap_mangen = "0.2.12" + +[dependencies.uuid] +version = "1.4.1" +features = [ + "v4", # Lets you generate random UUIDs + "fast-rng", # Use a faster (but still sufficiently random) RNG + "macro-diagnostics", # Enable better diagnostics for compile-time UUIDs +] diff --git a/moq-pub/src/cli.rs b/moq-pub/src/cli.rs index a76ef55..1e714c0 100644 --- a/moq-pub/src/cli.rs +++ b/moq-pub/src/cli.rs @@ -18,6 +18,9 @@ pub struct Config { #[arg(long, hide_short_help = true, default_value = "1500000")] pub catalog_bit_rate: u32, + + #[arg(short, long, required = false, default_value = "")] + pub namespace: String, } fn input_parser(s: &str) -> Result { diff --git a/moq-pub/src/main.rs b/moq-pub/src/main.rs index 8e285c8..92ed357 100644 --- a/moq-pub/src/main.rs +++ b/moq-pub/src/main.rs @@ -17,13 +17,19 @@ use media::*; mod cli; use cli::*; +use uuid::Uuid; + // TODO: clap complete #[tokio::main] async fn main() -> anyhow::Result<()> { env_logger::init(); - let config = Config::parse(); + let mut config = Config::parse(); + + if config.namespace.is_empty() { + config.namespace = format!("quic.video/{}", Uuid::new_v4()); + } let mut media = Media::new(&config).await?; let session_runner = SessionRunner::new(&config).await?; @@ -40,8 +46,7 @@ async fn main() -> anyhow::Result<()> { join_set.spawn(async { session_runner.run().await.context("failed to run session runner") }); join_set.spawn(async move { log_viewer.run().await.context("failed to run media source") }); - // TODO: generate unique namespace with UUID and/or take a command line arg - media_runner.announce("quic.video/moq-pub-foo", media.source()).await?; + media_runner.announce(&config.namespace, media.source()).await?; join_set.spawn(async move { media.run().await.context("failed to run media source") }); join_set.spawn(async move { media_runner.run().await.context("failed to run client") }); diff --git a/moq-pub/src/media.rs b/moq-pub/src/media.rs index b8f9975..650d411 100644 --- a/moq-pub/src/media.rs +++ b/moq-pub/src/media.rs @@ -64,10 +64,9 @@ impl Media { } // Create the catalog track - let namespace = "quic.video/moq-pub-foo"; let (_catalog, subscriber) = Self::create_catalog( config, - namespace.to_string(), + config.namespace.to_string(), init_track_name.to_string(), &moov, &tracks,