helper: localhost into 127.0.0.1 for xmrig

This commit is contained in:
hinto-janaiyo 2023-02-06 09:17:09 -05:00
parent 38a8614357
commit 55f8c24cc7
No known key found for this signature in database
GPG key ID: B1C5A64B80691E45
7 changed files with 134 additions and 30 deletions

View file

@ -1,21 +1,4 @@
# v1.1.2 # v1.1.2
## Updates
*
## Fixes
*
## Bundled Versions
* [`P2Pool v3.0`](https://github.com/SChernykh/p2pool/releases/tag/v3.0)
* [`XMRig v6.18.1`](https://github.com/xmrig/xmrig/releases/tag/v6.18.1)
---
# v1.2.0
## Updates
*
## Fixes ## Fixes
* *

47
Cargo.lock generated
View file

@ -91,9 +91,9 @@ dependencies = [
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.68" version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2cb2f989d18dd141ab8ae82f64d1a8cdd37e0840f73a406896cf5e99502fab61" checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800"
[[package]] [[package]]
name = "arboard" name = "arboard"
@ -1271,9 +1271,9 @@ dependencies = [
[[package]] [[package]]
name = "exr" name = "exr"
version = "1.5.2" version = "1.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eb5f255b5980bb0c8cf676b675d1a99be40f316881444f44e0462eaf5df5ded" checksum = "e8af5ef47e2ed89d23d0ecbc1b681b30390069de70260937877514377fc24feb"
dependencies = [ dependencies = [
"bit_field", "bit_field",
"flume", "flume",
@ -1282,6 +1282,7 @@ dependencies = [
"miniz_oxide", "miniz_oxide",
"smallvec", "smallvec",
"threadpool", "threadpool",
"zune-inflate",
] ]
[[package]] [[package]]
@ -1798,7 +1799,7 @@ dependencies = [
[[package]] [[package]]
name = "gupax" name = "gupax"
version = "1.1.1" version = "1.1.2"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"arti-client", "arti-client",
@ -1823,6 +1824,7 @@ dependencies = [
"regex", "regex",
"rfd", "rfd",
"serde", "serde",
"serde-xml-rs",
"serde_json", "serde_json",
"static_vcruntime", "static_vcruntime",
"sudo", "sudo",
@ -3026,9 +3028,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.50" version = "1.0.51"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -3434,6 +3436,18 @@ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]]
name = "serde-xml-rs"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb3aa78ecda1ebc9ec9847d5d3aba7d618823446a049ba2491940506da6e2782"
dependencies = [
"log",
"serde",
"thiserror",
"xml-rs",
]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.152" version = "1.0.152"
@ -3456,9 +3470,9 @@ dependencies = [
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.91" version = "1.0.92"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" checksum = "7434af0dc1cbd59268aa98b4c22c131c0584d2232f6fb166efb993e2832e896a"
dependencies = [ dependencies = [
"itoa", "itoa",
"ryu", "ryu",
@ -3646,6 +3660,12 @@ version = "1.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c"
[[package]]
name = "simd-adler32"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14a5df39617d7c8558154693a1bb8157a4aab8179209540cc0b10e5dc24e0b18"
[[package]] [[package]]
name = "simple_asn1" name = "simple_asn1"
version = "0.6.2" version = "0.6.2"
@ -5474,3 +5494,12 @@ dependencies = [
"libc", "libc",
"pkg-config", "pkg-config",
] ]
[[package]]
name = "zune-inflate"
version = "0.2.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c473377c11c4a3ac6a2758f944cd336678e9c977aa0abf54f6450cf77e902d6d"
dependencies = [
"simd-adler32",
]

View file

@ -1,6 +1,6 @@
[package] [package]
name = "gupax" name = "gupax"
version = "1.2.0" version = "1.1.2"
authors = ["hinto-janaiyo <hinto.janaiyo@protonmail.com>"] authors = ["hinto-janaiyo <hinto.janaiyo@protonmail.com>"]
description = "GUI for P2Pool+XMRig" description = "GUI for P2Pool+XMRig"
documentation = "https://github.com/hinto-janaiyo/gupax" documentation = "https://github.com/hinto-janaiyo/gupax"
@ -58,6 +58,7 @@ toml = { version = "0.5.9", features = ["preserve_order"] }
tor-rtcompat = "0.7.0" tor-rtcompat = "0.7.0"
walkdir = "2.3.2" walkdir = "2.3.2"
zeroize = "1.5.7" zeroize = "1.5.7"
serde-xml-rs = "0.6.0"
# Unix dependencies # Unix dependencies
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]

View file

@ -18,6 +18,7 @@
## Structure ## Structure
| File/Folder | Purpose | | File/Folder | Purpose |
|--------------|---------| |--------------|---------|
| benchmark.rs | Code for handling [XMRig's benchmark data](https://xmrig.com/docs/api/1/benchmark)
| constants.rs | General constants used in Gupax | constants.rs | General constants used in Gupax
| disk.rs | Code for writing to disk: `state.toml/node.toml/pool.toml`; This holds the structs for the [State] struct | disk.rs | Code for writing to disk: `state.toml/node.toml/pool.toml`; This holds the structs for the [State] struct
| ferris.rs | Cute crab bytes | ferris.rs | Cute crab bytes

87
src/benchmark.rs Normal file
View file

@ -0,0 +1,87 @@
// Gupax - GUI Uniting P2Pool And XMRig
//
// Copyright (c) 2022 hinto-janaiyo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// This file contains backend code for handling XMRig's benchmark data:
// - HTTP(s) fetchs to [https://xmrig.com]
// - (De)serialization of JSON data
// - (De)serialization of CPU topology XML (./xmrig --export topology)
use serde::{Serialize, Deserialize};
use std::fmt::Write;
// Input: Full [&str] of XMRig's [topology.xml] file
// Output: The CPU name formatted so it's usable as the endpoint, e.g: [AMD+Ryzen+9+5950X+16-Core+Processor]
fn cpu_name_from_xml(xml: &str) -> Option<String> {
// A minimal matching struct for the [CPUModel] <info> field in the XML file
#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct Info { // <info [...] />
name: String, // name="CPUModel"
value: String, // value="Ryzen ..."
}
// Regex to find matching field
let regex = regex::Regex::new("\"CPUModel\"").unwrap();
for line in xml.lines() {
if !regex.is_match(&line) { continue }
// If found, attempt to serialize XML proper
if let Ok(info) = serde_xml_rs::from_str::<Info>(&line) {
// Return early if empty
if info.value.is_empty() {
return None
}
// If serialized, turn whitespaces into '+'
let words: Vec<&str> = info.value.split_whitespace().collect();
let last_word = words.len();
let mut result = String::new();
let mut n = 1;
for word in words.iter() {
match n == last_word {
false => write!(result, "{}+", word),
true => write!(result, "{}", word),
};
n += 1;
}
return Some(result)
}
}
// If loop didn't return early, return none
None
}
//---------------------------------------------------------------------------------------------------- TESTS
#[cfg(test)]
mod test {
#[test]
fn get_cpu_from_xml() {
let string =
r#"<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topology SYSTEM "hwloc2.dtd">
<topology version="2.0">
<object type="Machine" os_index="0" cpuset="0xffffffff" complete_cpuset="0xffffffff" allowed_cpuset="0xffffffff" nodeset="0x00000001" complete_nodeset="0x00000001" allowed_nodeset="0x00000001" gp_index="1">
<info name="DMIBIOSVendor" value="American Megatrends International, LLC."/>
<info name="Backend" value="Linux"/>
<info name="LinuxCgroup" value="/"/>
<info name="OSName" value="Linux"/>
<info name="CPUModel" value="AMD Ryzen 9 5950X 16-Core Processor "/>
<info name="CPUStepping" value="0"/>
"#;
assert_eq!(crate::benchmark::cpu_name_from_xml(&string).unwrap(), "AMD+Ryzen+9+5950X+16-Core+Processor");
}
}

View file

@ -417,14 +417,15 @@ impl Helper {
_ => (), _ => (),
} }
if !mini { p2pool_image.mini = "P2Pool Main".to_string(); } if !mini { p2pool_image.mini = "P2Pool Main".to_string(); }
let arg = if arg == "localhost" { "127.0.0.1" } else { arg };
args.push(arg.to_string()); args.push(arg.to_string());
last = arg; last = arg;
} }
// Else, build the argument // Else, build the argument
} else { } else {
let ip = if state.selected_ip == "localhost" { "127.0.0.1".to_string() } else { state.selected_ip.to_string() }; let ip = if state.selected_ip == "localhost" { "127.0.0.1" } else { &state.selected_ip };
args.push("--wallet".to_string()); args.push(state.address.clone()); // Wallet args.push("--wallet".to_string()); args.push(state.address.clone()); // Wallet
args.push("--host".to_string()); args.push(ip); // IP args.push("--host".to_string()); args.push(ip.to_string()); // IP
args.push("--rpc-port".to_string()); args.push(state.selected_rpc.to_string()); // RPC args.push("--rpc-port".to_string()); args.push(state.selected_rpc.to_string()); // RPC
args.push("--zmq-port".to_string()); args.push(state.selected_zmq.to_string()); // ZMQ args.push("--zmq-port".to_string()); args.push(state.selected_zmq.to_string()); // ZMQ
args.push("--loglevel".to_string()); args.push(state.log_level.to_string()); // Log Level args.push("--loglevel".to_string()); args.push(state.log_level.to_string()); // Log Level
@ -799,9 +800,10 @@ impl Helper {
// Else, build the argument // Else, build the argument
} else { } else {
// XMRig doesn't understand [localhost] // XMRig doesn't understand [localhost]
let ip = if state.selected_ip == "localhost" || state.selected_ip.is_empty() { "127.0.0.1" } else { &state.selected_ip };
api_ip = if state.api_ip == "localhost" || state.api_ip.is_empty() { "127.0.0.1".to_string() } else { state.api_ip.to_string() }; api_ip = if state.api_ip == "localhost" || state.api_ip.is_empty() { "127.0.0.1".to_string() } else { state.api_ip.to_string() };
api_port = if state.api_port.is_empty() { "18088".to_string() } else { state.api_port.to_string() }; api_port = if state.api_port.is_empty() { "18088".to_string() } else { state.api_port.to_string() };
let url = format!("{}:{}", state.selected_ip, state.selected_port); // Combine IP:Port into one string let url = format!("{}:{}", ip, state.selected_port); // Combine IP:Port into one string
args.push("--user".to_string()); args.push(state.address.clone()); // Wallet args.push("--user".to_string()); args.push(state.address.clone()); // Wallet
args.push("--threads".to_string()); args.push(state.current_threads.to_string()); // Threads args.push("--threads".to_string()); args.push(state.current_threads.to_string()); // Threads
args.push("--rig-id".to_string()); args.push(state.selected_rig.to_string()); // Rig ID args.push("--rig-id".to_string()); args.push(state.selected_rig.to_string()); // Rig ID

View file

@ -52,6 +52,7 @@ use std::{
// Sysinfo // Sysinfo
use sysinfo::SystemExt; use sysinfo::SystemExt;
// Modules // Modules
//mod benchmark;
mod ferris; mod ferris;
mod constants; mod constants;
mod node; mod node;