From fef068d8098ed7becd8f63f2498d7a8ecad4db86 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Wed, 28 Aug 2024 13:56:12 +0100 Subject: [PATCH] Fix desktop to support this --- desktop/src-tauri/Cargo.lock | 19 +++++++++++++++++++ desktop/src-tauri/Cargo.toml | 1 + desktop/src-tauri/src/config.rs | 9 --------- desktop/src-tauri/src/main.rs | 16 +++++++--------- desktop/src/configuration.tsx | 1 - desktop/src/configure.tsx | 10 ---------- 6 files changed, 27 insertions(+), 29 deletions(-) diff --git a/desktop/src-tauri/Cargo.lock b/desktop/src-tauri/Cargo.lock index 4855d4e..5afb096 100644 --- a/desktop/src-tauri/Cargo.lock +++ b/desktop/src-tauri/Cargo.lock @@ -68,6 +68,15 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "assert_cfg" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04e2651f366b7ee3f97729fded1441539b49d5f39eeb05b842689e11e84501b2" +dependencies = [ + "const_panic", +] + [[package]] name = "async-stream" version = "0.3.5" @@ -498,6 +507,12 @@ dependencies = [ "libc", ] +[[package]] +name = "const_panic" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7782af8f90fe69a4bb41e460abe1727d493403d8b2cc43201a3a3e906b24379f" + [[package]] name = "convert_case" version = "0.4.0" @@ -1916,6 +1931,7 @@ name = "librqbit-core" version = "4.0.1" dependencies = [ "anyhow", + "assert_cfg", "bytes", "data-encoding", "directories", @@ -1980,6 +1996,7 @@ dependencies = [ name = "librqbit-sha1-wrapper" version = "4.0.0" dependencies = [ + "assert_cfg", "crypto-hash", ] @@ -2034,6 +2051,7 @@ dependencies = [ "librqbit-sha1-wrapper", "librqbit-upnp", "mime_guess", + "network-interface", "parking_lot", "quick-xml 0.36.1", "reqwest", @@ -3051,6 +3069,7 @@ dependencies = [ "anyhow", "base64 0.22.1", "directories", + "gethostname", "http 1.1.0", "librqbit", "parking_lot", diff --git a/desktop/src-tauri/Cargo.toml b/desktop/src-tauri/Cargo.toml index 4efd073..6378cd4 100644 --- a/desktop/src-tauri/Cargo.toml +++ b/desktop/src-tauri/Cargo.toml @@ -31,6 +31,7 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json"] } tracing = "0.1" serde_with = "3.4.0" parking_lot = "0.12.1" +gethostname = "0.5.0" [features] # this feature is used for production builds or when `devPath` points to the filesystem diff --git a/desktop/src-tauri/src/config.rs b/desktop/src-tauri/src/config.rs index 72308f4..bb6dc90 100644 --- a/desktop/src-tauri/src/config.rs +++ b/desktop/src-tauri/src/config.rs @@ -135,9 +135,6 @@ pub struct RqbitDesktopConfigUpnp { #[serde(default)] pub enable_server: bool, - #[serde(default)] - pub server_hostname: Option, - #[serde(default)] pub server_friendly_name: Option, } @@ -183,12 +180,6 @@ impl RqbitDesktopConfig { if self.http_api.listen_addr.ip().is_loopback() { anyhow::bail!("if UPnP server is enabled, you need to set HTTP API IP to 0.0.0.0 or at least non-localhost address.") } - match self.upnp.server_hostname.as_ref().map(|s| s.trim()) { - Some("") | None => { - anyhow::bail!("UPnP hostname must be set to non-empty string") - } - Some(_) => {} - } } Ok(()) } diff --git a/desktop/src-tauri/src/main.rs b/desktop/src-tauri/src/main.rs index 3979182..eecce76 100644 --- a/desktop/src-tauri/src/main.rs +++ b/desktop/src-tauri/src/main.rs @@ -122,13 +122,6 @@ async fn api_from_config( let api = api.clone(); let read_only = config.http_api.read_only; let upnp_router = if config.upnp.enable_server { - let hostname = config - .upnp - .server_hostname - .as_ref() - .map(|h| h.trim()) - .context("empty UPNP hostname")? - .to_owned(); let friendly_name = config .upnp .server_friendly_name @@ -136,10 +129,15 @@ async fn api_from_config( .map(|f| f.trim()) .filter(|s| !s.is_empty()) .map(|s| s.to_owned()) - .unwrap_or_else(|| format!("rqbit@{hostname}")); + .unwrap_or_else(|| { + format!( + "rqbit-desktop@{}", + gethostname::gethostname().to_string_lossy() + ) + }); let mut upnp_adapter = session - .make_upnp_adapter(friendly_name, hostname, config.http_api.listen_addr.port()) + .make_upnp_adapter(friendly_name, config.http_api.listen_addr.port()) .await .context("error starting UPnP server")?; let router = upnp_adapter.take_router()?; diff --git a/desktop/src/configuration.tsx b/desktop/src/configuration.tsx index 7373d67..80f7677 100644 --- a/desktop/src/configuration.tsx +++ b/desktop/src/configuration.tsx @@ -36,7 +36,6 @@ interface RqbitDesktopConfigUpnp { disable: boolean; enable_server: boolean; - server_hostname: string; server_friendly_name: string; } diff --git a/desktop/src/configure.tsx b/desktop/src/configure.tsx index c2fb649..bfe68de 100644 --- a/desktop/src/configure.tsx +++ b/desktop/src/configure.tsx @@ -293,16 +293,6 @@ export const ConfigModal: React.FC<{ help="If enabled, rqbit will advertise the media to supported LAN devices, e.g. TVs." /> - -