Skip to content

Commit

Permalink
merge: resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
shanimal08 committed Dec 5, 2024
2 parents b54eeb9 + cb5a757 commit 6ea58b8
Show file tree
Hide file tree
Showing 18 changed files with 504 additions and 227 deletions.
43 changes: 40 additions & 3 deletions src-tauri/src/binaries/binaries_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ impl BinaryManager {
Ok(in_progress_folder)
}

fn delete_in_progress_folder_for_selected_version(
async fn delete_in_progress_folder_for_selected_version(
&self,
selected_version: Version,
progress_tracker: ProgressTracker,
) -> Result<(), Error> {
info!(target: LOG_TARGET,"Deleting in progress folder for version: {:?}", selected_version);

Expand All @@ -156,6 +157,12 @@ impl BinaryManager {
.join(selected_version.to_string())
.join("in_progress");

progress_tracker
.send_last_action(format!(
"Removing in progress folder: {:?}",
in_progress_folder
))
.await;
if in_progress_folder.exists() {
info!(target: LOG_TARGET,"Removing in progress folder: {:?}", in_progress_folder);
if let Err(error) = std::fs::remove_dir_all(&in_progress_folder) {
Expand Down Expand Up @@ -231,6 +238,12 @@ impl BinaryManager {
version: version.clone(),
assets: vec![asset.clone()],
};
progress_tracker
.send_last_action(format!(
"Downloading checksum file for dest: {:?}",
destination_dir
))
.await;
let checksum_file = self
.adapter
.download_and_get_checksum_path(
Expand All @@ -251,6 +264,12 @@ impl BinaryManager {
info!(target: LOG_TARGET, "Validating checksum for version: {:?}", version);
info!(target: LOG_TARGET, "Checksum file: {:?}", checksum_file);
info!(target: LOG_TARGET, "In progress file: {:?}", in_progress_file_zip);
progress_tracker
.send_last_action(format!(
"Validating checksum for checksum file: {:?} and in progress file: {:?}",
checksum_file, in_progress_file_zip
))
.await;
match validate_checksum(
in_progress_file_zip.clone(),
checksum_file,
Expand Down Expand Up @@ -426,6 +445,13 @@ 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());

progress_tracker
.send_last_action(format!(
"Downloading binary: {} with version: {}",
self.binary_name,
version.to_string()
))
.await;
download_file_with_retries(
asset.url.as_str(),
&in_progress_file_zip,
Expand All @@ -436,6 +462,13 @@ impl BinaryManager {

info!(target: LOG_TARGET, "Downloaded version: {:?}", version);

progress_tracker
.send_last_action(format!(
"Extracting file: {} to dest: {}",
in_progress_file_zip.to_str().unwrap_or_default(),
destination_dir.to_str().unwrap_or_default()
))
.await;
extract(&in_progress_file_zip, &destination_dir)
.await
.map_err(|e| anyhow!("Error extracting version: {:?}. Error: {:?}", version, e))?;
Expand All @@ -446,12 +479,16 @@ impl BinaryManager {
asset,
destination_dir,
in_progress_file_zip,
progress_tracker,
progress_tracker.clone(),
)
.await?;
}

self.delete_in_progress_folder_for_selected_version(version.clone())?;
self.delete_in_progress_folder_for_selected_version(
version.clone(),
progress_tracker.clone(),
)
.await?;
Ok(())
}

Expand Down
52 changes: 51 additions & 1 deletion src-tauri/src/binaries/binaries_resolver.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
use crate::ProgressTracker;
use anyhow::{anyhow, Error};
use async_trait::async_trait;
use log::error;
use regex::Regex;
use semver::Version;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::LazyLock;
use std::time::Duration;
use tari_common::configuration::Network;
use tauri_plugin_sentry::sentry;
use tokio::sync::watch::Receiver;
use tokio::sync::RwLock;
use tokio::time::timeout;

use super::adapter_github::GithubReleasesAdapter;
use super::adapter_tor::TorReleaseAdapter;
Expand Down Expand Up @@ -202,7 +207,31 @@ impl BinaryResolver {
Ok(base_dir.join(binary.binary_file_name(version)))
}

pub async fn initalize_binary(
pub async fn initialize_binary_timeout(
&mut self,
binary: Binaries,
progress_tracker: ProgressTracker,
should_check_for_update: bool,
timeout_channel: Receiver<String>,
) -> Result<(), Error> {
match timeout(
Duration::from_secs(60 * 5),
self.initialize_binary(binary, progress_tracker.clone(), should_check_for_update),
)
.await
{
Err(_) => {
let last_msg = timeout_channel.borrow().clone();
error!(target: "tari::universe::main", "Setup took too long: {:?}", last_msg);
let error_msg = format!("Setup took too long: {}", last_msg);
sentry::capture_message(&error_msg, sentry::Level::Error);
Err(anyhow!(error_msg))
}
Ok(result) => result,
}
}

pub async fn initialize_binary(
&mut self,
binary: Binaries,
progress_tracker: ProgressTracker,
Expand Down Expand Up @@ -269,6 +298,17 @@ impl BinaryResolver {
manager.check_for_updates().await;
let highest_version = manager.select_highest_version();

progress_tracker
.send_last_action(format!(
"Checking if files exist before download: {} {}",
binary.name(),
highest_version
.clone()
.unwrap_or(Version::new(0, 0, 0))
.to_string()
))
.await;

let check_if_files_exist =
manager.check_if_files_for_version_exist(highest_version.clone());
if !check_if_files_exist {
Expand All @@ -277,6 +317,16 @@ impl BinaryResolver {
.await?;
}

progress_tracker
.send_last_action(format!(
"Checking if files exist after download: {} {}",
binary.name(),
highest_version
.clone()
.unwrap_or(Version::new(0, 0, 0))
.to_string()
))
.await;
let check_if_files_exist =
manager.check_if_files_for_version_exist(highest_version.clone());
if !check_if_files_exist {
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,7 @@ pub async fn update_applications(
)
.map_err(|e| e.to_string())?;

let progress_tracker = ProgressTracker::new(app.clone());
let progress_tracker = ProgressTracker::new(app.clone(), None);
binary_resolver
.update_binary(Binaries::Xmrig, progress_tracker.clone())
.await
Expand Down
8 changes: 8 additions & 0 deletions src-tauri/src/download_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ pub async fn download_file_with_retries(
}
retries += 1;
eprintln!("Error downloading file: {}. Try {:?}/3", err, retries);
progress_tracker
.send_last_action(format!(
"Failed at retry: {} to download binary from url: {} to destination: {}",
retries,
url,
destination.to_str().unwrap_or("unknown")
))
.await;
sleep(Duration::from_secs(1)).await;
}
}
Expand Down
43 changes: 33 additions & 10 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use log::trace;
use log::{debug, error, info, warn};
use p2pool::models::Connections;
use std::fs::{remove_dir_all, remove_file};
use tokio::sync::watch::{self};

use log4rs::config::RawConfig;
use serde::Serialize;
Expand Down Expand Up @@ -197,7 +198,8 @@ async fn setup_inner(
.initialize_auto_launcher(is_auto_launcher_enabled)
.await?;

let progress = ProgressTracker::new(app.clone());
let (tx, rx) = watch::channel("".to_string());
let progress = ProgressTracker::new(app.clone(), Some(tx));

let last_binaries_update_timestamp = state.config.read().await.last_binaries_update_timestamp();
let now = SystemTime::now();
Expand All @@ -221,7 +223,12 @@ async fn setup_inner(
.update("checking-latest-version-tor".to_string(), None, 0)
.await;
binary_resolver
.initalize_binary(Binaries::Tor, progress.clone(), should_check_for_update)
.initialize_binary_timeout(
Binaries::Tor,
progress.clone(),
should_check_for_update,
rx.clone(),
)
.await?;
sleep(Duration::from_secs(1));
}
Expand All @@ -231,10 +238,11 @@ async fn setup_inner(
.update("checking-latest-version-node".to_string(), None, 0)
.await;
binary_resolver
.initalize_binary(
.initialize_binary_timeout(
Binaries::MinotariNode,
progress.clone(),
should_check_for_update,
rx.clone(),
)
.await?;
sleep(Duration::from_secs(1));
Expand All @@ -244,31 +252,39 @@ async fn setup_inner(
.update("checking-latest-version-mmproxy".to_string(), None, 0)
.await;
binary_resolver
.initalize_binary(
.initialize_binary_timeout(
Binaries::MergeMiningProxy,
progress.clone(),
should_check_for_update,
rx.clone(),
)
.await?;
sleep(Duration::from_secs(1));

progress.set_max(20).await;
progress
.update("checking-latest-version-wallet".to_string(), None, 0)
.await;
binary_resolver
.initalize_binary(Binaries::Wallet, progress.clone(), should_check_for_update)
.initialize_binary_timeout(
Binaries::Wallet,
progress.clone(),
should_check_for_update,
rx.clone(),
)
.await?;

sleep(Duration::from_secs(1));

progress.set_max(25).await;
progress
.update("checking-latest-version-gpuminer".to_string(), None, 0)
.await;
binary_resolver
.initalize_binary(
.initialize_binary_timeout(
Binaries::GpuMiner,
progress.clone(),
should_check_for_update,
rx.clone(),
)
.await?;
sleep(Duration::from_secs(1));
Expand All @@ -278,21 +294,29 @@ async fn setup_inner(
.update("checking-latest-version-xmrig".to_string(), None, 0)
.await;
binary_resolver
.initalize_binary(Binaries::Xmrig, progress.clone(), should_check_for_update)
.initialize_binary_timeout(
Binaries::Xmrig,
progress.clone(),
should_check_for_update,
rx.clone(),
)
.await?;
sleep(Duration::from_secs(1));

progress.set_max(35).await;
progress
.update("checking-latest-version-sha-p2pool".to_string(), None, 0)
.await;
binary_resolver
.initalize_binary(
.initialize_binary_timeout(
Binaries::ShaP2pool,
progress.clone(),
should_check_for_update,
rx.clone(),
)
.await?;
sleep(Duration::from_secs(1));

if should_check_for_update {
state
.config
Expand Down Expand Up @@ -357,7 +381,6 @@ async fn setup_inner(
}
}
}

info!(target: LOG_TARGET, "Node has started and is ready");

progress.set_max(40).await;
Expand Down
Loading

0 comments on commit 6ea58b8

Please sign in to comment.