-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Aaron Pepper <pepdog@gmail.com> Co-authored-by: Misieq01 <38589417+Misieq01@users.noreply.github.com> Co-authored-by: Keith Simon <41575888+Krakaw@users.noreply.github.com> Co-authored-by: stringhandler <stringhandler@protonmail.com>
- Loading branch information
1 parent
fbfacb3
commit 8a5d7c5
Showing
89 changed files
with
2,744 additions
and
1,849 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"binaries": { | ||
"xmrig": "6.22.0", | ||
"mmproxy": "1.5.1-pre.0", | ||
"minotari_node": "1.5.1-pre.0", | ||
"wallet": "1.5.1-pre.0", | ||
"sha-p2pool": "0.1.8", | ||
"xtrgpuminer": "0.1.8-pre.4" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"binaries": { | ||
"xmrig": "6.22.0", | ||
"mmproxy": "1.5.1-rc.2", | ||
"minotari_node": "1.5.1-rc.2", | ||
"wallet": "1.5.1-rc.2", | ||
"sha-p2pool": "0.1.8", | ||
"xtrgpuminer": "0.1.8-pre.4" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
use std::path::PathBuf; | ||
|
||
use anyhow::Error; | ||
use async_trait::async_trait; | ||
use log::{error, info}; | ||
use regex::Regex; | ||
use tari_common::configuration::Network; | ||
use tauri::api::path::cache_dir; | ||
|
||
use crate::{ | ||
download_utils::download_file_with_retries, github, progress_tracker::ProgressTracker, | ||
}; | ||
|
||
use super::binaries_resolver::{LatestVersionApiAdapter, VersionAsset, VersionDownloadInfo}; | ||
|
||
pub const LOG_TARGET: &str = "tari::universe::adapter_github"; | ||
|
||
pub struct GithubReleasesAdapter { | ||
pub repo: String, | ||
pub owner: String, | ||
pub specific_name: Option<Regex>, | ||
} | ||
|
||
#[async_trait] | ||
impl LatestVersionApiAdapter for GithubReleasesAdapter { | ||
async fn fetch_releases_list(&self) -> Result<Vec<VersionDownloadInfo>, Error> { | ||
let releases = github::list_releases(&self.owner, &self.repo).await?; | ||
Ok(releases.clone()) | ||
} | ||
|
||
async fn download_and_get_checksum_path( | ||
&self, | ||
directory: PathBuf, | ||
download_info: VersionDownloadInfo, | ||
progress_tracker: ProgressTracker, | ||
) -> Result<PathBuf, Error> { | ||
let asset = self.find_version_for_platform(&download_info)?; | ||
let checksum_path = directory | ||
.join("in_progress") | ||
.join(format!("{}.sha256", asset.name)); | ||
let checksum_url = format!("{}.sha256", asset.url); | ||
|
||
match download_file_with_retries(&checksum_url, &checksum_path, progress_tracker).await { | ||
Ok(_) => Ok(checksum_path), | ||
Err(e) => { | ||
error!(target: LOG_TARGET, "Failed to download checksum file: {}", e); | ||
Err(e) | ||
} | ||
} | ||
} | ||
|
||
fn get_binary_folder(&self) -> PathBuf { | ||
let binary_folder_path = cache_dir() | ||
.unwrap() | ||
.join("com.tari.universe") | ||
.join("binaries") | ||
.join(&self.repo) | ||
.join( | ||
Network::get_current_or_user_setting_or_default() | ||
.to_string() | ||
.to_lowercase(), | ||
); | ||
|
||
if !binary_folder_path.exists() { | ||
drop(std::fs::create_dir_all(&binary_folder_path)); | ||
} | ||
|
||
binary_folder_path | ||
} | ||
|
||
fn find_version_for_platform( | ||
&self, | ||
version: &VersionDownloadInfo, | ||
) -> Result<VersionAsset, Error> { | ||
let mut name_suffix = ""; | ||
// TODO: add platform specific logic | ||
if cfg!(target_os = "windows") { | ||
name_suffix = r"windows-x64.*\.zip"; | ||
} | ||
|
||
if cfg!(target_os = "macos") && cfg!(target_arch = "x86_64") { | ||
name_suffix = r"macos-x86_64.*\.zip"; | ||
} | ||
|
||
if cfg!(target_os = "macos") && cfg!(target_arch = "aarch64") { | ||
name_suffix = r"macos-arm64.*\.zip"; | ||
} | ||
if cfg!(target_os = "linux") { | ||
name_suffix = r"linux-x86_64.*\.zip"; | ||
} | ||
if name_suffix.is_empty() { | ||
panic!("Unsupported OS"); | ||
} | ||
|
||
info!(target: LOG_TARGET, "Looking for platform with suffix: {}", name_suffix); | ||
|
||
let reg = Regex::new(name_suffix).unwrap(); | ||
|
||
let platform = version | ||
.assets | ||
.iter() | ||
.find(|a| { | ||
if let Some(ref specific) = self.specific_name { | ||
specific.is_match(&a.name) && reg.is_match(&a.name) | ||
} else { | ||
reg.is_match(&a.name) | ||
} | ||
}) | ||
.ok_or(anyhow::anyhow!("Failed to get platform asset"))?; | ||
info!(target: LOG_TARGET, "Found platform: {:?}", platform); | ||
Ok(platform.clone()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
use std::path::PathBuf; | ||
|
||
use anyhow::Error; | ||
use async_trait::async_trait; | ||
use regex::Regex; | ||
use tari_common::configuration::Network; | ||
use tauri::api::path::cache_dir; | ||
|
||
use crate::{github, progress_tracker::ProgressTracker}; | ||
|
||
use super::binaries_resolver::{LatestVersionApiAdapter, VersionAsset, VersionDownloadInfo}; | ||
|
||
pub struct XmrigVersionApiAdapter {} | ||
|
||
#[async_trait] | ||
impl LatestVersionApiAdapter for XmrigVersionApiAdapter { | ||
async fn fetch_releases_list(&self) -> Result<Vec<VersionDownloadInfo>, Error> { | ||
let releases = github::list_releases("xmrig", "xmrig").await?; | ||
Ok(releases.clone()) | ||
} | ||
|
||
async fn download_and_get_checksum_path( | ||
&self, | ||
directory: PathBuf, | ||
download_info: VersionDownloadInfo, | ||
_: ProgressTracker, | ||
) -> Result<PathBuf, Error> { | ||
// When xmrig is downloaded checksum will be already in its folder so there is no need to download it | ||
// directory parameter should point to folder where xmrig is extracted | ||
// file with checksum should be in the same folder as xmrig | ||
// file name is SHA256SUMS | ||
// let platform = self.find_version_for_platform(version)?; | ||
let checksum_path = directory | ||
.join(format!("xmrig-{}", download_info.version)) | ||
.join("SHA256SUMS"); | ||
|
||
Ok(checksum_path) | ||
} | ||
|
||
fn get_binary_folder(&self) -> PathBuf { | ||
let binary_folder_path = cache_dir() | ||
.unwrap() | ||
.join("com.tari.universe") | ||
.join("binaries") | ||
.join("xmrig") | ||
.join( | ||
Network::get_current_or_user_setting_or_default() | ||
.to_string() | ||
.to_lowercase(), | ||
); | ||
|
||
if !binary_folder_path.exists() { | ||
drop(std::fs::create_dir_all(&binary_folder_path)); | ||
} | ||
|
||
binary_folder_path | ||
} | ||
|
||
fn find_version_for_platform( | ||
&self, | ||
_version: &VersionDownloadInfo, | ||
) -> Result<VersionAsset, anyhow::Error> { | ||
let mut name_suffix = ""; | ||
if cfg!(target_os = "windows") { | ||
name_suffix = r".*msvc-win64\.zip"; | ||
} | ||
if cfg!(target_os = "macos") && cfg!(target_arch = "x86_64") { | ||
name_suffix = r".*macos-x64\.tar.gz"; | ||
} | ||
if cfg!(target_os = "macos") && cfg!(target_arch = "aarch64") { | ||
// the x64 seems to work better on the M1 | ||
name_suffix = r".*macos-arm64\.tar.gz"; | ||
} | ||
if cfg!(target_os = "linux") { | ||
name_suffix = r".*linux-static-x64\.tar.gz"; | ||
} | ||
if cfg!(target_os = "freebsd") { | ||
name_suffix = r".*freebsd-static-x64\.tar.gz"; | ||
} | ||
if name_suffix.is_empty() { | ||
panic!("Unsupported OS"); | ||
} | ||
|
||
let reg = Regex::new(name_suffix).unwrap(); | ||
let platform = _version | ||
.assets | ||
.iter() | ||
.find(|a| reg.is_match(&a.name)) | ||
.ok_or(anyhow::anyhow!("Failed to get platform asset"))?; | ||
Ok(platform.clone()) | ||
} | ||
} |
Oops, something went wrong.