Skip to content

Commit

Permalink
50 or less
Browse files Browse the repository at this point in the history
  • Loading branch information
ckcr4lyf committed Apr 2, 2022
1 parent 2536307 commit 8cbb7fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod byte_functions;
mod query;
mod db;

use actix_web::{get, App, HttpServer, Responder, web, HttpRequest, HttpResponse, http::StatusCode};
use actix_web::{get, App, HttpServer, Responder, web, HttpRequest, HttpResponse, http::header, http::StatusCode};
use rand::{thread_rng, prelude::SliceRandom};
use std::time::{SystemTime, UNIX_EPOCH, Duration};

Expand Down Expand Up @@ -152,10 +152,24 @@ async fn healthz(req: HttpRequest, data: web::Data<AppState>) -> HttpResponse {
println!("is_seeder: {}", is_seeder);
println!("is_leecher: {}", is_leecher);

let bruvva_res = query::announce_reply(seeders.len(), leechers.len(), &seeders[0..50], &leechers[0..50]);
// endex = end index XD. seems in rust cannot select first 50 elements, or limit to less if vector doesnt have 50
// e.g. &seeders[0..50] is panicking when seeders len is < 50. Oh well.
let seeder_endex = if seeders.len() >= 50 {
50
} else {
seeders.len()
};

let leecher_endex = if leechers.len() >= 50 {
50
} else {
leechers.len()
};

let bruvva_res = query::announce_reply(seeders.len(), leechers.len(), &seeders[0..seeder_endex], &leechers[0..leecher_endex]);

// return final_response;
return HttpResponse::build(StatusCode::OK).body(bruvva_res);
return HttpResponse::build(StatusCode::OK).append_header(header::ContentType::plaintext()).body(bruvva_res);
}

#[get("/announce")]
Expand Down
3 changes: 2 additions & 1 deletion src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ pub fn announce_reply(seeders_count: usize, leechers_count: usize, seeders: &[Ve
+ &"e10:incompletei".to_string()
+ &leechers_count.to_string()
+ &"e8:intervali1800e12:min intervali1800e5:peers".to_string()
+ &(peers_length * 6).to_string();
+ &(peers_length * 6).to_string()
+ &":";

let response_body: Vec<u8> = [response_body_string.into_bytes(), seeders.concat(), leechers.concat(), "e".as_bytes().to_vec()].concat() ;

Expand Down

0 comments on commit 8cbb7fd

Please sign in to comment.