Skip to content

Commit

Permalink
Added enhancement and bug fixes, need one more check before releasing…
Browse files Browse the repository at this point in the history
… as v4.0.2
  • Loading branch information
Power2All committed Oct 21, 2024
1 parent 579d4fe commit 8f59500
Show file tree
Hide file tree
Showing 47 changed files with 2,718 additions and 1,741 deletions.
57 changes: 27 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "torrust-actix"
version = "4.0.1"
version = "4.0.2"
edition = "2021"
license = "AGPL-3.0"
authors = [
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ Swagger UI is introduced, and when enabled in the configuration, is accessible t

### ChangeLog

#### v4.0.2
* Added option that the system will remove data from database.
* Added updates variables for the white/black list and keys tables.
* Renaming the "database" naming which should be "tables".
* A lot of fixes and bugs I stumbled upon.

#### v4.0.0
* Completely rebuilt of the tracker code, for readability.
* Moved to Actix v4, thus versioning this software to v4.0.0 as well.
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM rust:alpine

RUN apk add git musl-dev curl
RUN git clone https://github.com/Power2All/torrust-actix.git /tmp/torrust-actix
RUN cd /tmp/torrust-actix && git checkout tags/v4.0.1
RUN cd /tmp/torrust-actix && git checkout tags/v4.0.2
WORKDIR /tmp/torrust-actix
RUN cd /tmp/torrust-actix
RUN cargo build --release && rm -Rf target/release/.fingerprint target/release/build target/release/deps target/release/examples target/release/incremental
Expand Down
17 changes: 17 additions & 0 deletions src/api/api_blacklists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::api::api::{api_parse_body, api_service_token, api_validation};
use crate::api::structs::api_service_data::ApiServiceData;
use crate::api::structs::query_token::QueryToken;
use crate::common::common::hex2bin;
use crate::tracker::enums::updates_action::UpdatesAction;
use crate::tracker::structs::info_hash::InfoHash;

pub async fn api_service_blacklist_get(request: HttpRequest, path: web::Path<String>, data: Data<Arc<ApiServiceData>>) -> HttpResponse
Expand Down Expand Up @@ -88,6 +89,10 @@ pub async fn api_service_blacklist_post(request: HttpRequest, path: web::Path<St
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid info_hash {}", info)})); }
};

if data.torrent_tracker.config.database.clone().unwrap().persistent {
let _ = data.torrent_tracker.add_blacklist_update(info_hash, UpdatesAction::Add);
}

return match data.torrent_tracker.add_blacklist(info_hash) {
true => { HttpResponse::Ok().content_type(ContentType::json()).json(json!({"status": "ok"})) }
false => { HttpResponse::NotModified().content_type(ContentType::json()).json(json!({"status": format!("info_hash updated {}", info)})) }
Expand Down Expand Up @@ -124,6 +129,10 @@ pub async fn api_service_blacklists_post(request: HttpRequest, payload: web::Pay
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid info_hash {}", info)})) }
};

if data.torrent_tracker.config.database.clone().unwrap().persistent {
let _ = data.torrent_tracker.add_blacklist_update(info_hash, UpdatesAction::Add);
}

match data.torrent_tracker.add_blacklist(info_hash) {
true => { blacklists_output.insert(info_hash, json!({"status": "ok"})); }
false => { blacklists_output.insert(info_hash, json!({"status": "info_hash updated"})); }
Expand Down Expand Up @@ -153,6 +162,10 @@ pub async fn api_service_blacklist_delete(request: HttpRequest, path: web::Path<
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid info_hash {}", info)})); }
};

if data.torrent_tracker.config.database.clone().unwrap().persistent {
let _ = data.torrent_tracker.add_blacklist_update(info_hash, UpdatesAction::Remove);
}

return match data.torrent_tracker.remove_blacklist(info_hash) {
true => { HttpResponse::Ok().content_type(ContentType::json()).json(json!({"status": "ok"})) }
false => { HttpResponse::NotModified().content_type(ContentType::json()).json(json!({"status": format!("unknown info_hash {}", info)})) }
Expand Down Expand Up @@ -189,6 +202,10 @@ pub async fn api_service_blacklists_delete(request: HttpRequest, payload: web::P
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid info_hash {}", info)})) }
};

if data.torrent_tracker.config.database.clone().unwrap().persistent {
let _ = data.torrent_tracker.add_blacklist_update(info_hash, UpdatesAction::Remove);
}

match data.torrent_tracker.remove_blacklist(info_hash) {
true => { blacklists_output.insert(info_hash, json!({"status": "ok"})); }
false => { blacklists_output.insert(info_hash, json!({"status": "unknown info_hash"})); }
Expand Down
25 changes: 21 additions & 4 deletions src/api/api_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::api::api::{api_parse_body, api_service_token, api_validation};
use crate::api::structs::api_service_data::ApiServiceData;
use crate::api::structs::query_token::QueryToken;
use crate::common::common::hex2bin;
use crate::tracker::enums::updates_action::UpdatesAction;
use crate::tracker::structs::info_hash::InfoHash;

pub async fn api_service_key_get(request: HttpRequest, path: web::Path<String>, data: Data<Arc<ApiServiceData>>) -> HttpResponse
Expand Down Expand Up @@ -98,6 +99,10 @@ pub async fn api_service_key_post(request: HttpRequest, path: web::Path<(String,
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid key_hash {}", key)})); }
};

if data.torrent_tracker.config.database.clone().unwrap().persistent {
let _ = data.torrent_tracker.add_key_update(key_hash, timeout as i64, UpdatesAction::Add);
}

return match data.torrent_tracker.add_key(key_hash, timeout as i64) {
true => { HttpResponse::Ok().content_type(ContentType::json()).json(json!({"status": "ok"})) }
false => { HttpResponse::NotModified().content_type(ContentType::json()).json(json!({"status": format!("key_hash updated {}", key)})) }
Expand Down Expand Up @@ -134,6 +139,10 @@ pub async fn api_service_keys_post(request: HttpRequest, payload: web::Payload,
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid key_hash {}", key)})) }
};

if data.torrent_tracker.config.database.clone().unwrap().persistent {
let _ = data.torrent_tracker.add_key_update(key_hash, timeout as i64, UpdatesAction::Add);
}

match data.torrent_tracker.add_key(key_hash, timeout as i64) {
true => { keys_output.insert(key, json!({"status": "ok"})); }
false => { keys_output.insert(key, json!({"status": "key_hash updated"})); }
Expand Down Expand Up @@ -163,6 +172,10 @@ pub async fn api_service_key_delete(request: HttpRequest, path: web::Path<String
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid key {}", key)})); }
};

if data.torrent_tracker.config.database.clone().unwrap().persistent {
let _ = data.torrent_tracker.add_key_update(key_hash, 0i64, UpdatesAction::Remove);
}

return match data.torrent_tracker.remove_key(key_hash) {
true => { HttpResponse::Ok().content_type(ContentType::json()).json(json!({"status": "ok"})) }
false => { HttpResponse::NotModified().content_type(ContentType::json()).json(json!({"status": format!("unknown key_hash {}", key)})) }
Expand Down Expand Up @@ -194,14 +207,18 @@ pub async fn api_service_keys_delete(request: HttpRequest, payload: web::Payload
let mut keys_output = HashMap::new();
for key_item in keys {
if key_item.len() == 40 {
let key = match hex2bin(key_item.clone()) {
let key_hash = match hex2bin(key_item.clone()) {
Ok(key) => { InfoHash(key) }
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid key {}", key_item)})) }
};

match data.torrent_tracker.remove_key(key) {
true => { keys_output.insert(key, json!({"status": "ok"})); }
false => { keys_output.insert(key, json!({"status": "unknown key_hash"})); }
if data.torrent_tracker.config.database.clone().unwrap().persistent {
let _ = data.torrent_tracker.add_key_update(key_hash, 0i64, UpdatesAction::Remove);
}

match data.torrent_tracker.remove_key(key_hash) {
true => { keys_output.insert(key_hash, json!({"status": "ok"})); }
false => { keys_output.insert(key_hash, json!({"status": "unknown key_hash"})); }
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/api/api_torrents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::api::api::{api_parse_body, api_service_token, api_validation};
use crate::api::structs::api_service_data::ApiServiceData;
use crate::api::structs::query_token::QueryToken;
use crate::common::common::hex2bin;
use crate::tracker::enums::updates_action::UpdatesAction;
use crate::tracker::structs::info_hash::InfoHash;
use crate::tracker::structs::torrent_entry::TorrentEntry;

Expand Down Expand Up @@ -101,7 +102,7 @@ pub async fn api_service_torrent_post(request: HttpRequest, path: web::Path<(Str
};

if data.torrent_tracker.config.database.clone().unwrap().persistent {
let _ = data.torrent_tracker.add_torrent_update(info_hash, torrent_entry.clone());
let _ = data.torrent_tracker.add_torrent_update(info_hash, torrent_entry.clone(), UpdatesAction::Add);
}

return match data.torrent_tracker.add_torrent(info_hash, torrent_entry.clone()) {
Expand Down Expand Up @@ -148,7 +149,7 @@ pub async fn api_service_torrents_post(request: HttpRequest, payload: web::Paylo
};

if data.torrent_tracker.config.database.clone().unwrap().persistent {
let _ = data.torrent_tracker.add_torrent_update(info_hash, torrent_entry.clone());
let _ = data.torrent_tracker.add_torrent_update(info_hash, torrent_entry.clone(), UpdatesAction::Add);
}

match data.torrent_tracker.add_torrent(info_hash, torrent_entry.clone()) {
Expand Down Expand Up @@ -180,6 +181,10 @@ pub async fn api_service_torrent_delete(request: HttpRequest, path: web::Path<St
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid info_hash {}", info)})); }
};

if data.torrent_tracker.config.database.clone().unwrap().persistent {
let _ = data.torrent_tracker.add_torrent_update(info_hash, TorrentEntry::default(), UpdatesAction::Remove);
}

return match data.torrent_tracker.remove_torrent(info_hash) {
None => { HttpResponse::NotModified().content_type(ContentType::json()).json(json!({"status": format!("unknown info_hash {}", info)})) }
Some(_) => { HttpResponse::Ok().content_type(ContentType::json()).json(json!({"status": "ok"})) }
Expand Down Expand Up @@ -216,6 +221,10 @@ pub async fn api_service_torrents_delete(request: HttpRequest, payload: web::Pay
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid info_hash {}", info)})) }
};

if data.torrent_tracker.config.database.clone().unwrap().persistent {
let _ = data.torrent_tracker.add_torrent_update(info_hash, TorrentEntry::default(), UpdatesAction::Remove);
}

match data.torrent_tracker.remove_torrent(info_hash) {
None => { torrents_output.insert(info_hash, json!({"status": "unknown info_hash"})); }
Some(_) => { torrents_output.insert(info_hash, json!({"status": "ok"})); }
Expand Down
Loading

0 comments on commit 8f59500

Please sign in to comment.