From be4eff59f1d8ac87f2d2a028f4650090abf3cac1 Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Tue, 22 Oct 2024 16:46:07 +0200 Subject: [PATCH 1/3] working implementation --- src-tauri/Cargo.toml | 28 +++++++++++----------- src-tauri/src/binaries/binaries_manager.rs | 2 ++ src-tauri/src/download_utils.rs | 7 ++++-- src-tauri/src/github/mod.rs | 4 +++- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 5ff532d5e..1684b3e2f 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -9,12 +9,12 @@ version = "0.5.42" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [build-dependencies] -tauri-build = {version = "1.5.5", features = ["isolation"]} +tauri-build = {version = "1.5.5", features = ["isolation"] } [dependencies] anyhow = "1" async-trait = "0.1.81" -async_zip = {version = "0.0.17", features = ["full"]} +async_zip = {version = "0.0.17", features = ["full"] } auto-launch = "0.5.0" blake2 = "0.10" chrono = "0.4.38" @@ -29,26 +29,26 @@ keyring = {version = "3.0.5", features = [ "windows-native", "apple-native", "linux-native", -]} +] } libsqlite3-sys = {version = "0.25.1", features = [ "bundled", -]}# Required for tari_wallet +] }# Required for tari_wallet log = "0.4.22" log4rs = "1.3.0" minotari_node_grpc_client = {git = "https://github.com/tari-project/tari.git", branch = "development"} minotari_wallet_grpc_client = {git = "https://github.com/tari-project/tari.git", branch = "development"} -nix = {version = "0.29.0", features = ["signal"]} +nix = {version = "0.29.0", features = ["signal"] } nvml-wrapper = "0.10.0" open = "5" phraze = "0.3.15" rand = "0.8.5" regex = "1.10.5" -reqwest = {version = "0.12.5", features = ["stream", "json", "multipart"]} +reqwest = {version = "0.12.5", features = ["stream", "json", "multipart"] } sanitize-filename = "0.5" semver = "1.0.23" -sentry = {version = "0.34.0", features = ["anyhow"]} +sentry = {version = "0.34.0", features = ["anyhow"] } sentry-tauri = "0.3.0" -serde = {version = "1", features = ["derive"]} +serde = {version = "1", features = ["derive"] } serde_json = "1" sha2 = "0.10.8" sys-locale = "0.3.1" @@ -58,7 +58,7 @@ tari_common = {git = "https://github.com/tari-project/tari.git", branch = "devel tari_common_types = {git = "https://github.com/tari-project/tari.git", branch = "development"} tari_core = {git = "https://github.com/tari-project/tari.git", branch = "development", features = [ "transactions", -]} +] } tari_crypto = "0.20.3" tari_key_manager = {git = "https://github.com/tari-project/tari.git", branch = "development"} tari_shutdown = {git = "https://github.com/tari-project/tari.git", branch = "development"} @@ -78,13 +78,13 @@ tauri = {version = "1.8.0", features = [ "isolation", "shell-open", "process-command-api", -]} +] } tauri-plugin-single-instance = {git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1"} thiserror = "1.0.26" -tokio = {version = "1", features = ["full"]} -tokio-util = {version = "0.7.11", features = ["compat"]} +tokio = {version = "1", features = ["full"] } +tokio-util = {version = "0.7.11", features = ["compat"] } tor-hash-passwd = "1.0.1" -xz2 = {version = "0.1.7", features = ["static"]}# static bind lzma +xz2 = {version = "0.1.7", features = ["static"] }# static bind lzma zip = "2.2.0" [target.'cfg(windows)'.dependencies] @@ -93,7 +93,7 @@ winreg = "0.52.0" # needed for keymanager. TODO: Find a way of creating a keymanager without bundling sqlite chrono = "0.4.38" device_query = "2.1.0" -libsqlite3-sys = {version = "0.25.1", features = ["bundled"]} +libsqlite3-sys = {version = "0.25.1", features = ["bundled"] } log = "0.4.22" nvml-wrapper = "0.10.0" rand = "0.8.5" diff --git a/src-tauri/src/binaries/binaries_manager.rs b/src-tauri/src/binaries/binaries_manager.rs index 1172493a4..927f8a6cd 100644 --- a/src-tauri/src/binaries/binaries_manager.rs +++ b/src-tauri/src/binaries/binaries_manager.rs @@ -401,10 +401,12 @@ impl BinaryManager { .map_err(|e| anyhow!("Error creating in progress folder. Error: {:?}", e))?; let in_progress_file_zip = in_progress_dir.join(asset.name.clone()); + let user_agent = format!("universe {}({}) | {}", env!("CARGO_PKG_VERSION"),std::env::consts::OS, self.binary_name); download_file_with_retries( asset.url.as_str(), &in_progress_file_zip, progress_tracker.clone(), + user_agent.as_str() ) .await .map_err(|e| anyhow!("Error downloading version: {:?}. Error: {:?}", version, e))?; diff --git a/src-tauri/src/download_utils.rs b/src-tauri/src/download_utils.rs index 6ba21eb5d..22b74b98c 100644 --- a/src-tauri/src/download_utils.rs +++ b/src-tauri/src/download_utils.rs @@ -22,10 +22,11 @@ pub async fn download_file_with_retries( url: &str, destination: &Path, progress_tracker: ProgressTracker, + user_agent: &str, ) -> Result<(), Error> { let mut retries = 0; loop { - match download_file(url, destination, progress_tracker.clone()).await { + match download_file(url, destination, progress_tracker.clone(),user_agent).await { Ok(_) => return Ok(()), Err(err) => { if retries >= 3 { @@ -43,8 +44,10 @@ async fn download_file( url: &str, destination: &Path, progress_tracker: ProgressTracker, + user_agent: &str, ) -> Result<(), anyhow::Error> { - let response = reqwest::get(url).await?; + let client = reqwest::Client::new(); + let response = client.get(url).header("User-Agent", user_agent).send().await?; // Ensure the directory exists if let Some(parent) = destination.parent() { diff --git a/src-tauri/src/github/mod.rs b/src-tauri/src/github/mod.rs index 9309ce779..982fe2201 100644 --- a/src-tauri/src/github/mod.rs +++ b/src-tauri/src/github/mod.rs @@ -107,9 +107,11 @@ async fn list_releases_from( ReleaseSource::Mirror => get_mirror_url(repo_owner, repo_name), }; + let user_agent = format!("universe {}({}) | {}", env!("CARGO_PKG_VERSION"),std::env::consts::OS, repo_name); + let response = client .get(&url) - .header("User-Agent", "request") + .header("User-Agent", user_agent) .send() .await?; if response.status() != 200 { From d78df1f53feece44de293d8b626a585d72bd6cd6 Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Tue, 22 Oct 2024 16:48:58 +0200 Subject: [PATCH 2/3] cargo fmt --- src-tauri/src/binaries/binaries_manager.rs | 9 +++++++-- src-tauri/src/download_utils.rs | 10 +++++++--- src-tauri/src/github/mod.rs | 7 ++++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/binaries/binaries_manager.rs b/src-tauri/src/binaries/binaries_manager.rs index 927f8a6cd..2ff279420 100644 --- a/src-tauri/src/binaries/binaries_manager.rs +++ b/src-tauri/src/binaries/binaries_manager.rs @@ -401,12 +401,17 @@ impl BinaryManager { .map_err(|e| anyhow!("Error creating in progress folder. Error: {:?}", e))?; let in_progress_file_zip = in_progress_dir.join(asset.name.clone()); - let user_agent = format!("universe {}({}) | {}", env!("CARGO_PKG_VERSION"),std::env::consts::OS, self.binary_name); + let user_agent = format!( + "universe {}({}) | {}", + env!("CARGO_PKG_VERSION"), + std::env::consts::OS, + self.binary_name + ); download_file_with_retries( asset.url.as_str(), &in_progress_file_zip, progress_tracker.clone(), - user_agent.as_str() + user_agent.as_str(), ) .await .map_err(|e| anyhow!("Error downloading version: {:?}. Error: {:?}", version, e))?; diff --git a/src-tauri/src/download_utils.rs b/src-tauri/src/download_utils.rs index 22b74b98c..46e1fd931 100644 --- a/src-tauri/src/download_utils.rs +++ b/src-tauri/src/download_utils.rs @@ -26,7 +26,7 @@ pub async fn download_file_with_retries( ) -> Result<(), Error> { let mut retries = 0; loop { - match download_file(url, destination, progress_tracker.clone(),user_agent).await { + match download_file(url, destination, progress_tracker.clone(), user_agent).await { Ok(_) => return Ok(()), Err(err) => { if retries >= 3 { @@ -44,10 +44,14 @@ async fn download_file( url: &str, destination: &Path, progress_tracker: ProgressTracker, - user_agent: &str, + user_agent: &str, ) -> Result<(), anyhow::Error> { let client = reqwest::Client::new(); - let response = client.get(url).header("User-Agent", user_agent).send().await?; + let response = client + .get(url) + .header("User-Agent", user_agent) + .send() + .await?; // Ensure the directory exists if let Some(parent) = destination.parent() { diff --git a/src-tauri/src/github/mod.rs b/src-tauri/src/github/mod.rs index 982fe2201..9741311a6 100644 --- a/src-tauri/src/github/mod.rs +++ b/src-tauri/src/github/mod.rs @@ -107,7 +107,12 @@ async fn list_releases_from( ReleaseSource::Mirror => get_mirror_url(repo_owner, repo_name), }; - let user_agent = format!("universe {}({}) | {}", env!("CARGO_PKG_VERSION"),std::env::consts::OS, repo_name); + let user_agent = format!( + "universe {}({}) | {}", + env!("CARGO_PKG_VERSION"), + std::env::consts::OS, + repo_name + ); let response = client .get(&url) From 6a48f87466b79c1f881d5cfeabdf15c2413f34d1 Mon Sep 17 00:00:00 2001 From: Misieq01 Date: Wed, 23 Oct 2024 09:57:27 +0200 Subject: [PATCH 3/3] fix lint --- src-tauri/src/binaries/adapter_github.rs | 9 ++++++++- src-tauri/src/binaries/adapter_tor.rs | 9 ++++++++- src-tauri/src/tor_adapter.rs | 4 ---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/binaries/adapter_github.rs b/src-tauri/src/binaries/adapter_github.rs index bc7f09079..bd1522980 100644 --- a/src-tauri/src/binaries/adapter_github.rs +++ b/src-tauri/src/binaries/adapter_github.rs @@ -41,7 +41,14 @@ impl LatestVersionApiAdapter for GithubReleasesAdapter { .join(format!("{}.sha256", asset.name)); let checksum_url = format!("{}.sha256", asset.url); - match download_file_with_retries(&checksum_url, &checksum_path, progress_tracker).await { + let user_agent = format!( + "universe {}({}) | {}", + env!("CARGO_PKG_VERSION"), + std::env::consts::OS, + "github adapter" + ); + + match download_file_with_retries(&checksum_url, &checksum_path, progress_tracker, user_agent.as_str()).await { Ok(_) => Ok(checksum_path), Err(e) => { error!(target: LOG_TARGET, "Failed to download checksum file: {}", e); diff --git a/src-tauri/src/binaries/adapter_tor.rs b/src-tauri/src/binaries/adapter_tor.rs index 0cb8ae751..cca46e545 100644 --- a/src-tauri/src/binaries/adapter_tor.rs +++ b/src-tauri/src/binaries/adapter_tor.rs @@ -71,7 +71,14 @@ impl LatestVersionApiAdapter for TorReleaseAdapter { .join(format!("{}.asc", asset.name)); let checksum_url = format!("{}.asc", asset.url); - match download_file_with_retries(&checksum_url, &checksum_path, progress_tracker).await { + let user_agent = format!( + "universe {}({}) | {}", + env!("CARGO_PKG_VERSION"), + std::env::consts::OS, + "github adapter" + ); + + match download_file_with_retries(&checksum_url, &checksum_path, progress_tracker, user_agent.as_str()).await { Ok(_) => Ok(checksum_path), Err(e) => { error!(target: LOG_TARGET, "Failed to download checksum file: {}", e); diff --git a/src-tauri/src/tor_adapter.rs b/src-tauri/src/tor_adapter.rs index ce3d76105..98fbf008b 100644 --- a/src-tauri/src/tor_adapter.rs +++ b/src-tauri/src/tor_adapter.rs @@ -6,7 +6,6 @@ use log::{debug, info}; use serde::{Deserialize, Serialize}; use tari_shutdown::Shutdown; use tokio::fs; -use tor_hash_passwd::EncryptedKey; use crate::{ process_adapter::{ @@ -19,7 +18,6 @@ const LOG_TARGET: &str = "tari::universe::tor_adapter"; pub(crate) struct TorAdapter { socks_port: u16, - password: String, config_file: Option, config: TorConfig, } @@ -27,11 +25,9 @@ pub(crate) struct TorAdapter { impl TorAdapter { pub fn new() -> Self { let socks_port = 9050; - let password = "tari is the best".to_string(); Self { socks_port, - password, config_file: None, config: TorConfig::default(), }