cleanup cargo warnings

This commit is contained in:
hinto-janaiyo 2022-11-16 14:40:25 -05:00
parent 50fff5c311
commit 1b85e59530
No known key found for this signature in database
GPG key ID: B1C5A64B80691E45
10 changed files with 92 additions and 134 deletions

84
Cargo.lock generated
View file

@ -2,48 +2,6 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "Gupax"
version = "0.2.0"
dependencies = [
"anyhow",
"arti-client",
"arti-hyper",
"bytes",
"chrono",
"dirs",
"eframe",
"egui",
"egui_extras",
"env_logger 0.9.3",
"figment",
"flate2",
"hex-literal",
"hyper",
"hyper-tls",
"image",
"log",
"monero",
"num-format",
"num_cpus",
"rand 0.8.5",
"regex",
"reqwest",
"rusqlite",
"serde",
"serde_json",
"sha2 0.10.6",
"tar",
"tls-api",
"tls-api-native-tls",
"tokio",
"toml",
"tor-rtcompat",
"walkdir",
"winres",
"zip",
]
[[package]]
name = "ab_glyph"
version = "0.2.18"
@ -1822,6 +1780,48 @@ dependencies = [
"gl_generator",
]
[[package]]
name = "gupax"
version = "0.2.0"
dependencies = [
"anyhow",
"arti-client",
"arti-hyper",
"bytes",
"chrono",
"dirs",
"eframe",
"egui",
"egui_extras",
"env_logger 0.9.3",
"figment",
"flate2",
"hex-literal",
"hyper",
"hyper-tls",
"image",
"log",
"monero",
"num-format",
"num_cpus",
"rand 0.8.5",
"regex",
"reqwest",
"rusqlite",
"serde",
"serde_json",
"sha2 0.10.6",
"tar",
"tls-api",
"tls-api-native-tls",
"tokio",
"toml",
"tor-rtcompat",
"walkdir",
"winres",
"zip",
]
[[package]]
name = "h2"
version = "0.3.15"

View file

@ -1,5 +1,5 @@
[package]
name = "Gupax"
name = "gupax"
version = "0.2.0"
authors = ["hinto-janaiyo <hinto.janaiyo@protonmail.com>"]
description = "GUI for P2Pool+XMRig"

View file

@ -27,7 +27,7 @@ pub const BYTES_ICON: &[u8] = include_bytes!("../images/icons/icon@2x.png");
pub const BYTES_ICON: &[u8] = include_bytes!("../images/icons/icon.png");
pub const BYTES_BANNER: &[u8] = include_bytes!("../images/banner.png");
pub const P2POOL_BASE_ARGS: &'static str = "";
pub const XMRIG_BASE_ARGS: &'static str = "--http-host=127.0.0.1 --http-port=18088 --algo=rx/0 --coin=Monero --randomx-cache-qos";
pub const XMRIG_BASE_ARGS: &'static str = "--http-host=127.0.0.1 --http-port=18088 --algo=rx/0 --coin=Monero";
pub const HORIZONTAL: &'static str = "--------------------------------------------";
// This is the typical space added when using
@ -41,29 +41,22 @@ pub const SPACE: f32 = 10.0;
pub const OS: &'static str = " Windows";
#[cfg(target_os = "windows")]
pub const OS_NAME: &'static str = "Windows";
#[cfg(target_os = "windows")]
pub const HUGEPAGES_1GB: bool = false;
#[cfg(target_os = "macos")]
pub const OS: &'static str = " macOS";
#[cfg(target_os = "macos")]
pub const OS_NAME: &'static str = "macOS";
#[cfg(target_os = "macos")]
pub const HUGEPAGES_1GB: bool = false;
#[cfg(target_os = "linux")]
pub const OS: &'static str = "🐧 Linux";
#[cfg(target_os = "linux")]
pub const OS_NAME: &'static str = "Linux";
#[cfg(target_os = "linux")]
pub const HUGEPAGES_1GB: bool = true;
// Tooltips
// Gupax
pub const GUPAX_UPDATE: &'static str = "Check for updates on Gupax, P2Pool, and XMRig via GitHub's API and upgrade automatically";
pub const GUPAX_AUTO_UPDATE: &'static str = "Automatically check for updates at startup";
pub const GUPAX_UPDATE_VIA_TOR: &'static str = "Update through the Tor network. Tor is embedded within Gupax; a Tor system proxy is not required";
pub const GUPAX_AUTO_NODE: &'static str = "Automatically ping the community Monero nodes and select the fastest at startup for P2Pool";
pub const GUPAX_ASK_BEFORE_QUIT: &'static str = "Ask before quitting Gupax";
pub const GUPAX_SAVE_BEFORE_QUIT: &'static str = "Automatically save any changed settings before quitting";
pub const GUPAX_PATH_P2POOL: &'static str = "The location of the P2Pool binary: Both absolute and relative paths are accepted; A red [X] will appear if there is no file found at the given path";
@ -74,8 +67,6 @@ pub const P2POOL_MINI: &'static str = "Use the P2Pool mini-chain. This P2Pool fi
pub const P2POOL_OUT: &'static str = "How many out-bound peers to connect to? (you connecting to others)";
pub const P2POOL_IN: &'static str = "How many in-bound peers to allow? (others connecting to you)";
pub const P2POOL_LOG: &'static str = "Verbosity of the console log";
pub const P2POOL_COMMUNITY: &'static str = "Connect to a community trusted Monero node: This is convenient because you don't have to download the Monero blockchain but it comes at the cost of privacy";
pub const P2POOL_MANUAL: &'static str = "Manually specify your own Monero node settings";
pub const P2POOL_AUTO_NODE: &'static str = "Automatically ping the community Monero nodes at Gupax startup";
pub const P2POOL_AUTO_SELECT: &'static str = "Automatically select the fastest community Monero node after pinging";
pub const P2POOL_SELECT_FASTEST: &'static str = "Select the fastest community Monero node";

View file

@ -30,18 +30,18 @@
// ├─ Version/
// ├─ ...
use std::{fs,env};
use std::fmt::Display;
use std::path::{Path,PathBuf};
use std::result::Result;
use std::sync::{Arc,Mutex};
use std::collections::{HashMap,BTreeMap};
use std::fmt::Write;
use std::{
fs,
fmt::Display,
path::PathBuf,
result::Result,
sync::{Arc,Mutex},
fmt::Write,
};
use serde::{Serialize,Deserialize};
use figment::Figment;
use figment::providers::{Format,Toml};
use crate::constants::*;
use anyhow::Error;
use log::*;
//---------------------------------------------------------------------------------------------------- General functions for all [File]'s
@ -55,8 +55,8 @@ pub fn get_os_data_path() -> Result<PathBuf, TomlError> {
// Linux | $XDG_DATA_HOME or $HOME/.local/share | /home/alice/.local/state
// macOS | $HOME/Library/Application Support | /Users/Alice/Library/Application Support
// Windows | {FOLDERID_RoamingAppData} | C:\Users\Alice\AppData\Roaming
let mut path = match dirs::data_dir() {
Some(mut path) => {
let path = match dirs::data_dir() {
Some(path) => {
info!("OS | Data path ... OK");
path
},
@ -205,7 +205,7 @@ impl State {
Ok(string) => string,
// Create
_ => {
let new = Self::create_new()?;
Self::create_new()?;
read_to_string(file, &path)?
},
};
@ -352,7 +352,7 @@ impl Node {
Ok(string) => string,
// Create
_ => {
let new = Self::create_new()?;
Self::create_new()?;
read_to_string(file, &path)?
},
};

View file

@ -15,11 +15,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use std::path::Path;
use crate::{App,State};
use crate::State;
use egui::{
TextStyle::Monospace,
Checkbox,
RichText,
Label,
Color32,
@ -86,7 +84,7 @@ impl Gupax {
} else {
ui.add_sized([width, height], egui::Label::new("..."));
}
ui.add_sized([width, height], egui::ProgressBar::new((update.lock().unwrap().prog.lock().unwrap().round() / 100.0)));
ui.add_sized([width, height], egui::ProgressBar::new(update.lock().unwrap().prog.lock().unwrap().round() / 100.0));
});
});

View file

@ -20,11 +20,10 @@
//---------------------------------------------------------------------------------------------------- Imports
// egui/eframe
use egui::Ui;
use egui::TextStyle::*;
use egui::color::Color32;
use egui::FontFamily::Proportional;
use egui::{FontId,Label,RichText,Stroke,Vec2,Pos2};
use egui::{FontId,Label,RichText,Stroke,Vec2};
use egui::special_emojis::GITHUB;
use egui::{Key,Modifiers};
use egui_extras::RetainedImage;
@ -55,7 +54,7 @@ mod gupax;
mod p2pool;
mod xmrig;
mod update;
use {ferris::*,constants::*,node::*,disk::*,status::*,gupax::*,p2pool::*,xmrig::*,update::*};
use {ferris::*,constants::*,node::*,disk::*,status::*,update::*};
//---------------------------------------------------------------------------------------------------- Struct + Impl
// The state of the outer main [App].
@ -64,7 +63,6 @@ use {ferris::*,constants::*,node::*,disk::*,status::*,gupax::*,p2pool::*,xmrig::
pub struct App {
// Misc state
tab: Tab, // What tab are we on?
// quit: bool, // Was the quit confirmed?
ping: Arc<Mutex<Ping>>, // Ping data found in [node.rs]
width: f32, // Top-level width
height: f32, // Top-level height
@ -114,7 +112,6 @@ impl App {
fn new() -> Self {
let app = Self {
tab: Tab::default(),
// quit: false,
ping: Arc::new(Mutex::new(Ping::new())),
width: 1280.0,
height: 720.0,
@ -268,12 +265,12 @@ impl Images {
//---------------------------------------------------------------------------------------------------- [Regexes] struct
#[derive(Clone, Debug)]
struct Regexes {
name: Regex,
address: Regex,
ipv4: Regex,
domain: Regex,
port: Regex,
pub struct Regexes {
pub name: Regex,
pub address: Regex,
pub ipv4: Regex,
pub domain: Regex,
pub port: Regex,
}
impl Regexes {
@ -478,7 +475,7 @@ fn parse_args(mut app: App) -> App {
// Get absolute [Gupax] binary path
pub fn get_exe() -> Result<String, std::io::Error> {
match std::env::current_exe() {
Ok(mut path) => { Ok(path.display().to_string()) },
Ok(path) => { Ok(path.display().to_string()) },
Err(err) => { error!("Couldn't get exe basepath PATH"); return Err(err) },
}
}
@ -558,7 +555,7 @@ impl Panic {
}
impl eframe::App for Panic {
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
let width = ui.available_width();
let height = ui.available_height();

View file

@ -19,11 +19,8 @@ use crate::State;
use serde::{Serialize,Deserialize};
use std::time::{Instant,Duration};
use std::collections::HashMap;
use std::error::Error;
use std::thread;
use std::sync::{Arc,Mutex};
use egui::Color32;
use rand::Rng;
use log::*;
use reqwest::blocking::ClientBuilder;
@ -273,7 +270,7 @@ pub fn ping(ping: Arc<Mutex<Ping>>, og: Arc<Mutex<State>>) {
let http = "http://".to_string() + &**ip + "/json_rpc";
match client.post(http).json(&get_info).send() {
Ok(_) => mid += now.elapsed(),
Err(err) => {
Err(_) => {
mid += timeout_sec;
timeout += 1;
let error = format!("Timeout [{}/3] ... {:#?} ... {}", timeout, id, ip);
@ -319,7 +316,6 @@ pub fn ping(ping: Arc<Mutex<Ping>>, og: Arc<Mutex<State>>) {
}
}
let info = format!("Fastest node: {}ms ... {} @ {}", best_ms, fastest, enum_to_ip(fastest));
let percent = (100.0 - ping.lock().unwrap().prog) / 2.0;
info!("Ping | {}", info);
ping.lock().unwrap().nodes = nodes;
ping.lock().unwrap().fastest = fastest;

View file

@ -16,17 +16,14 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::{
App,
Regexes,
constants::*,
disk::*,
node::*
};
use egui::{
TextEdit,SelectableLabel,ComboBox,Label,FontId,Button,Color32,RichText,Slider,Checkbox,
TextEdit,SelectableLabel,ComboBox,Label,Button,Color32,RichText,Slider,
TextStyle::*,
FontFamily::Proportional,
TextBuffer,
};
use std::sync::{Arc,Mutex};
use std::thread;
@ -303,7 +300,7 @@ impl P2pool {
});
ui.horizontal(|ui| {
ui.set_enabled(node_vec_len > 1);
let text = format!("{}\n Currently selected node: {}. {}\n Current amount of nodes: {}/1000", P2POOL_ADD, self.selected_index, self.selected_name, node_vec_len);
let text = format!("{}\n Currently selected node: {}. {}\n Current amount of nodes: {}/1000", P2POOL_DELETE, self.selected_index, self.selected_name, node_vec_len);
if ui.add_sized([width, text_edit], Button::new("Delete")).on_hover_text(text).clicked() {
let mut n = 0;
for (name, _) in node_vec.iter() {

View file

@ -27,32 +27,28 @@
use anyhow::{anyhow,Error};
use arti_client::{TorClient,TorClientConfig};
use arti_hyper::*;
use arti_hyper::*;
use crate::constants::GUPAX_VERSION;
//use crate::{Name::*,State};
use crate::disk::*;
use crate::update::Name::*;
use hyper::{Client,Body,Request};
use hyper::header::HeaderValue;
use hyper_tls::HttpsConnector;
use hyper::header::LOCATION;
use hyper::{
Client,Body,Request,
header::{HeaderValue,LOCATION},
};
use log::*;
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use serde::{Serialize,Deserialize};
use std::io::{Read,Write};
use std::path::PathBuf;
use std::sync::{Arc,Mutex};
use std::time::Duration;
use tls_api::{TlsConnector, TlsConnectorBuilder};
use tokio::io::{AsyncReadExt,AsyncWriteExt};
use tokio::task::JoinHandle;
use walkdir::WalkDir;
#[cfg(target_os = "windows")]
use zip::ZipArchive;
#[cfg(target_family = "unix")]
use std::os::unix::fs::OpenOptionsExt;
//#[cfg(target_family = "unix")]
//use std::os::unix::fs::OpenOptionsExt;
//---------------------------------------------------------------------------------------------------- Constants
// Package naming schemes:
@ -323,9 +319,9 @@ impl Update {
let prog = update.lock().unwrap().prog.clone();
let msg = update.lock().unwrap().msg.clone();
let mut vec = vec![
Pkg::new(Gupax, &tmp_dir, prog.clone(), msg.clone()),
Pkg::new(P2pool, &tmp_dir, prog.clone(), msg.clone()),
Pkg::new(Xmrig, &tmp_dir, prog.clone(), msg.clone()),
Pkg::new(Gupax),
Pkg::new(P2pool),
Pkg::new(Xmrig),
];
// Generate fake user-agent
@ -365,15 +361,14 @@ impl Update {
let mut handles: Vec<JoinHandle<Result<(), anyhow::Error>>> = vec![];
for pkg in vec.iter() {
// Clone data before sending to async
let name = pkg.name.clone();
let new_ver = Arc::clone(&pkg.new_ver);
let client = client.clone();
let link = pkg.link_metadata.to_string();
// Send to async
let handle: JoinHandle<Result<(), anyhow::Error>> = tokio::spawn(async move {
match client {
ClientEnum::Tor(t) => Pkg::get_metadata(name, new_ver, t, link, user_agent).await,
ClientEnum::Https(h) => Pkg::get_metadata(name, new_ver, h, link, user_agent).await,
ClientEnum::Tor(t) => Pkg::get_metadata(new_ver, t, link, user_agent).await,
ClientEnum::Https(h) => Pkg::get_metadata(new_ver, h, link, user_agent).await,
}
});
handles.push(handle);
@ -419,8 +414,6 @@ impl Update {
//---------------------------------------------------------------------------------------------------- Compare
*update.lock().unwrap().msg.lock().unwrap() = MSG_COMPARE.to_string();
info!("Update | {}", COMPARE);
let prog = update.lock().unwrap().prog.clone();
let msg = update.lock().unwrap().msg.clone();
let mut vec3 = vec![];
let mut new_pkgs = vec![];
for pkg in vec2.iter() {
@ -479,7 +472,6 @@ impl Update {
let mut handles: Vec<JoinHandle<Result<(), anyhow::Error>>> = vec![];
for pkg in vec3.iter() {
// Clone data before async
let name = pkg.name.clone();
let bytes = Arc::clone(&pkg.bytes);
let client = client.clone();
let version = pkg.new_ver.lock().unwrap();
@ -495,8 +487,8 @@ impl Update {
info!("Update | {} ... {}", pkg.name, link);
let handle: JoinHandle<Result<(), anyhow::Error>> = tokio::spawn(async move {
match client {
ClientEnum::Tor(t) => Pkg::get_bytes(name, bytes, t, link, user_agent).await,
ClientEnum::Https(h) => Pkg::get_bytes(name, bytes, h, link, user_agent).await,
ClientEnum::Tor(t) => Pkg::get_bytes(bytes, t, link, user_agent).await,
ClientEnum::Https(h) => Pkg::get_bytes(bytes, h, link, user_agent).await,
}
});
handles.push(handle);
@ -640,16 +632,12 @@ pub struct Pkg {
link_prefix: &'static str,
link_suffix: &'static str,
link_extension: &'static str,
tmp_dir: String,
prog: Arc<Mutex<f32>>,
msg: Arc<Mutex<String>>,
bytes: Arc<Mutex<hyper::body::Bytes>>,
old_ver: String,
new_ver: Arc<Mutex<String>>,
}
impl Pkg {
pub fn new(name: Name, tmp_dir: &String, prog: Arc<Mutex<f32>>, msg: Arc<Mutex<String>>) -> Self {
pub fn new(name: Name) -> Self {
let link_metadata = match name {
Gupax => GUPAX_METADATA,
P2pool => P2POOL_METADATA,
@ -676,11 +664,7 @@ impl Pkg {
link_prefix,
link_suffix,
link_extension,
tmp_dir: tmp_dir.to_string(),
prog,
msg,
bytes: Arc::new(Mutex::new(bytes::Bytes::new())),
old_ver: String::new(),
new_ver: Arc::new(Mutex::new(String::new())),
}
}
@ -706,9 +690,9 @@ impl Pkg {
// Get metadata using [Generic hyper::client<C>] & [Request]
// and change [version, prog] under an Arc<Mutex>
async fn get_metadata<C>(name: Name, new_ver: Arc<Mutex<String>>, client: Client<C>, link: String, user_agent: &'static str) -> Result<(), Error>
async fn get_metadata<C>(new_ver: Arc<Mutex<String>>, client: Client<C>, link: String, user_agent: &'static str) -> Result<(), Error>
where C: hyper::client::connect::Connect + Clone + Send + Sync + 'static, {
let request = Pkg::get_request(link.clone(), user_agent)?;
let request = Pkg::get_request(link, user_agent)?;
let mut response = client.request(request).await?;
let body = hyper::body::to_bytes(response.body_mut()).await?;
let body: TagName = serde_json::from_slice(&body)?;
@ -718,9 +702,9 @@ impl Pkg {
// Takes a [Request], fills the appropriate [Pkg]
// [bytes] field with the [Archive/Standalone]
async fn get_bytes<C>(name: Name, bytes: Arc<Mutex<bytes::Bytes>>, client: Client<C>, link: String, user_agent: &'static str) -> Result<(), anyhow::Error>
async fn get_bytes<C>(bytes: Arc<Mutex<bytes::Bytes>>, client: Client<C>, link: String, user_agent: &'static str) -> Result<(), anyhow::Error>
where C: hyper::client::connect::Connect + Clone + Send + Sync + 'static, {
let request = Self::get_request(link.clone(), user_agent)?;
let request = Self::get_request(link, user_agent)?;
let mut response = client.request(request).await?;
// GitHub sends a 302 redirect, so we must follow
// the [Location] header... only if Reqwest had custom

View file

@ -15,18 +15,13 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::App;
use monero::util::address::Address;
use std::str::FromStr;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use num_cpus;
use crate::constants::*;
use crate::disk::Xmrig;
impl Xmrig {
pub fn show(&mut self, width: f32, height: f32, ctx: &egui::Context, ui: &mut egui::Ui) {
let height = ui.available_height() / 10.0;
let mut width = ui.available_width() - 10.0;
let width = ui.available_width() - 10.0;
ui.group(|ui| {
ui.add_sized([width, height*4.0], egui::TextEdit::multiline(&mut "".to_owned()));
ui.add_sized([width, 30.0], egui::TextEdit::singleline(&mut "".to_owned()));
@ -70,7 +65,7 @@ impl Xmrig {
// ui.group(|ui| {
if self.simple == false { ui.set_enabled(false); }
let width = (width/4.0);
let width = width/4.0;
ui.horizontal(|ui| {
ui.add_sized([width/8.0, height/8.0], egui::Label::new("Pool IP:"));
ui.spacing_mut().text_edit_width = ui.available_width() - 35.0;