reorganize the main of moq-demo-quinn

This commit is contained in:
François Michel 2023-07-15 11:32:42 +00:00
parent 6212dc5e2f
commit 912c438cc9
1 changed files with 13 additions and 14 deletions

View File

@ -7,7 +7,7 @@ use ring::digest::{digest, SHA256};
use tokio::task::JoinSet; use tokio::task::JoinSet;
use warp::Filter; use warp::Filter;
use moq_warp::{relay::{self}, source}; use moq_warp::{relay::{self, broker::Broadcasts}, source};
mod server; mod server;
@ -41,10 +41,6 @@ async fn main() -> anyhow::Result<()> {
// Create a web server to serve the fingerprint // Create a web server to serve the fingerprint
let serve = serve_http(args.clone()); let serve = serve_http(args.clone());
let mut tasks = JoinSet::new();
tasks.spawn(async move {
serve.await.unwrap();
});
// Create a fake media source from disk. // Create a fake media source from disk.
let media = source::File::new(args.media).context("failed to open file source")?; let media = source::File::new(args.media).context("failed to open file source")?;
@ -53,11 +49,6 @@ async fn main() -> anyhow::Result<()> {
broker broker
.announce("quic.video/demo", media.source()) .announce("quic.video/demo", media.source())
.context("failed to announce file source")?; .context("failed to announce file source")?;
let mut tasks = JoinSet::new();
tasks.spawn(async move {
media.run().await.unwrap();
});
// Create a server to actually serve the media // Create a server to actually serve the media
let config = relay::ServerConfig { let config = relay::ServerConfig {
@ -67,8 +58,17 @@ async fn main() -> anyhow::Result<()> {
broker: broker.clone(), broker: broker.clone(),
}; };
let quinn = server::Server::new_quinn_connection(config).unwrap(); tokio::select! {
res = run_server(config, broker) => res.context("failed to run server"),
res = media.run() => res.context("failed to run media source"),
res = serve => res.context("failed to run HTTP server"),
}
}
async fn run_server(config: relay::ServerConfig, broker: Broadcasts) -> anyhow::Result<()> {
let quinn = server::Server::new_quinn_connection(config).unwrap();
let mut tasks = JoinSet::new(); let mut tasks = JoinSet::new();
loop { loop {
let broker = broker.clone(); let broker = broker.clone();
@ -87,8 +87,8 @@ async fn main() -> anyhow::Result<()> {
role, role,
}; };
let session = client_setup.accept(setup_server).await.unwrap(); let session = client_setup.accept(setup_server).await?;
let session = relay::Session::from_transport_session(session, broker.clone()).await.unwrap(); let session = relay::Session::from_transport_session(session, broker.clone()).await?;
session.run().await?; session.run().await?;
let ret: anyhow::Result<()> = Ok(()); let ret: anyhow::Result<()> = Ok(());
ret ret
@ -103,7 +103,6 @@ async fn main() -> anyhow::Result<()> {
}, },
} }
} }
} }
// Run a HTTP server using Warp // Run a HTTP server using Warp