mirror of
https://github.com/TransparentLC/opencl_vanity_gpg.git
synced 2025-10-20 07:14:09 +00:00
chore: tidy up & make progress bar better
This commit is contained in:
parent
0b6038d395
commit
a50bbf356a
6 changed files with 82 additions and 54 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -994,6 +994,16 @@ dependencies = [
|
|||
"web-time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indicatif-log-bridge"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "63703cf9069b85dbe6fe26e1c5230d013dee99d3559cd3d02ba39e099ef7ab02"
|
||||
dependencies = [
|
||||
"indicatif",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "inout"
|
||||
version = "0.1.3"
|
||||
|
@ -1289,6 +1299,7 @@ dependencies = [
|
|||
"env_logger",
|
||||
"hex",
|
||||
"indicatif",
|
||||
"indicatif-log-bridge",
|
||||
"log",
|
||||
"ocl",
|
||||
"pgp",
|
||||
|
|
|
@ -23,3 +23,4 @@ rand = "0.8"
|
|||
smallvec = "1.13"
|
||||
anyhow = "1.0"
|
||||
indicatif = "0.17"
|
||||
indicatif-log-bridge = "0.2"
|
||||
|
|
51
src/main.rs
51
src/main.rs
|
@ -1,11 +1,9 @@
|
|||
use anyhow::bail;
|
||||
use indicatif::{ProgressBar, ProgressState, ProgressStyle};
|
||||
use log::{debug, info, warn};
|
||||
use log::*;
|
||||
use ocl::{Buffer, Device, Platform, ProQue};
|
||||
use pgp::types::PublicKeyTrait;
|
||||
use rand::thread_rng;
|
||||
use std::{
|
||||
fmt::Write,
|
||||
fs,
|
||||
path::Path,
|
||||
str::FromStr,
|
||||
|
@ -19,11 +17,7 @@ use utils::*;
|
|||
mod utils;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
env_logger::Builder::from_env(
|
||||
env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"),
|
||||
)
|
||||
.format_indent(None)
|
||||
.init();
|
||||
let bars = init_logger();
|
||||
|
||||
debug!("{:#?}", LazyLock::force(&ARGS));
|
||||
|
||||
|
@ -126,7 +120,8 @@ fn main() -> anyhow::Result<()> {
|
|||
thread::spawn(move || opencl_thread(buffer_result, pro_que, rx_hashdata, tx_result));
|
||||
|
||||
let bench_size = (dimension * iteration) as u64;
|
||||
let bar = init_progress_bar(estimate);
|
||||
let bar = bars.add(init_progress_bar(estimate));
|
||||
|
||||
loop {
|
||||
debug!("Send key to OpenCL thread");
|
||||
tx_hashdata.send(hashdata)?;
|
||||
|
@ -178,6 +173,8 @@ fn main() -> anyhow::Result<()> {
|
|||
}
|
||||
|
||||
if ARGS.oneshot {
|
||||
bar.finish();
|
||||
bars.clear()?;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -242,39 +239,3 @@ fn opencl_thread(
|
|||
}
|
||||
debug!("OpenCL thread quit");
|
||||
}
|
||||
|
||||
fn init_progress_bar(estimate: Option<f64>) -> ProgressBar {
|
||||
let bar = match estimate {
|
||||
Some(estimate) => ProgressBar::new(estimate as u64),
|
||||
None => ProgressBar::new_spinner(),
|
||||
};
|
||||
|
||||
bar.set_style(
|
||||
ProgressStyle::default_spinner()
|
||||
.template("[{elapsed_precise}] {bar:40.cyan/blue} {progress} {rate}")
|
||||
.unwrap()
|
||||
.progress_chars("##-")
|
||||
.with_key("progress", |state: &ProgressState, w: &mut dyn Write| {
|
||||
write!(
|
||||
w,
|
||||
"{}/{}",
|
||||
format_number(state.pos() as f64),
|
||||
match state.len() {
|
||||
None => "???".to_string(),
|
||||
Some(x) => format_number(x as f64),
|
||||
}
|
||||
)
|
||||
.unwrap()
|
||||
})
|
||||
.with_key("rate", |state: &ProgressState, w: &mut dyn Write| {
|
||||
write!(
|
||||
w,
|
||||
"{} hash/s",
|
||||
format_number((state.pos() as f64) / state.elapsed().as_secs_f64()),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
);
|
||||
|
||||
bar
|
||||
}
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
mod args;
|
||||
mod device;
|
||||
mod hash_pattern;
|
||||
mod vanity_secret_key;
|
||||
mod pattern;
|
||||
mod vanity_key;
|
||||
|
||||
use std::mem;
|
||||
use std::{fmt::Write, mem};
|
||||
|
||||
pub use args::*;
|
||||
pub use device::DeviceList;
|
||||
pub use hash_pattern::HashPattern;
|
||||
pub use vanity_secret_key::VanitySecretKey;
|
||||
pub use pattern::HashPattern;
|
||||
use indicatif::*;
|
||||
use indicatif_log_bridge::LogWrapper;
|
||||
pub use vanity_key::VanitySecretKey;
|
||||
|
||||
/// Do SHA-1 padding manually
|
||||
/// A SHA-1 block is 512 bit, so the output Vec<u32> length is a multiple of 16
|
||||
|
@ -44,19 +46,72 @@ pub fn manually_prepare_sha1(hashdata: Vec<u8>) -> Vec<u32> {
|
|||
result_u32
|
||||
}
|
||||
|
||||
pub fn init_logger() -> MultiProgress {
|
||||
let logger = env_logger::Builder::from_env(
|
||||
env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"),
|
||||
)
|
||||
.format_indent(None)
|
||||
.build();
|
||||
|
||||
let level = logger.filter();
|
||||
let multi = MultiProgress::new();
|
||||
|
||||
LogWrapper::new(multi.clone(), logger).try_init().unwrap();
|
||||
log::set_max_level(level);
|
||||
|
||||
multi
|
||||
}
|
||||
|
||||
pub fn init_progress_bar(estimate: Option<f64>) -> ProgressBar {
|
||||
let bar = match estimate {
|
||||
Some(estimate) => ProgressBar::new(estimate as u64),
|
||||
None => ProgressBar::new_spinner(),
|
||||
};
|
||||
|
||||
bar.set_style(
|
||||
ProgressStyle::default_spinner()
|
||||
.template("[{elapsed_precise}] {bar:50.cyan/blue} {progress} {rate} > {eta_precise}")
|
||||
.unwrap()
|
||||
.progress_chars("##-")
|
||||
.with_key("progress", |state: &ProgressState, w: &mut dyn Write| {
|
||||
write!(
|
||||
w,
|
||||
"{}/{}",
|
||||
format_number(state.pos() as f64),
|
||||
match state.len() {
|
||||
None => "???".to_string(),
|
||||
Some(x) => format_number(x as f64),
|
||||
}
|
||||
)
|
||||
.unwrap()
|
||||
})
|
||||
.with_key("rate", |state: &ProgressState, w: &mut dyn Write| {
|
||||
write!(
|
||||
w,
|
||||
"{} hash/s",
|
||||
format_number((state.pos() as f64) / state.elapsed().as_secs_f64()),
|
||||
)
|
||||
.unwrap()
|
||||
}),
|
||||
);
|
||||
|
||||
bar
|
||||
}
|
||||
|
||||
|
||||
pub fn format_number(v: impl Into<f64>) -> String {
|
||||
match Into::<f64>::into(v) {
|
||||
v if v >= 1e12f64 => {
|
||||
format!("{:.02}t", v / 1e12f64)
|
||||
format!("{:.02}T", v / 1e12f64)
|
||||
}
|
||||
v if v >= 1e9f64 => {
|
||||
format!("{:.02}b", v / 1e9f64)
|
||||
format!("{:.02}B", v / 1e9f64)
|
||||
}
|
||||
v if v >= 1e6f64 => {
|
||||
format!("{:.02}m", v / 1e6f64)
|
||||
format!("{:.02}M", v / 1e6f64)
|
||||
}
|
||||
v if v >= 1e3f64 => {
|
||||
format!("{:.02}k", v / 1e3f64)
|
||||
format!("{:.02}K", v / 1e3f64)
|
||||
}
|
||||
v => {
|
||||
format!("{v:.02}")
|
||||
|
|
Loading…
Add table
Reference in a new issue