Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve cdn downloads #935

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7549183
working implementation
Misieq01 Oct 22, 2024
a6867cc
Delete tari-win-bundler directory
Misieq01 Oct 22, 2024
2a5a426
cargo fmt, cleanup
Misieq01 Oct 22, 2024
e726822
Merge branch 'main' into fix/reduce-requests-to-tari-suite
Misieq01 Oct 22, 2024
53048ec
Merge branch 'main' into fix/reduce-requests-to-tari-suite
Misieq01 Oct 22, 2024
bb447fc
Merge branch 'main' into fix/reduce-requests-to-tari-suite
Misieq01 Oct 23, 2024
7bbb828
fix lint
Misieq01 Oct 23, 2024
e5c5aae
Merge remote-tracking branch 'upstream/fix/reduce-requests-to-tari-su…
Misieq01 Oct 23, 2024
27178a5
save
Misieq01 Oct 24, 2024
422df6a
save
Misieq01 Oct 24, 2024
def934a
working implementation
Misieq01 Oct 25, 2024
03c73b0
Merge remote-tracking branch 'origin' into feat/improve-cdn-downloads
Misieq01 Oct 25, 2024
c86bdd4
remove old cache system
Misieq01 Oct 25, 2024
f018a2a
Extend cache code behaviours and reduce requests send
Misieq01 Oct 25, 2024
1730e32
add sleep time based on content length
Misieq01 Oct 25, 2024
2c74fdf
include http status handling
Misieq01 Oct 25, 2024
d3e1c8c
cargo fmt
Misieq01 Oct 25, 2024
882400a
fix lock's issues
Misieq01 Oct 25, 2024
3a546b5
mvp
Misieq01 Oct 25, 2024
964edc2
bring back tor and shouldupdate check
Misieq01 Oct 25, 2024
11b000b
part of cleanup
Misieq01 Oct 25, 2024
7d79388
Remove misplaced folder
Misieq01 Oct 25, 2024
fae3a14
rest of cleanup
Misieq01 Oct 25, 2024
190c7eb
Merge remote-tracking branch 'origin' into feat/improve-cdn-downloads
Misieq01 Oct 25, 2024
55e6ef7
cargo fmt and lints fix
Misieq01 Oct 25, 2024
c4a65fd
cargo fmt and lints fix
Misieq01 Oct 25, 2024
99b42cd
fix timeout calculation
Misieq01 Oct 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ version = "0.5.46"
# 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"
Expand All @@ -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"
Expand All @@ -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.21.0"
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"}
Expand All @@ -80,12 +80,12 @@ tauri = {version = "1.8.0", features = [
"icon-ico",
"icon-png",
"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"]}
xz2 = {version = "0.1.7", features = ["static"]}# static bind lzma
tokio = {version = "1", features = ["full"] }
tokio-util = {version = "0.7.11", features = ["compat"] }
xz2 = {version = "0.1.7", features = ["static"] }# static bind lzma
zip = "2.2.0"

[target.'cfg(windows)'.dependencies]
Expand All @@ -94,7 +94,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"
Expand Down
10 changes: 9 additions & 1 deletion src-tauri/src/binaries/adapter_github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use tari_common::configuration::Network;
use tauri::api::path::cache_dir;

use crate::{
download_utils::download_file_with_retries, github, progress_tracker::ProgressTracker,
download_utils::download_file_with_retries,
github::{self, request_client::RequestClient},
progress_tracker::ProgressTracker,
APPLICATION_FOLDER_ID,
};

Expand Down Expand Up @@ -41,6 +43,12 @@ impl LatestVersionApiAdapter for GithubReleasesAdapter {
.join(format!("{}.sha256", asset.name));
let checksum_url = format!("{}.sha256", asset.url);

if asset.source.is_mirror() {
RequestClient::current()
.check_if_cache_hits(checksum_url.as_str())
.await?;
}

match download_file_with_retries(&checksum_url, &checksum_path, progress_tracker).await {
Ok(_) => Ok(checksum_path),
Err(e) => {
Expand Down
22 changes: 8 additions & 14 deletions src-tauri/src/binaries/adapter_tor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use crate::binaries::binaries_resolver::{
LatestVersionApiAdapter, VersionAsset, VersionDownloadInfo,
};
use crate::download_utils::download_file_with_retries;
use crate::github::request_client::RequestClient;
use crate::github::ReleaseSource;
use crate::progress_tracker::ProgressTracker;
use crate::APPLICATION_FOLDER_ID;
use anyhow::Error;
Expand All @@ -22,27 +24,18 @@ impl LatestVersionApiAdapter for TorReleaseAdapter {
"https://cdn-universe.tari.com/torbrowser/13.5.7/tor-expert-bundle-{}-13.5.7.tar.gz",
platform
);
let mut cdn_responded = false;

let client = reqwest::Client::new();
for _ in 0..3 {
let cloned_cdn_tor_bundle_url = cdn_tor_bundle_url.clone();
let response = client.head(cloned_cdn_tor_bundle_url).send().await;

if let Ok(resp) = response {
if resp.status().is_success() {
cdn_responded = true;
break;
}
}
}

let cdn_responded = RequestClient::current()
.check_if_cache_hits(cdn_tor_bundle_url.as_str())
.await?;

if cdn_responded {
let version = VersionDownloadInfo {
version: "13.5.7".parse().expect("Bad tor version"),
assets: vec![VersionAsset {
url: cdn_tor_bundle_url.to_string(),
name: format!("tor-expert-bundle-{}-13.5.7.tar.gz", platform),
source: ReleaseSource::Mirror,
}],
};
return Ok(vec![version]);
Expand All @@ -54,6 +47,7 @@ impl LatestVersionApiAdapter for TorReleaseAdapter {
assets: vec![VersionAsset {
url: format!("https://dist.torproject.org/torbrowser/13.5.7/tor-expert-bundle-{}-13.5.7.tar.gz", platform),
name: format!("tor-expert-bundle-{}-13.5.7.tar.gz", platform),
source: ReleaseSource::Github
}]
};
Ok(vec![version])
Expand Down
7 changes: 7 additions & 0 deletions src-tauri/src/binaries/binaries_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use tari_common::configuration::Network;

use crate::{
download_utils::{download_file_with_retries, extract, validate_checksum},
github::request_client::RequestClient,
progress_tracker::ProgressTracker,
};

Expand Down Expand Up @@ -426,6 +427,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());

if asset.source.is_mirror() {
RequestClient::current()
.check_if_cache_hits(asset.url.as_str())
.await?;
}

download_file_with_retries(
asset.url.as_str(),
&in_progress_file_zip,
Expand Down
14 changes: 11 additions & 3 deletions src-tauri/src/binaries/binaries_resolver.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use crate::github::ReleaseSource;
use crate::ProgressTracker;
use anyhow::{anyhow, Error};
use async_trait::async_trait;
use log::info;
use regex::Regex;
use semver::Version;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::LazyLock;
Expand All @@ -15,19 +18,22 @@ use super::adapter_xmrig::XmrigVersionApiAdapter;
use super::binaries_manager::BinaryManager;
use super::Binaries;

pub const LOG_TARGET: &str = "tari::universe::binary_resolver";

static INSTANCE: LazyLock<RwLock<BinaryResolver>> =
LazyLock::new(|| RwLock::new(BinaryResolver::new()));

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VersionDownloadInfo {
pub(crate) version: Version,
pub(crate) assets: Vec<VersionAsset>,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VersionAsset {
pub(crate) url: String,
pub(crate) name: String,
pub(crate) source: ReleaseSource,
}

#[async_trait]
Expand Down Expand Up @@ -208,14 +214,16 @@ impl BinaryResolver {
progress_tracker: ProgressTracker,
should_check_for_update: bool,
) -> Result<(), Error> {
info!(target: LOG_TARGET, "Initializing binary: {} | should check for update: {}", binary.name(), should_check_for_update);

let manager = self
.managers
.get_mut(&binary)
.ok_or_else(|| anyhow!("Couldn't find manager for binary: {}", binary.name()))?;

manager.read_local_versions().await;

if should_check_for_update {
if true {
// Will populate Vec of downloaded versions that meet the requirements
manager.check_for_updates().await;
}
Expand Down
11 changes: 6 additions & 5 deletions src-tauri/src/download_utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::github::request_client::RequestClient;
use crate::ProgressTracker;
use anyhow::{anyhow, Error};
use async_zip::base::read::seek::ZipFileReader;
Expand Down Expand Up @@ -39,12 +40,12 @@ pub async fn download_file_with_retries(
}
}

async fn download_file(
pub async fn download_file(
url: &str,
destination: &Path,
progress_tracker: ProgressTracker,
) -> Result<(), anyhow::Error> {
let response = reqwest::get(url).await?;
let response = RequestClient::current().send_get_request(url).await?;

// Ensure the directory exists
if let Some(parent) = destination.parent() {
Expand All @@ -57,9 +58,9 @@ async fn download_file(
// Stream the response body directly to the file
let mut stream = response.bytes_stream();
while let Some(item) = stream.next().await {
let _ = progress_tracker
.update("downloading".to_string(), None, 10)
.await;
// let _ = progress_tracker
// .update("downloading".to_string(), None, 10)
// .await;
dest.write_all(&item?).await?;
}

Expand Down
Loading
Loading