Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
fix(net): custom DNS resolver with public fallback for zero-config platforms
Samir Hossainsd1c630f3a836
diff --git a/Cargo.lock b/Cargo.lockindex e81b213..ee4d874 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1636,6 +1636,7 @@ dependencies = ["flate2","flexi_logger","futures",+ "hickory-resolver","hmac","image","log",@@ -2497,7 +2498,6 @@ dependencies = ["base64 0.22.1","bytes","futures-core",- "hickory-resolver","http","http-body","http-body-util",@@ -2506,7 +2506,6 @@ dependencies = ["hyper-util","js-sys","log",- "once_cell","percent-encoding","pin-project-lite","quinn",diff --git a/Cargo.toml b/Cargo.tomlindex 8001208..df27c59 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -49,7 +49,8 @@ open = "5.4.0"percent-encoding = "2.3.2"log = "0.4.33"flexi_logger = "0.31.10"-reqwest = { version = "0.12.12", default-features = false, features = ["json", "rustls-tls-webpki-roots", "hickory-dns"] }+hickory-resolver = { version = "0.25.2", default-features = false, features = ["system-config", "tokio"] }+reqwest = { version = "0.12.12", default-features = false, features = ["json", "rustls-tls-webpki-roots"] }sha2 = "0.10.8"flate2 = "1.0.35"tar = "0.4.44"diff --git a/docs/cross-platform.md b/docs/cross-platform.mdindex c910ab0..e339540 100644--- a/docs/cross-platform.md+++ b/docs/cross-platform.md@@ -15,7 +15,7 @@ the release checks in [`release-checklist.md`](release-checklist.md).| macOS | IINA preferred player (via the installed IINA `iina-cli`); VLC/mpv `.app` paths detected. `process_group(0)` on spawn. || Windows | mpv/VLC detected via Program Files + `%LOCALAPPDATA%`; path-safe file stems; static MSVC CRT linking (`+crt-static`) for zero-dependency standalone binaries. || Linux | Flatpak mpv/VLC supported (`flatpak run …`); xdg data/cache dirs. |-| Android (Termux) | Uses the Linux ARM64 binary with pure-Rust async DNS (`hickory-dns`) for zero-config name resolution and dynamically checks for `termux-open`, `termux-open-url`, `termux-am`, or in-terminal `mpv`; playback strips `LD_LIBRARY_PATH` and `LD_PRELOAD` before launching the chooser. Android intent playback cannot forward stream headers or attach subtitles. Real-device chooser behavior is a release prerequisite; Proot/Termux X11 behavior is unsupported unless separately tested. |+| Android (Termux) | Uses the Linux ARM64 binary with a pure-Rust DNS resolver that reads the system configuration when available and otherwise falls back to public resolvers (Cloudflare, Google, Quad9) for zero-config name resolution, and dynamically checks for `termux-open`, `termux-open-url`, `termux-am`, or in-terminal `mpv`; playback strips `LD_LIBRARY_PATH` and `LD_PRELOAD` before launching the chooser. Android intent playback cannot forward stream headers or attach subtitles. Real-device chooser behavior is a release prerequisite; Proot/Termux X11 behavior is unsupported unless separately tested. |## Terminal capabilities@@ -28,7 +28,11 @@ The app probes the terminal at startup via `ratatui_image`:## Network & TLS portability- **TLS Engine**: Uses `rustls` with embedded Mozilla roots (`webpki-roots`) across all targets (macOS, Linux, Windows, Android/Termux). The release binary has no OpenSSL runtime dependency; the `ring` cryptography backend is compiled into the binary by the platform build toolchain.-- **DNS Resolution**: Uses standard POSIX/WinSock system DNS (`getaddrinfo`) on all platforms, without requiring JNI or `ndk-context`.+- **DNS Resolution**: Pure-Rust resolver (hickory) on all platforms: it reads the OS+ configuration first (`/etc/resolv.conf`, registry on Windows) and falls back to+ embedded public resolvers (Cloudflare `1.1.1.1`, Google `8.8.8.8`, Quad9 `9.9.9.9`)+ when no system configuration exists — as on Android/Termux or minimal containers.+ No JNI or `ndk-context` required.## Things to verify per releasediff --git a/src/lib.rs b/src/lib.rsindex e89da35..d85e659 100644--- a/src/lib.rs+++ b/src/lib.rs@@ -5,6 +5,7 @@ pub mod favorites;pub mod history;pub mod logging;pub mod models;+pub mod net;pub mod player;pub mod providers;pub mod service;diff --git a/src/net.rs b/src/net.rsnew file mode 100644index 0000000..29898ba--- /dev/null+++ b/src/net.rs@@ -0,0 +1,115 @@+use std::net::SocketAddr;+use std::sync::{Arc, OnceLock};++use hickory_resolver::TokioResolver;+use hickory_resolver::config::{+ CLOUDFLARE_IPS, GOOGLE_IPS, LookupIpStrategy, NameServerConfigGroup, QUAD9_IPS, ResolverConfig,+};+use hickory_resolver::name_server::TokioConnectionProvider;+use reqwest::dns::{Addrs, Name, Resolve, Resolving};++const FALLBACK_DNS_PORT: u16 = 53;++#[derive(Debug, Default, Clone)]+pub struct FallbackResolver {+ inner: Arc<OnceLock<Arc<TokioResolver>>>,+}++impl FallbackResolver {+ pub fn new() -> Self {+ Self::default()+ }+}++fn fallback_servers() -> Vec<std::net::IpAddr> {+ let mut servers = Vec::with_capacity(CLOUDFLARE_IPS.len() + GOOGLE_IPS.len() + QUAD9_IPS.len());+ servers.extend_from_slice(CLOUDFLARE_IPS);+ servers.extend_from_slice(GOOGLE_IPS);+ servers.extend_from_slice(QUAD9_IPS);+ servers+}++fn fallback_config() -> ResolverConfig {+ ResolverConfig::from_parts(+ None,+ Vec::new(),+ NameServerConfigGroup::from_ips_clear(&fallback_servers(), FALLBACK_DNS_PORT, true),+ )+}++fn build_resolver() -> TokioResolver {+ let mut builder = match TokioResolver::builder_tokio() {+ Ok(builder) => builder,+ Err(_) => TokioResolver::builder_with_config(+ fallback_config(),+ TokioConnectionProvider::default(),+ ),+ };+ builder.options_mut().ip_strategy = LookupIpStrategy::Ipv4AndIpv6;+ builder.build()+}++impl Resolve for FallbackResolver {+ fn resolve(&self, name: Name) -> Resolving {+ let inner = Arc::clone(&self.inner);+ Box::pin(async move {+ let resolver = inner.get_or_init(|| Arc::new(build_resolver()));+ let lookup = resolver.lookup_ip(name.as_str()).await?;+ let addrs: Addrs = Box::new(+ lookup+ .into_iter()+ .map(|address| SocketAddr::new(address, 0)),+ );+ Ok(addrs)+ })+ }+}++pub fn http_client_builder() -> reqwest::ClientBuilder {+ reqwest::Client::builder().dns_resolver(Arc::new(FallbackResolver::new()))+}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn fallback_config_contains_public_resolvers() {+ let config = fallback_config();+ let servers = config.name_servers();+ assert!(servers.len() >= 12);+ assert!(servers.iter().any(|server| server.socket_addr.ip()+ == std::net::IpAddr::V4(std::net::Ipv4Addr::new(1, 1, 1, 1))));+ assert!(+ servers+ .iter()+ .any(|server| server.socket_addr.port() == FALLBACK_DNS_PORT)+ );+ }++ #[test]+ fn fallback_servers_deduplicate_nothing_and_cover_all_providers() {+ let servers = fallback_servers();+ assert_eq!(+ servers.len(),+ CLOUDFLARE_IPS.len() + GOOGLE_IPS.len() + QUAD9_IPS.len()+ );+ }++ #[tokio::test]+ async fn built_resolver_prefers_ipv4_and_ipv6_lookup() {+ let resolver = build_resolver();+ assert_eq!(+ resolver.options().ip_strategy,+ LookupIpStrategy::Ipv4AndIpv6+ );+ }++ #[test]+ fn clones_share_lazy_state_slot() {+ let original = FallbackResolver::new();+ let clone = original.clone();+ assert!(original.inner.get().is_none());+ assert!(clone.inner.get().is_none());+ }+}diff --git a/src/providers/addons/client.rs b/src/providers/addons/client.rsindex 1b68dea..9b5b098 100644--- a/src/providers/addons/client.rs+++ b/src/providers/addons/client.rs@@ -15,7 +15,7 @@ impl Default for AddonClient {impl AddonClient {pub fn new() -> Self {- let http = Client::builder()+ let http = crate::net::http_client_builder().timeout(Duration::from_secs(12)).connect_timeout(Duration::from_secs(8)).user_agent("MovieBox-Tui/1.0 (Addon-Client)")diff --git a/src/providers/bdix/circleftp/client.rs b/src/providers/bdix/circleftp/client.rsindex 498e23e..a0dd16e 100644--- a/src/providers/bdix/circleftp/client.rs+++ b/src/providers/bdix/circleftp/client.rs@@ -333,7 +333,7 @@ impl CircleFtpClient {}fn build_client() -> reqwest::Client {- reqwest::Client::builder()+ crate::net::http_client_builder().timeout(Duration::from_secs(5)).build().unwrap_or_else(|_| reqwest::Client::new())diff --git a/src/providers/bdix/dhakaflix/client.rs b/src/providers/bdix/dhakaflix/client.rsindex ffd3125..5f6c7fa 100644--- a/src/providers/bdix/dhakaflix/client.rs+++ b/src/providers/bdix/dhakaflix/client.rs@@ -83,7 +83,7 @@ impl Default for DhakaFlixClient {impl DhakaFlixClient {pub fn new() -> Self {Self {- client: reqwest::Client::builder()+ client: crate::net::http_client_builder().timeout(Duration::from_secs(5)).user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36").build()diff --git a/src/providers/fourkhdhub/client.rs b/src/providers/fourkhdhub/client.rsindex b7dec2b..9de3a4b 100644--- a/src/providers/fourkhdhub/client.rs+++ b/src/providers/fourkhdhub/client.rs@@ -231,7 +231,7 @@ impl FourKHdHubClient {}fn build_client() -> reqwest::Client {- reqwest::Client::builder()+ crate::net::http_client_builder().timeout(std::time::Duration::from_secs(20)).connect_timeout(std::time::Duration::from_secs(5)).user_agent(BROWSER_UA)diff --git a/src/providers/moviebox/client.rs b/src/providers/moviebox/client.rsindex 60c81d0..4a6accb 100644--- a/src/providers/moviebox/client.rs+++ b/src/providers/moviebox/client.rs@@ -47,7 +47,7 @@ impl Default for MovieBoxClient {impl MovieBoxClient {pub fn new() -> Self {- let client = reqwest::Client::builder()+ let client = crate::net::http_client_builder().timeout(std::time::Duration::from_secs(12)).connect_timeout(std::time::Duration::from_secs(3)).tcp_keepalive(std::time::Duration::from_secs(30))diff --git a/src/providers/tv/parser.rs b/src/providers/tv/parser.rsindex 9040419..eaadbc4 100644--- a/src/providers/tv/parser.rs+++ b/src/providers/tv/parser.rs@@ -17,7 +17,7 @@ impl M3UParser {pub fn new() -> Self {let cache_dir = crate::config::cache_dir().join("tv_playlists");std::fs::create_dir_all(&cache_dir).ok();- let client = reqwest::Client::builder()+ let client = crate::net::http_client_builder().connect_timeout(std::time::Duration::from_secs(10)).timeout(std::time::Duration::from_secs(30)).build()diff --git a/src/service.rs b/src/service.rsindex 65cc24f..edc6a56 100644--- a/src/service.rs+++ b/src/service.rs@@ -27,7 +27,7 @@ impl Default for MovieBoxService {impl MovieBoxService {pub fn new() -> Self {- let http_client = reqwest::Client::builder()+ let http_client = crate::net::http_client_builder().timeout(std::time::Duration::from_secs(15)).build().unwrap_or_default();@@ -362,6 +362,14 @@ pub async fn decode_poster(bytes: Vec<u8>) -> Option<Arc<image::DynamicImage>> {.map(Arc::new)}+pub fn downscale_for_cache(img: &Arc<image::DynamicImage>) -> Arc<image::DynamicImage> {+ const MAX_DIM: u32 = 512;+ if img.width().max(img.height()) <= MAX_DIM {+ return Arc::clone(img);+ }+ Arc::new(img.resize(MAX_DIM, MAX_DIM, image::imageops::FilterType::Triangle))+}+pub fn extract_cover_url(val: &serde_json::Value) -> Option<String> {let keys = ["cover",diff --git a/src/tui/app/download.rs b/src/tui/app/download.rsindex 22ebce4..d257ed4 100644--- a/src/tui/app/download.rs+++ b/src/tui/app/download.rs@@ -124,7 +124,7 @@ impl App {let cancel = self.state.cancel_download.clone();let sender = self.action_sender.clone();- let client = reqwest::Client::builder()+ let client = crate::net::http_client_builder().connect_timeout(std::time::Duration::from_secs(15)).tcp_keepalive(std::time::Duration::from_secs(30)).build()diff --git a/src/updater/check.rs b/src/updater/check.rsindex d7970f0..87d5219 100644--- a/src/updater/check.rs+++ b/src/updater/check.rs@@ -109,7 +109,7 @@ async fn fetch_latest_tag() -> Result<String, String> {}pub(crate) fn http_client() -> Result<reqwest::Client, String> {- reqwest::Client::builder()+ crate::net::http_client_builder().user_agent("MovieBox-Tui").timeout(std::time::Duration::from_secs(30)).connect_timeout(std::time::Duration::from_secs(10))