From 88d674801ca478f59b9f501510bb293396b96f35 Mon Sep 17 00:00:00 2001 From: silt Date: Sun, 1 Oct 2023 22:43:16 -0400 Subject: [PATCH] move away from rayon --- Cargo.lock | 69 ----------------------------------------------------- Cargo.toml | 1 - src/main.rs | 34 +++++++++++++------------- 3 files changed, 18 insertions(+), 86 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 104e1cb..49ee1b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -208,39 +208,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crossbeam-deque" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" -dependencies = [ - "cfg-if", - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" -dependencies = [ - "autocfg", - "cfg-if", - "crossbeam-utils", - "memoffset", - "scopeguard", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" -dependencies = [ - "cfg-if", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -308,12 +275,6 @@ dependencies = [ "syn 2.0.37", ] -[[package]] -name = "either" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" - [[package]] name = "equivalent" version = "1.0.1" @@ -614,15 +575,6 @@ version = "2.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" -[[package]] -name = "memoffset" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" -dependencies = [ - "autocfg", -] - [[package]] name = "minimal-lexical" version = "0.2.1" @@ -842,26 +794,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "rayon" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", -] - [[package]] name = "redox_syscall" version = "0.3.5" @@ -1170,7 +1102,6 @@ dependencies = [ "age", "chrono", "glob-match", - "rayon", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 65b5f1c..41b7c00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -"rayon" = "1.8.0" "age" = "0.9.2" "glob-match" = "0.2.1" "chrono" = "0.4.31" diff --git a/src/main.rs b/src/main.rs index 6e7fbdd..39514b0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,8 +20,7 @@ use chrono::{ SecondsFormat, }; use glob_match::glob_match; -use rayon::prelude::*; -use std::{env, process}; +use std::{env, process, thread::{self, JoinHandle}, sync::{self, mpsc, Arc, Mutex}}; fn genpair() -> (String, String) { let key_priv = age::x25519::Identity::generate(); @@ -56,24 +55,27 @@ fn main() { format!("age1{}", args.last().unwrap().to_ascii_lowercase()) }; - let pairs = loop { - let pairs: Vec<(String, String)> = (0..=4096) - .into_par_iter() - .filter_map(|_| { + + let (tx, rx) = mpsc::sync_channel(1); + let mut threads: Vec> = Vec::new(); + for _ in 0..thread::available_parallelism().unwrap().get() { + let tx = tx.clone(); + let pattern = pattern.clone(); + threads.push(thread::spawn(move || { + loop { let keypair = genpair(); if try_pattern(pattern.clone(), keypair.1.clone()) { - Some(keypair) - } else { - None + tx.send(keypair).expect("no sendy :c"); + break; } - }) - .collect(); - if pairs.len() > 0 { - break pairs; - } - }; + }; + })) + } + + let keypair = rx.recv().expect("no receivey :c"); + + let (key_priv, key_pub) = keypair; - let (key_priv, key_pub) = pairs.first().unwrap(); let timestamp = Into::>::into(std::time::SystemTime::now()) .to_rfc3339_opts(SecondsFormat::Secs, false); println!("# created: {timestamp}\n# public key: {key_pub}\n{key_priv}");