From 3dd4159f4015bd2803de79716b0b03801b795cc1 Mon Sep 17 00:00:00 2001 From: skifli <121291719+skifli@users.noreply.github.com> Date: Tue, 1 Oct 2024 18:02:43 +0000 Subject: [PATCH] feat: server `v0.2.6.1` --- bruty_server/Cargo.toml | 2 +- bruty_server/src/server_threads.rs | 110 ++++++++++++++++------------- 2 files changed, 60 insertions(+), 52 deletions(-) diff --git a/bruty_server/Cargo.toml b/bruty_server/Cargo.toml index 5b22e43..00e3e7e 100644 --- a/bruty_server/Cargo.toml +++ b/bruty_server/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bruty_server" authors = ["skifli"] -version = "0.2.6" +version = "0.2.6.1" edition = "2021" [dependencies] diff --git a/bruty_server/src/server_threads.rs b/bruty_server/src/server_threads.rs index 744350a..4558543 100644 --- a/bruty_server/src/server_threads.rs +++ b/bruty_server/src/server_threads.rs @@ -78,16 +78,16 @@ pub async fn results_progress_handler( let mut awaiting_results = Vec::new(); let mut awaiting_current_id_update = Vec::new(); - let mut cant_update = Vec::new(); + let mut cant_update_awaiting_results = Vec::new(); loop { let current_id_receiver_try = current_id_receiver.try_recv(); if let Ok(id) = current_id_receiver_try { log::info!("Finished generating {}", id.iter().collect::()); - awaiting_current_id_update = id; // Get the current ID - cant_update.clear(); + awaiting_current_id_update.push(id.clone()); + cant_update_awaiting_results.clear(); } let results_awaiting_receiver_try = results_awaiting_receiver.try_recv(); @@ -105,59 +105,67 @@ pub async fn results_progress_handler( awaiting_results.retain(|x| x != &id); // Remove the ID from the list of awaiting results } - if !awaiting_current_id_update.is_empty() { - // Only want to update current ID when all awaiting IDs start with current ID. - // This means that we are not waiting for any results from the previous current ID. + if awaiting_current_id_update.len() > 0 { + for (index, id) in awaiting_current_id_update.clone().iter().enumerate() { + // Only want to update current ID when all awaiting IDs start with current ID. + // This means that we are not waiting for any results from the previous current ID. - if awaiting_results.iter().all(|testing_id| { - for (index, chr) in awaiting_current_id_update.iter().enumerate() { - let awaiting_char_position = bruty_share::VALID_CHARS - .iter() - .position(|&checking_chr| checking_chr == *chr) - .unwrap(); - - let testing_char_position = bruty_share::VALID_CHARS - .iter() - .position(|&checking_chr| checking_chr == testing_id[index]) - .unwrap(); + if awaiting_results.iter().all(|testing_id| { + for (index, chr) in id.iter().enumerate() { + let awaiting_char_position = bruty_share::VALID_CHARS + .iter() + .position(|&checking_chr| checking_chr == *chr) + .unwrap(); - if awaiting_char_position > testing_char_position { - return false; - } else if awaiting_char_position != testing_char_position { - return true; + let testing_char_position = bruty_share::VALID_CHARS + .iter() + .position(|&checking_chr| checking_chr == testing_id[index]) + .unwrap(); + + if awaiting_char_position > testing_char_position { + return false; + } else if awaiting_char_position != testing_char_position { + return true; + } } - } - return true; - }) { - state.current_id = awaiting_current_id_update.clone(); // Update the current ID - persist - .save( - "server_state", - bruty_share::types::ServerState { - current_id: state.current_id.clone(), - starting_id: state.starting_id.clone(), - }, - ) - .unwrap(); // Save the current ID to the database - - log::info!( - "Finished checking {}", - awaiting_current_id_update.iter().collect::() - ); - awaiting_current_id_update.clear(); // Clear the current ID - } else { - if cant_update.is_empty() { - cant_update = awaiting_current_id_update.clone(); - - log::warn!( - "Can't update current ID to {}, awaiting {:?}", - cant_update.iter().collect::(), - awaiting_results - .iter() - .map(|x| x.iter().collect::()) - .collect::>() + return true; + }) { + state.current_id = awaiting_current_id_update.remove(0); + + persist + .save( + "server_state", + bruty_share::types::ServerState { + current_id: state.current_id.clone(), + starting_id: state.starting_id.clone(), + }, + ) + .unwrap(); // Save the current ID to the database + + log::info!( + "Finished checking {}", + state.current_id.iter().collect::() ); + } else { + if cant_update_awaiting_results != awaiting_results { + log::warn!( + "Can't update current ID to {:?}[{}], awaiting {:?}", + awaiting_current_id_update + .iter() + .map(|x| x.iter().collect::()) + .collect::>(), + index, + awaiting_results + .iter() + .map(|x| x.iter().collect::()) + .collect::>() + ); + + cant_update_awaiting_results = awaiting_results.clone(); + } + + break; } } }