2022-10-14 21:13:38 +00:00
|
|
|
// 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/>.
|
|
|
|
|
2022-11-23 04:21:46 +00:00
|
|
|
use crate::{
|
|
|
|
constants::*,
|
|
|
|
};
|
update: save [Version] to state, use runtime [og: State]
[og: State] is now completely wrapped in an [Arc<Mutex>] so that
when the update is done, it can [.lock()] the CURRENT runtime
settings of the user and save to [gupax.toml] instead of using an
old copy that was given to it at the beginning of the thread.
In practice, this means users can change settings around during
an update and the update finishing and saving to disk won't be
using their old settings, but the current ones. Wrapping all of
[og: State] within in [Arc<Mutex>] might be overkill compared to
message channels but [State] really is just a few [bool]'s, [u*],
and small [String]'s, so it's not much data.
To bypass a deadlock when comparing [og == state] every frame,
[og]'s struct fields get cloned every frame into separate
variables, then it gets compared. This is also pretty stupid, but
again, the data being cloned is so tiny that it doesn't seem to
slow anything down.
2022-11-02 17:58:44 +00:00
|
|
|
use serde::{Serialize,Deserialize};
|
2022-12-17 03:39:34 +00:00
|
|
|
use rand::{thread_rng, Rng};
|
2022-10-14 21:13:38 +00:00
|
|
|
use std::time::{Instant,Duration};
|
2022-11-11 02:20:31 +00:00
|
|
|
use std::sync::{Arc,Mutex};
|
2022-10-14 21:13:38 +00:00
|
|
|
use egui::Color32;
|
|
|
|
use log::*;
|
2022-11-21 01:21:47 +00:00
|
|
|
use hyper::{
|
|
|
|
client::HttpConnector,
|
|
|
|
Client,Body,Request,
|
|
|
|
};
|
2022-11-18 03:45:57 +00:00
|
|
|
|
2022-11-11 02:20:31 +00:00
|
|
|
//---------------------------------------------------------------------------------------------------- Node list
|
2022-11-23 04:10:06 +00:00
|
|
|
// Community Monerod nodes. ALL BUT ONE of these have ZMQ on 18083 (plowsof pls)
|
2022-10-14 21:13:38 +00:00
|
|
|
// Adding/removing nodes will need changes to pretty
|
|
|
|
// much all the code in this file, and the code that
|
|
|
|
// handles the actual Enum selector in the P2Pool tab.
|
2022-11-24 04:03:56 +00:00
|
|
|
pub const C3POOL: &str = "node.c3pool.com:18081";
|
|
|
|
pub const CAKE: &str = "xmr-node.cakewallet.com:18081";
|
|
|
|
pub const CAKE_EU: &str = "xmr-node-eu.cakewallet.com:18081";
|
|
|
|
pub const CAKE_UK: &str = "xmr-node-uk.cakewallet.com:18081";
|
|
|
|
pub const CAKE_US: &str = "xmr-node-usa-east.cakewallet.com:18081";
|
|
|
|
pub const FEATHER_1: &str = "selsta1.featherwallet.net:18081";
|
|
|
|
pub const FEATHER_2: &str = "selsta2.featherwallet.net:18081";
|
|
|
|
pub const MAJESTICBANK_IS: &str = "node.majesticbank.is:18089";
|
|
|
|
pub const MAJESTICBANK_SU: &str = "node.majesticbank.su:18089";
|
|
|
|
pub const MONERUJO: &str = "nodex.monerujo.io:18081";
|
|
|
|
pub const PLOWSOF_1: &str = "node.monerodevs.org:18089"; // ZMQ = 18084
|
|
|
|
pub const PLOWSOF_2: &str = "node2.monerodevs.org:18089"; // ZMQ = 18084
|
|
|
|
pub const RINO: &str = "node.community.rino.io:18081";
|
|
|
|
pub const SETH: &str = "node.sethforprivacy.com:18089";
|
|
|
|
pub const SUPPORTXMR: &str = "node.supportxmr.com:18081";
|
|
|
|
pub const SUPPORTXMR_IR: &str = "node.supportxmr.ir:18081";
|
|
|
|
pub const XMRVSBEAST: &str = "p2pmd.xmrvsbeast.com:18081";
|
2022-10-14 21:13:38 +00:00
|
|
|
|
2022-12-15 02:09:37 +00:00
|
|
|
pub const NODE_IPS: [&str; 17] = [
|
2022-11-17 18:03:45 +00:00
|
|
|
C3POOL,CAKE,CAKE_EU,CAKE_UK,CAKE_US,FEATHER_1,FEATHER_2,MAJESTICBANK_IS,MAJESTICBANK_SU,
|
2022-12-15 02:09:37 +00:00
|
|
|
MONERUJO,PLOWSOF_1,PLOWSOF_2,RINO,SETH,SUPPORTXMR,SUPPORTXMR_IR,XMRVSBEAST,
|
2022-10-16 21:29:24 +00:00
|
|
|
];
|
|
|
|
|
2022-12-17 03:39:34 +00:00
|
|
|
pub const COMMUNITY_NODE_LENGTH: usize = NODE_IPS.len();
|
|
|
|
|
2022-11-11 02:20:31 +00:00
|
|
|
#[derive(Copy,Clone,Eq,PartialEq,Debug,Deserialize,Serialize)]
|
|
|
|
pub enum NodeEnum {
|
2022-11-23 04:10:06 +00:00
|
|
|
C3pool,Cake,CakeEu,CakeUk,CakeUs,MajesticBankIs,MajesticBankSu,Monerujo,Plowsof1,
|
2022-12-15 02:09:37 +00:00
|
|
|
Plowsof2,Rino,Feather1,Feather2,Seth,SupportXmr,SupportXmrIr,XmrVsBeast,
|
2022-10-14 21:13:38 +00:00
|
|
|
}
|
|
|
|
|
2022-12-17 03:39:34 +00:00
|
|
|
impl NodeEnum {
|
|
|
|
fn get_index(&self) -> usize {
|
|
|
|
match self {
|
|
|
|
C3pool => 0,
|
|
|
|
Cake => 1,
|
|
|
|
CakeEu => 2,
|
|
|
|
CakeUk => 3,
|
|
|
|
CakeUs => 4,
|
|
|
|
Feather1 => 5,
|
|
|
|
Feather2 => 6,
|
|
|
|
MajesticBankIs => 7,
|
|
|
|
MajesticBankSu => 8,
|
|
|
|
Monerujo => 9,
|
|
|
|
Plowsof1 => 10,
|
|
|
|
Plowsof2 => 11,
|
|
|
|
Rino => 12,
|
|
|
|
Seth => 13,
|
|
|
|
SupportXmr => 14,
|
|
|
|
SupportXmrIr => 15,
|
|
|
|
_ => 16,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return a random node (that isn't the one already selected).
|
|
|
|
pub fn get_random(&self) -> Self {
|
|
|
|
let index = Self::get_index(self);
|
|
|
|
let mut rand = thread_rng().gen_range(0..COMMUNITY_NODE_LENGTH);
|
|
|
|
while rand == index {
|
|
|
|
rand = thread_rng().gen_range(0..COMMUNITY_NODE_LENGTH);
|
|
|
|
}
|
|
|
|
ip_to_enum(NODE_IPS[rand])
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the node [-1] of this one (wraps around)
|
|
|
|
pub fn get_last(&self) -> Self {
|
|
|
|
let index = Self::get_index(self);
|
|
|
|
if index == 0 {
|
|
|
|
ip_to_enum(NODE_IPS[COMMUNITY_NODE_LENGTH-1])
|
|
|
|
} else {
|
|
|
|
ip_to_enum(NODE_IPS[index-1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the node [+1] of this one (wraps around)
|
|
|
|
pub fn get_next(&self) -> Self {
|
|
|
|
let index = Self::get_index(self);
|
|
|
|
if index == COMMUNITY_NODE_LENGTH-1 {
|
|
|
|
ip_to_enum(NODE_IPS[0])
|
|
|
|
} else {
|
|
|
|
ip_to_enum(NODE_IPS[index+1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This returns relative to the ping.
|
|
|
|
pub fn get_last_from_ping(&self, nodes: &Vec<NodeData>) -> Self {
|
|
|
|
let mut found = false;
|
|
|
|
let mut last = *self;
|
|
|
|
for data in nodes {
|
|
|
|
if found { return last }
|
|
|
|
if *self == data.id { found = true; } else { last = data.id; }
|
|
|
|
}
|
|
|
|
last
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_next_from_ping(&self, nodes: &Vec<NodeData>) -> Self {
|
|
|
|
let mut found = false;
|
|
|
|
for data in nodes {
|
|
|
|
if found { return data.id }
|
|
|
|
if *self == data.id { found = true; }
|
|
|
|
}
|
|
|
|
*self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-11 02:20:31 +00:00
|
|
|
impl std::fmt::Display for NodeEnum {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
write!(f, "{:#?}", self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------- Node data
|
2022-11-18 19:25:13 +00:00
|
|
|
#[derive(Debug, Clone)]
|
2022-11-11 02:20:31 +00:00
|
|
|
pub struct NodeData {
|
2022-10-14 21:13:38 +00:00
|
|
|
pub id: NodeEnum,
|
2022-10-16 21:29:24 +00:00
|
|
|
pub ip: &'static str,
|
2022-11-11 02:20:31 +00:00
|
|
|
pub ms: u128,
|
|
|
|
pub color: Color32,
|
2022-10-14 21:13:38 +00:00
|
|
|
}
|
|
|
|
|
2022-11-11 02:20:31 +00:00
|
|
|
impl NodeData {
|
|
|
|
pub fn new_vec() -> Vec<Self> {
|
|
|
|
let mut vec = Vec::new();
|
2022-11-18 03:45:57 +00:00
|
|
|
for ip in NODE_IPS {
|
2022-11-11 02:20:31 +00:00
|
|
|
vec.push(Self {
|
|
|
|
id: ip_to_enum(ip),
|
|
|
|
ip,
|
|
|
|
ms: 0,
|
|
|
|
color: Color32::LIGHT_GRAY,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
vec
|
|
|
|
}
|
2022-10-14 21:13:38 +00:00
|
|
|
}
|
|
|
|
|
2022-11-11 02:20:31 +00:00
|
|
|
//---------------------------------------------------------------------------------------------------- IP <-> Enum functions
|
2022-11-18 19:25:13 +00:00
|
|
|
use crate::NodeEnum::*;
|
2022-11-11 02:20:31 +00:00
|
|
|
// Function for returning IP/Enum
|
|
|
|
pub fn ip_to_enum(ip: &'static str) -> NodeEnum {
|
|
|
|
match ip {
|
|
|
|
C3POOL => C3pool,
|
|
|
|
CAKE => Cake,
|
|
|
|
CAKE_EU => CakeEu,
|
|
|
|
CAKE_UK => CakeUk,
|
|
|
|
CAKE_US => CakeUs,
|
2022-11-17 18:03:45 +00:00
|
|
|
FEATHER_1 => Feather1,
|
|
|
|
FEATHER_2 => Feather2,
|
2022-11-11 02:20:31 +00:00
|
|
|
MAJESTICBANK_IS => MajesticBankIs,
|
|
|
|
MAJESTICBANK_SU => MajesticBankSu,
|
|
|
|
MONERUJO => Monerujo,
|
2022-11-23 04:10:06 +00:00
|
|
|
PLOWSOF_1 => Plowsof1,
|
|
|
|
PLOWSOF_2 => Plowsof2,
|
2022-11-11 02:20:31 +00:00
|
|
|
RINO => Rino,
|
|
|
|
SETH => Seth,
|
|
|
|
SUPPORTXMR => SupportXmr,
|
|
|
|
SUPPORTXMR_IR => SupportXmrIr,
|
|
|
|
_ => XmrVsBeast,
|
2022-10-14 21:13:38 +00:00
|
|
|
}
|
2022-11-11 02:20:31 +00:00
|
|
|
}
|
2022-10-14 21:13:38 +00:00
|
|
|
|
2022-11-11 02:20:31 +00:00
|
|
|
pub fn enum_to_ip(node: NodeEnum) -> &'static str {
|
|
|
|
match node {
|
|
|
|
C3pool => C3POOL,
|
|
|
|
Cake => CAKE,
|
|
|
|
CakeEu => CAKE_EU,
|
|
|
|
CakeUk => CAKE_UK,
|
|
|
|
CakeUs => CAKE_US,
|
2022-11-17 18:03:45 +00:00
|
|
|
Feather1 => FEATHER_1,
|
|
|
|
Feather2 => FEATHER_2,
|
2022-11-11 02:20:31 +00:00
|
|
|
MajesticBankIs => MAJESTICBANK_IS,
|
|
|
|
MajesticBankSu => MAJESTICBANK_SU,
|
|
|
|
Monerujo => MONERUJO,
|
2022-11-23 04:10:06 +00:00
|
|
|
Plowsof1 => PLOWSOF_1,
|
|
|
|
Plowsof2 => PLOWSOF_2,
|
2022-11-11 02:20:31 +00:00
|
|
|
Rino => RINO,
|
|
|
|
Seth => SETH,
|
|
|
|
SupportXmr => SUPPORTXMR,
|
|
|
|
SupportXmrIr => SUPPORTXMR_IR,
|
|
|
|
_ => XMRVSBEAST
|
|
|
|
}
|
|
|
|
}
|
2022-10-14 21:13:38 +00:00
|
|
|
|
2022-12-03 18:37:57 +00:00
|
|
|
// Returns a tuple of (IP, RPC_PORT, ZMQ_PORT)
|
|
|
|
pub fn enum_to_ip_rpc_zmq_tuple(node: NodeEnum) -> (&'static str, &'static str, &'static str) {
|
|
|
|
// [.unwrap()] should be safe, IP:PORTs are constants after all.
|
|
|
|
let (ip, rpc) = enum_to_ip(node).rsplit_once(':').unwrap();
|
|
|
|
// Get ZMQ, grr... plowsof is the only 18084 zmq person.
|
|
|
|
let zmq = match node {
|
|
|
|
Plowsof1|Plowsof2 => "18084",
|
|
|
|
_ => "18083",
|
|
|
|
};
|
|
|
|
(ip, rpc, zmq)
|
|
|
|
}
|
|
|
|
|
2022-11-11 02:20:31 +00:00
|
|
|
// 5000 = 4 max length
|
|
|
|
pub fn format_ms(ms: u128) -> String {
|
|
|
|
match ms.to_string().len() {
|
|
|
|
1 => format!("{}ms ", ms),
|
|
|
|
2 => format!("{}ms ", ms),
|
|
|
|
3 => format!("{}ms ", ms),
|
|
|
|
_ => format!("{}ms", ms),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MajesticBankIs = 14 max length
|
|
|
|
pub fn format_enum(id: NodeEnum) -> String {
|
|
|
|
match id.to_string().len() {
|
|
|
|
1 => format!("{} ", id),
|
|
|
|
2 => format!("{} ", id),
|
|
|
|
3 => format!("{} ", id),
|
|
|
|
4 => format!("{} ", id),
|
|
|
|
5 => format!("{} ", id),
|
|
|
|
6 => format!("{} ", id),
|
|
|
|
7 => format!("{} ", id),
|
|
|
|
8 => format!("{} ", id),
|
|
|
|
9 => format!("{} ", id),
|
|
|
|
10 => format!("{} ", id),
|
|
|
|
11 => format!("{} ", id),
|
|
|
|
12 => format!("{} ", id),
|
|
|
|
13 => format!("{} ", id),
|
|
|
|
_ => format!("{}", id),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-20 19:20:25 +00:00
|
|
|
//---------------------------------------------------------------------------------------------------- Ping data
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Ping {
|
|
|
|
pub nodes: Vec<NodeData>,
|
|
|
|
pub fastest: NodeEnum,
|
|
|
|
pub pinging: bool,
|
|
|
|
pub msg: String,
|
|
|
|
pub prog: f32,
|
|
|
|
pub pinged: bool,
|
|
|
|
pub auto_selected: bool,
|
|
|
|
}
|
2022-11-18 03:45:57 +00:00
|
|
|
|
2022-12-14 03:41:05 +00:00
|
|
|
impl Default for Ping {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-20 19:20:25 +00:00
|
|
|
impl Ping {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self {
|
|
|
|
nodes: NodeData::new_vec(),
|
|
|
|
fastest: NodeEnum::C3pool,
|
|
|
|
pinging: false,
|
|
|
|
msg: "No ping in progress".to_string(),
|
|
|
|
prog: 0.0,
|
|
|
|
pinged: false,
|
|
|
|
auto_selected: true,
|
|
|
|
}
|
|
|
|
}
|
2022-11-18 03:45:57 +00:00
|
|
|
|
2022-11-20 19:20:25 +00:00
|
|
|
//---------------------------------------------------------------------------------------------------- Main Ping function
|
2022-11-21 01:21:47 +00:00
|
|
|
// Intermediate function for spawning thread
|
2022-12-10 02:00:33 +00:00
|
|
|
pub fn spawn_thread(ping: &Arc<Mutex<Self>>) {
|
2022-12-12 19:34:17 +00:00
|
|
|
info!("Spawning ping thread...");
|
2022-11-24 04:03:56 +00:00
|
|
|
let ping = Arc::clone(ping);
|
2022-11-20 19:20:25 +00:00
|
|
|
std::thread::spawn(move|| {
|
2022-12-12 19:34:17 +00:00
|
|
|
let now = Instant::now();
|
|
|
|
match Self::ping(&ping) {
|
|
|
|
Ok(msg) => {
|
2022-11-22 01:10:47 +00:00
|
|
|
info!("Ping ... OK");
|
2022-12-12 19:34:17 +00:00
|
|
|
ping.lock().unwrap().msg = msg;
|
2022-11-22 01:10:47 +00:00
|
|
|
ping.lock().unwrap().pinged = true;
|
|
|
|
ping.lock().unwrap().auto_selected = false;
|
2022-12-17 03:39:34 +00:00
|
|
|
ping.lock().unwrap().prog = 100.0;
|
2022-11-22 01:10:47 +00:00
|
|
|
},
|
2022-11-20 19:20:25 +00:00
|
|
|
Err(err) => {
|
|
|
|
error!("Ping ... FAIL ... {}", err);
|
|
|
|
ping.lock().unwrap().pinged = false;
|
|
|
|
ping.lock().unwrap().msg = err.to_string();
|
|
|
|
},
|
2022-12-10 02:00:33 +00:00
|
|
|
}
|
2022-12-12 19:34:17 +00:00
|
|
|
info!("Ping ... Took [{}] seconds...", now.elapsed().as_secs_f32());
|
2022-11-20 19:20:25 +00:00
|
|
|
ping.lock().unwrap().pinging = false;
|
|
|
|
});
|
2022-11-18 03:45:57 +00:00
|
|
|
}
|
|
|
|
|
2022-11-20 19:20:25 +00:00
|
|
|
// This is for pinging the community nodes to
|
|
|
|
// find the fastest/slowest one for the user.
|
|
|
|
// The process:
|
|
|
|
// - Send [get_info] JSON-RPC request over HTTP to all IPs
|
|
|
|
// - Measure each request in milliseconds
|
|
|
|
// - Timeout on requests over 5 seconds
|
|
|
|
// - Add data to appropriate struct
|
|
|
|
// - Sorting fastest to lowest is automatic (fastest nodes return ... the fastest)
|
|
|
|
//
|
|
|
|
// This used to be done 3x linearly but after testing, sending a single
|
|
|
|
// JSON-RPC call to all IPs asynchronously resulted in the same data.
|
|
|
|
//
|
|
|
|
// <300ms = GREEN
|
|
|
|
// <1000ms = YELLOW
|
|
|
|
// >1000ms = RED
|
|
|
|
// timeout = BLACK
|
|
|
|
// default = GRAY
|
|
|
|
#[tokio::main]
|
2022-12-12 19:34:17 +00:00
|
|
|
pub async fn ping(ping: &Arc<Mutex<Self>>) -> Result<String, anyhow::Error> {
|
2022-11-20 19:20:25 +00:00
|
|
|
// Start ping
|
2022-12-14 03:41:05 +00:00
|
|
|
let ping = Arc::clone(ping);
|
2022-11-20 19:20:25 +00:00
|
|
|
ping.lock().unwrap().pinging = true;
|
|
|
|
ping.lock().unwrap().prog = 0.0;
|
2022-12-17 03:39:34 +00:00
|
|
|
let percent = (100.0 / (COMMUNITY_NODE_LENGTH as f32)).floor();
|
2022-11-20 19:20:25 +00:00
|
|
|
|
|
|
|
// Create HTTP client
|
2022-11-24 04:03:56 +00:00
|
|
|
let info = "Creating HTTP Client".to_string();
|
2022-11-20 19:20:25 +00:00
|
|
|
ping.lock().unwrap().msg = info;
|
2022-11-21 01:21:47 +00:00
|
|
|
let client: Client<HttpConnector> = Client::builder()
|
|
|
|
.build(HttpConnector::new());
|
2022-11-20 19:20:25 +00:00
|
|
|
|
|
|
|
// Random User Agent
|
|
|
|
let rand_user_agent = crate::Pkg::get_user_agent();
|
|
|
|
// Handle vector
|
2022-12-17 03:39:34 +00:00
|
|
|
let mut handles = Vec::with_capacity(COMMUNITY_NODE_LENGTH);
|
|
|
|
let node_vec = Arc::new(Mutex::new(Vec::with_capacity(COMMUNITY_NODE_LENGTH)));
|
2022-11-20 19:20:25 +00:00
|
|
|
|
|
|
|
for ip in NODE_IPS {
|
|
|
|
let client = client.clone();
|
|
|
|
let ping = Arc::clone(&ping);
|
|
|
|
let node_vec = Arc::clone(&node_vec);
|
2022-11-21 01:21:47 +00:00
|
|
|
let request = Request::builder()
|
2022-11-20 19:20:25 +00:00
|
|
|
.method("POST")
|
|
|
|
.uri("http://".to_string() + ip + "/json_rpc")
|
|
|
|
.header("User-Agent", rand_user_agent)
|
|
|
|
.body(hyper::Body::from(r#"{"jsonrpc":"2.0","id":"0","method":"get_info"}"#))
|
|
|
|
.unwrap();
|
2022-12-17 00:16:16 +00:00
|
|
|
let handle = tokio::task::spawn(async move { Self::response(client, request, ip, ping, percent, node_vec).await; });
|
2022-11-20 19:20:25 +00:00
|
|
|
handles.push(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
for handle in handles {
|
2022-12-17 15:09:50 +00:00
|
|
|
handle.await?;
|
2022-11-20 19:20:25 +00:00
|
|
|
}
|
|
|
|
|
2022-12-12 19:34:17 +00:00
|
|
|
let node_vec = std::mem::take(&mut *node_vec.lock().unwrap());
|
|
|
|
let fastest_info = format!("Fastest node: {}ms ... {} @ {}", node_vec[0].ms, node_vec[0].id, node_vec[0].ip);
|
|
|
|
|
2022-12-14 03:41:05 +00:00
|
|
|
let info = "Cleaning up connections".to_string();
|
2022-12-12 19:34:17 +00:00
|
|
|
info!("Ping | {}...", info);
|
2022-11-20 19:20:25 +00:00
|
|
|
let mut ping = ping.lock().unwrap();
|
|
|
|
ping.fastest = node_vec[0].id;
|
|
|
|
ping.nodes = node_vec;
|
|
|
|
ping.msg = info;
|
|
|
|
drop(ping);
|
2022-12-12 19:34:17 +00:00
|
|
|
Ok(fastest_info)
|
2022-11-18 03:45:57 +00:00
|
|
|
}
|
|
|
|
|
2022-11-21 01:21:47 +00:00
|
|
|
async fn response(client: Client<HttpConnector>, request: Request<Body>, ip: &'static str, ping: Arc<Mutex<Self>>, percent: f32, node_vec: Arc<Mutex<Vec<NodeData>>>) {
|
2022-11-20 19:20:25 +00:00
|
|
|
let id = ip_to_enum(ip);
|
|
|
|
let ms;
|
|
|
|
let info;
|
2022-12-14 03:41:05 +00:00
|
|
|
let now = Instant::now();
|
2022-11-20 19:20:25 +00:00
|
|
|
match tokio::time::timeout(Duration::from_secs(5), client.request(request)).await {
|
|
|
|
Ok(_) => {
|
|
|
|
ms = now.elapsed().as_millis();
|
|
|
|
info = format!("{}ms ... {}: {}", ms, id, ip);
|
|
|
|
info!("Ping | {}", info)
|
|
|
|
},
|
cargo/tor/p2pool: clean deps, warn macos arti, fix node overflow
Cargo: Cleanup unused dependencies, enable some build optimizations
Tor: Arti doesn't seem to work on macOS
Even a bare Arti+Hyper request doesn't seem to work, so it's
probably not something to do with Gupax. A lot of issues only
seem to popup in a VM (OpenGL, TLS) even though on bare metal
Gupax runs fine, so Tor might work fine on real macOS but I don't
have real macOS to test it. VM macOS can't create a circuit, so,
disable by default and add a warning that it's unstable.
P2Pool: Let selected_index start at 0, and only +1 when printing
to the user, this makes the overflow math when adding/deleting a
lot more simple because selected_index will match the actual index
of the node vector
2022-11-21 22:16:31 +00:00
|
|
|
Err(_) => {
|
2022-11-20 19:20:25 +00:00
|
|
|
ms = 5000;
|
|
|
|
info = format!("{}ms ... {}: {}", ms, id, ip);
|
|
|
|
warn!("Ping | {}", info)
|
|
|
|
},
|
|
|
|
};
|
|
|
|
let color;
|
|
|
|
if ms < 300 {
|
2022-11-23 04:21:46 +00:00
|
|
|
color = GREEN;
|
2022-11-20 19:20:25 +00:00
|
|
|
} else if ms < 1000 {
|
2022-11-23 04:21:46 +00:00
|
|
|
color = YELLOW;
|
2022-11-20 19:20:25 +00:00
|
|
|
} else if ms < 5000 {
|
2022-11-23 04:21:46 +00:00
|
|
|
color = RED;
|
2022-11-20 19:20:25 +00:00
|
|
|
} else {
|
2022-11-23 04:21:46 +00:00
|
|
|
color = BLACK;
|
2022-11-20 19:20:25 +00:00
|
|
|
}
|
|
|
|
let mut ping = ping.lock().unwrap();
|
2022-11-18 19:25:13 +00:00
|
|
|
ping.msg = info;
|
2022-11-20 19:20:25 +00:00
|
|
|
ping.prog += percent;
|
2022-11-18 19:25:13 +00:00
|
|
|
drop(ping);
|
2022-11-20 19:20:25 +00:00
|
|
|
node_vec.lock().unwrap().push(NodeData { id: ip_to_enum(ip), ip, ms, color, });
|
2022-10-14 21:13:38 +00:00
|
|
|
}
|
|
|
|
}
|