Compare commits

...

1 Commits

Author SHA1 Message Date
88d674801c move away from rayon 2023-10-01 22:43:16 -04:00
3 changed files with 18 additions and 86 deletions

69
Cargo.lock generated
View File

@ -208,39 +208,6 @@ dependencies = [
"libc", "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]] [[package]]
name = "crypto-common" name = "crypto-common"
version = "0.1.6" version = "0.1.6"
@ -308,12 +275,6 @@ dependencies = [
"syn 2.0.37", "syn 2.0.37",
] ]
[[package]]
name = "either"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]] [[package]]
name = "equivalent" name = "equivalent"
version = "1.0.1" version = "1.0.1"
@ -614,15 +575,6 @@ version = "2.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c"
[[package]]
name = "memoffset"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "minimal-lexical" name = "minimal-lexical"
version = "0.2.1" version = "0.2.1"
@ -842,26 +794,6 @@ dependencies = [
"rand_core 0.5.1", "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]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.3.5" version = "0.3.5"
@ -1170,7 +1102,6 @@ dependencies = [
"age", "age",
"chrono", "chrono",
"glob-match", "glob-match",
"rayon",
] ]
[[package]] [[package]]

View File

@ -6,7 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
"rayon" = "1.8.0"
"age" = "0.9.2" "age" = "0.9.2"
"glob-match" = "0.2.1" "glob-match" = "0.2.1"
"chrono" = "0.4.31" "chrono" = "0.4.31"

View File

@ -20,8 +20,7 @@ use chrono::{
SecondsFormat, SecondsFormat,
}; };
use glob_match::glob_match; use glob_match::glob_match;
use rayon::prelude::*; use std::{env, process, thread::{self, JoinHandle}, sync::{self, mpsc, Arc, Mutex}};
use std::{env, process};
fn genpair() -> (String, String) { fn genpair() -> (String, String) {
let key_priv = age::x25519::Identity::generate(); let key_priv = age::x25519::Identity::generate();
@ -56,24 +55,27 @@ fn main() {
format!("age1{}", args.last().unwrap().to_ascii_lowercase()) format!("age1{}", args.last().unwrap().to_ascii_lowercase())
}; };
let pairs = loop {
let pairs: Vec<(String, String)> = (0..=4096) let (tx, rx) = mpsc::sync_channel(1);
.into_par_iter() let mut threads: Vec<JoinHandle<()>> = Vec::new();
.filter_map(|_| { 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(); let keypair = genpair();
if try_pattern(pattern.clone(), keypair.1.clone()) { if try_pattern(pattern.clone(), keypair.1.clone()) {
Some(keypair) tx.send(keypair).expect("no sendy :c");
} else { break;
None
} }
}) };
.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::<DateTime<Local>>::into(std::time::SystemTime::now()) let timestamp = Into::<DateTime<Local>>::into(std::time::SystemTime::now())
.to_rfc3339_opts(SecondsFormat::Secs, false); .to_rfc3339_opts(SecondsFormat::Secs, false);
println!("# created: {timestamp}\n# public key: {key_pub}\n{key_priv}"); println!("# created: {timestamp}\n# public key: {key_pub}\n{key_priv}");