mirror of
https://github.com/Cyrix126/gupaxx.git
synced 2024-12-22 14:49:21 +00:00
fix: getting current shares
fix: get the good pattern fix: use regex (perf improvements) fix: use error message in log instead of panic feat: add debug messages
This commit is contained in:
parent
d74e4c863a
commit
23fc9f3a39
3 changed files with 51 additions and 14 deletions
|
@ -5,6 +5,10 @@ use crate::disk::state::P2pool;
|
|||
use crate::helper::ProcessName;
|
||||
use crate::helper::ProcessSignal;
|
||||
use crate::helper::ProcessState;
|
||||
use crate::regex::contains_end_status;
|
||||
use crate::regex::contains_statuscommand;
|
||||
use crate::regex::contains_yourshare;
|
||||
use crate::regex::nb_current_shares;
|
||||
use crate::regex::P2POOL_REGEX;
|
||||
use crate::{
|
||||
constants::*,
|
||||
|
@ -58,19 +62,24 @@ impl Helper {
|
|||
while let Some(Ok(line)) = stdout.next() {
|
||||
// if command status is sent by gupaxx process and not the user, forward it only to update_from_status method.
|
||||
// 25 lines after the command are the result of status, with last line finishing by update.
|
||||
if line.contains("statusfromgupaxx") {
|
||||
if contains_statuscommand(&line) {
|
||||
status_output = true;
|
||||
continue;
|
||||
}
|
||||
if status_output {
|
||||
if line.contains("Your shares") {
|
||||
if contains_yourshare(&line) {
|
||||
// update sidechain shares
|
||||
// todo optimization: replace with regex
|
||||
// todo safety: do not panic but show error message to user
|
||||
let shares = line.split_once("=").expect("should be = at Your Share, maybe new version of p2pool has different output for status command ?").1.split_once("blocks").expect("should be a 'blocks' at Your Share, maybe new version of p2pool has different output for status command ?").0.trim().parse::<u32>().expect("this should be the number of share");
|
||||
lock!(pub_api).sidechain_shares = shares;
|
||||
if let Some(shares) = nb_current_shares(&line) {
|
||||
debug!(
|
||||
"P2pool | PTY getting current shares data from status: {} share",
|
||||
shares
|
||||
);
|
||||
lock!(pub_api).sidechain_shares = shares;
|
||||
} else {
|
||||
error!("P2pool | PTY Getting data from status: Lines contains Your shares but no value found: {}", line);
|
||||
}
|
||||
}
|
||||
if line.contains("Uptime") {
|
||||
if contains_end_status(&line) {
|
||||
// end of status
|
||||
status_output = false;
|
||||
}
|
||||
|
@ -667,7 +676,7 @@ impl Helper {
|
|||
}
|
||||
}
|
||||
if lock!(gui_api).tick_status >= 10 && lock!(process).state == ProcessState::Alive {
|
||||
debug!("reading status output of p2pool node");
|
||||
debug!("P2Pool Watchdog | Reading status output of p2pool node");
|
||||
#[cfg(target_os = "windows")]
|
||||
if let Err(e) = write!(stdin, "statusfromgupaxx\r\n") {
|
||||
error!("P2Pool Watchdog | STDIN error: {}", e);
|
||||
|
|
|
@ -464,12 +464,8 @@ pub const UNKNOWN_DATA: &str = "???";
|
|||
pub const BLOCK_PPLNS_WINDOW_MINI: u64 = 2160;
|
||||
pub const BLOCK_PPLNS_WINDOW_MAIN: u64 = 363;
|
||||
pub const SECOND_PER_BLOCK_P2POOL: u64 = 10;
|
||||
pub const TIME_PPLNS_WINDOW_MINI: Duration =
|
||||
Duration::from_secs(BLOCK_PPLNS_WINDOW_MINI * SECOND_PER_BLOCK_P2POOL);
|
||||
pub const TIME_PPLNS_WINDOW_MAIN: Duration =
|
||||
Duration::from_secs(BLOCK_PPLNS_WINDOW_MAIN * SECOND_PER_BLOCK_P2POOL);
|
||||
|
||||
use std::time::Duration;
|
||||
// pub const TIME_PPLNS_WINDOW_MINI: Duration = Duration::from_secs(BLOCK_PPLNS_WINDOW_MINI * SECOND_PER_BLOCK_P2POOL);
|
||||
// pub const TIME_PPLNS_WINDOW_MAIN: Duration = Duration::from_secs(BLOCK_PPLNS_WINDOW_MAIN * SECOND_PER_BLOCK_P2POOL);
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Visuals
|
||||
use egui::epaint::{Rounding, Shadow, Stroke};
|
||||
|
|
|
@ -129,6 +129,38 @@ pub fn num_lines(s: &str) -> usize {
|
|||
static LINE_BREAKS: Lazy<Regex> = Lazy::new(|| Regex::new(r"\r?\n").unwrap());
|
||||
LINE_BREAKS.captures_iter(s).count() + 1
|
||||
}
|
||||
// get the number of current shares
|
||||
pub fn nb_current_shares(s: &str) -> Option<u32> {
|
||||
static CURRENT_SHARE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"Your shares = (?P<nb>\d+) blocks").unwrap());
|
||||
if let Some(c) = CURRENT_SHARE.captures(s) {
|
||||
if let Some(m) = c.name("nb") {
|
||||
return Some(
|
||||
m.as_str().parse::<u32>().expect(
|
||||
&[
|
||||
"the number of shares should have been a unit number but is :\n",
|
||||
m.as_str(),
|
||||
]
|
||||
.concat(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
pub fn contains_statuscommand(l: &str) -> bool {
|
||||
static LINE_SHARE: Lazy<Regex> = Lazy::new(|| Regex::new(r"^statusfromgupaxx").unwrap());
|
||||
LINE_SHARE.is_match(l)
|
||||
}
|
||||
pub fn contains_yourshare(l: &str) -> bool {
|
||||
static LINE_SHARE: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"^Your shares = ").unwrap());
|
||||
LINE_SHARE.is_match(l)
|
||||
}
|
||||
pub fn contains_end_status(l: &str) -> bool {
|
||||
static LINE_SHARE: Lazy<Regex> = Lazy::new(|| Regex::new(r"^Uptime ").unwrap());
|
||||
LINE_SHARE.is_match(l)
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------- TEST
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
|
Loading…
Reference in a new issue