Skip to content

Commit

Permalink
Revert "feat: v3.0.0"
Browse files Browse the repository at this point in the history
This reverts commit db3ea60.
  • Loading branch information
skifli authored Oct 14, 2024
1 parent 81fe4a4 commit 65b9d9c
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 285 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"cSpell.language": "en-GB",
"cSpell.words": [
"ahash",
"axum",
"bruty",
"chrono",
Expand Down
3 changes: 1 addition & 2 deletions bruty_client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[package]
name = "bruty_client"
authors = ["skifli"]
version = "0.3.4"
version = "0.2.9"
edition = "2021"

[dependencies]
ahash = "0.8.11"
bytes = "1.7.2"
chrono = "0.4.38"
clap = { version = "4.5.18", features = ["derive"] }
Expand Down
124 changes: 19 additions & 105 deletions bruty_client/src/client_threads.rs
Original file line number Diff line number Diff line change
@@ -1,81 +1,19 @@
use ahash;
use sonic_rs;

struct IDCheckingStats {
total_checked: u16,
positives: Vec<bruty_share::types::Video>,
}

pub async fn results_handler(client_channels: &bruty_share::types::ClientChannels) {
let mut results_map: ahash::AHashMap<Vec<char>, IDCheckingStats> = ahash::AHashMap::new();

loop {
let video = client_channels.results_receiver.recv_async().await;

if video.is_err() {
// Client has probably disconnected.
return;
}

let video = video.unwrap();

let base_id: Vec<char> = video.id.iter().take(9).cloned().collect();
let base_id_clone = base_id.clone();

let stats = results_map.entry(base_id).or_insert(IDCheckingStats {
total_checked: 0,
positives: Vec::new(),
});

stats.total_checked += 1;

if video.event != bruty_share::types::VideoEvent::NotFound {
stats.positives.push(video);
}

if stats.total_checked == 4096 {
let base_id_clone_clone = base_id_clone.clone();

let positives_len = stats.positives.len();

log::info!(
"Tested {} with {} hit{}",
base_id_clone.iter().collect::<String>(),
positives_len,
if positives_len == 1 { "" } else { "s" },
);

client_channels
.payload_send_sender
.send(bruty_share::Payload {
op_code: bruty_share::OperationCode::TestingResult,
data: bruty_share::Data::TestingResult(bruty_share::TestingResultData {
id: base_id_clone,
positives: results_map.remove(&base_id_clone_clone).unwrap().positives,
}),
})
.unwrap();
}
}
}

/// Checks the IDs for validity.
///
/// # Arguments
/// * `reqwest_client` - The reqwest client, used for checking the IDs.
/// * `client_channels` - The client's channels, used for communication between threads.
pub async fn id_checker(
id_receiver: &flume::Receiver<Vec<char>>,
reqwest_client: &reqwest::Client,
client_channels: &bruty_share::types::ClientChannels,
positives_sender: &flume::Sender<bruty_share::types::Video>,
) {
let url_base = "https://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=".to_string();

loop {
let id = client_channels.id_receiver.recv_async().await;
let id = id_receiver.recv_async().await;

if id.is_err() {
// Client has probably disconnected.
return;
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;

continue;
}

let id = id.unwrap();
Expand All @@ -102,8 +40,7 @@ pub async fn id_checker(
let video_data: bruty_share::types::VideoData =
sonic_rs::from_str(&response.text().await.unwrap()).unwrap();

client_channels
.results_sender
positives_sender
.send(bruty_share::types::Video {
event: bruty_share::types::VideoEvent::Success,
id: id_vec,
Expand All @@ -114,8 +51,7 @@ pub async fn id_checker(
break;
}
401 => {
client_channels
.results_sender
positives_sender
.send(bruty_share::types::Video {
event: bruty_share::types::VideoEvent::NotEmbeddable,
id: id_vec,
Expand All @@ -126,8 +62,7 @@ pub async fn id_checker(
break;
}
404 | 400 => {
client_channels
.results_sender
positives_sender
.send(bruty_share::types::Video {
event: bruty_share::types::VideoEvent::NotFound,
id: id_vec,
Expand All @@ -149,47 +84,26 @@ pub async fn id_checker(
}
}

/// Generates the IDs to be checked based on the base ID.
/// Checks the video IDs.
///
/// # Arguments
/// * `base_id` - The base ID, which will be used to generate the IDs to be checked.
/// * `client_channels` - The client's channels, used for communication between threads.
pub fn generate_ids(mut base_id: Vec<char>, client_channels: &bruty_share::types::ClientChannels) {
if base_id.len() == 10 {
/// * `id_sender` - The sender for sending video IDs.
/// * `id` - The ID to check.
pub async fn generate_ids(id_sender: &flume::Sender<Vec<char>>, mut id: Vec<char>) {
if id.len() == 10 {
for &chr in bruty_share::VALID_CHARS {
base_id.push(chr); // No need to clone here because it was cloned for us by the recursive call
id.push(chr); // No need to clone here because it was cloned for us by the recursive call

client_channels.id_sender.send(base_id.clone()).unwrap();
id_sender.send(id.clone()).unwrap();

base_id.pop();
id.pop();
}
} else {
for &chr in bruty_share::VALID_CHARS {
let mut new_id: Vec<char> = base_id.clone();
let mut new_id = id.clone();
new_id.push(chr);

generate_ids(new_id, client_channels);
Box::pin(generate_ids(id_sender, new_id)).await;
}
}
}

/// Gets the base IDs to be checked, and generates the IDs to be checked based on them.
///
/// # Arguments
/// * `client_channels` - The client's channels, used for communication between threads.
pub async fn generate_all_ids(client_channels: &bruty_share::types::ClientChannels) {
loop {
let base_id = client_channels.base_id_receiver.recv_async().await;

if base_id.is_err() {
// Client has probably disconnected.
return;
}

let base_id = base_id.unwrap();

generate_ids(base_id.clone(), client_channels);

log::info!("Generated IDs for {}", base_id.iter().collect::<String>());
}
}
Loading

0 comments on commit 65b9d9c

Please sign in to comment.