diff --git a/flake.lock b/flake.lock index 3f4fd165..0b1c936f 100644 --- a/flake.lock +++ b/flake.lock @@ -258,6 +258,25 @@ "type": "github" } }, + "fenix": { + "inputs": { + "nixpkgs": "nixpkgs_7", + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1734935689, + "narHash": "sha256-yl/iko/0pvRN3PF6Z4FjQeb6AuGiavMENEisQWJ78h0=", + "owner": "nix-community", + "repo": "fenix", + "rev": "30616281e9bfe0883acb3369f2b89aad6850706f", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, "flake-compat": { "locked": { "lastModified": 1696426674, @@ -680,6 +699,22 @@ } }, "nixpkgs_7": { + "locked": { + "lastModified": 1734649271, + "narHash": "sha256-4EVBRhOjMDuGtMaofAIqzJbg4Ql7Ai0PSeuVZTHjyKQ=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "d70bd19e0a38ad4790d3913bf08fcbfc9eeca507", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_8": { "locked": { "lastModified": 1733212471, "narHash": "sha256-M1+uCoV5igihRfcUKrr1riygbe73/dzNnzPsmaLCmpo=", @@ -798,8 +833,26 @@ "root": { "inputs": { "crate2nix": "crate2nix", + "fenix": "fenix", "flake-utils": "flake-utils_6", - "nixpkgs": "nixpkgs_7" + "nixpkgs": "nixpkgs_8" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1734874959, + "narHash": "sha256-NlsVD/fI32wsHFua9Xvc7IFHCUpQIOs6D6RS/3AhMT8=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "fa4a40bbe867ed54f5a7c905b591fd7d60ba35eb", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" } }, "systems": { diff --git a/flake.nix b/flake.nix index 9a46c647..d0006208 100644 --- a/flake.nix +++ b/flake.nix @@ -4,7 +4,8 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; - crate2nix.url = "github:nix-community/crate2nix"; + fenix.url = "github:nix-community/fenix"; + crate2nix.url = "github:nix-community/crate2nix"; }; outputs = inputs@{ flake-utils, crate2nix, ... }: diff --git a/moq-relay/src/web.rs b/moq-relay/src/web.rs index 0aed109d..008125e6 100644 --- a/moq-relay/src/web.rs +++ b/moq-relay/src/web.rs @@ -1,7 +1,7 @@ use std::{net, sync::Arc}; use axum::{extract::State, http::Method, response::IntoResponse, routing::get, Router}; -use hyper_serve::tls_rustls::RustlsAcceptor; +use hyper_serve::accept::DefaultAcceptor; use tower_http::cors::{Any, CorsLayer}; pub struct WebConfig { @@ -13,7 +13,7 @@ pub struct WebConfig { // TODO remove this when Chrome adds support for self-signed certificates using WebTransport pub struct Web { app: Router, - server: hyper_serve::Server, + server: hyper_serve::Server, } impl Web { @@ -22,16 +22,12 @@ impl Web { // TODO serve all of them so we can support multiple signature algorithms. let fingerprint = config.tls.fingerprints.first().expect("missing certificate").clone(); - let mut tls = config.tls.server.expect("missing server configuration"); - tls.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()]; - let tls = hyper_serve::tls_rustls::RustlsConfig::from_config(Arc::new(tls)); - let app = Router::new() .route("/fingerprint", get(serve_fingerprint)) .layer(CorsLayer::new().allow_origin(Any).allow_methods([Method::GET])) .with_state(fingerprint); - let server = hyper_serve::bind_rustls(config.bind, tls); + let server = hyper_serve::bind(config.bind); Self { app, server } } diff --git a/moq-web/src/demo/index.html b/moq-web/src/demo/index.html index 076eac07..e0cd57e5 100644 --- a/moq-web/src/demo/index.html +++ b/moq-web/src/demo/index.html @@ -8,7 +8,7 @@ - + - \ No newline at end of file + diff --git a/moq-web/src/session.rs b/moq-web/src/session.rs index 7d230b74..0b555461 100644 --- a/moq-web/src/session.rs +++ b/moq-web/src/session.rs @@ -3,23 +3,22 @@ use url::Url; use crate::{Error, Result}; -pub async fn connect(addr: &Url) -> Result { +pub async fn connect(addr: &mut Url) -> Result { tracing::info!("connecting to: {}", addr); - if addr.scheme() != "https" { - return Err(Error::InvalidUrl); - } - let client = web_transport::Client::new().congestion_control(web_transport::CongestionControl::LowLatency); - // TODO Unfortunately, WebTransport doesn't work correctly with self-signed certificates. - // Until that gets fixed, we need to perform a HTTP request to fetch the certificate hashes. - let client = match addr.host_str() { - Some("localhost") => { + let client = match addr.scheme() { + "http" => { + // TODO Unfortunately, WebTransport doesn't work correctly with self-signed certificates. + // Until that gets fixed, we need to perform a HTTP request to fetch the certificate hashes. let fingerprint = fingerprint(addr).await?; + // convert the URL back to https for WebTransport + let _ = addr.set_scheme("https"); client.server_certificate_hashes(vec![fingerprint]) } - _ => client, + "https" => client, + _ => return Err(Error::InvalidUrl), }; let session = client.connect(addr).await?; diff --git a/moq-web/src/watch.rs b/moq-web/src/watch.rs index 7eec4aed..0987f69c 100644 --- a/moq-web/src/watch.rs +++ b/moq-web/src/watch.rs @@ -107,7 +107,7 @@ impl WatchBackend { } async fn run(&mut self) -> Result<()> { - let session = super::session::connect(&self.src).await?; + let session = super::session::connect(&mut self.src).await?; let path = self.src.path_segments().ok_or(Error::InvalidUrl)?.collect(); let mut broadcast = moq_karp::BroadcastConsumer::new(session, path); diff --git a/nix/shell.nix b/nix/shell.nix index 75bd7e37..edeb7290 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -1,18 +1,41 @@ -{ self, nixpkgs, flake-utils, ... }: +{ self, nixpkgs, flake-utils, fenix, ... }: flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; in - with pkgs; { - devShells.default = mkShell { - nativeBuildInputs = [ - pkg-config - libressl - cargo - ffmpeg - ]; - LIBCLANG_PATH = "${pkgs.libclang.lib}/lib"; + devShells = { + default = with pkgs; mkShell { + nativeBuildInputs = [ + pkg-config + libressl + cargo + rustfmt + ffmpeg + ]; + LIBCLANG_PATH = "${pkgs.libclang.lib}/lib"; + }; + + web = + let + rustToolchain = with fenix.packages.${system}; + combine [ + latest.rustc + latest.cargo + targets.wasm32-unknown-unknown.latest.rust-std + ]; + in + with pkgs; + mkShell { + nativeBuildInputs = [ + bun + go + nodejs_23 + biome + rustToolchain + wasm-pack + ]; + }; }; } )