Skip to content

Commit 8f59500

Browse files
committed
Added enhancement and bug fixes, need one more check before releasing as v4.0.2
1 parent 579d4fe commit 8f59500

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2718
-1741
lines changed

Cargo.lock

+27-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "torrust-actix"
3-
version = "4.0.1"
3+
version = "4.0.2"
44
edition = "2021"
55
license = "AGPL-3.0"
66
authors = [

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ Swagger UI is introduced, and when enabled in the configuration, is accessible t
5656

5757
### ChangeLog
5858

59+
#### v4.0.2
60+
* Added option that the system will remove data from database.
61+
* Added updates variables for the white/black list and keys tables.
62+
* Renaming the "database" naming which should be "tables".
63+
* A lot of fixes and bugs I stumbled upon.
64+
5965
#### v4.0.0
6066
* Completely rebuilt of the tracker code, for readability.
6167
* Moved to Actix v4, thus versioning this software to v4.0.0 as well.

docker/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM rust:alpine
22

33
RUN apk add git musl-dev curl
44
RUN git clone https://github.com/Power2All/torrust-actix.git /tmp/torrust-actix
5-
RUN cd /tmp/torrust-actix && git checkout tags/v4.0.1
5+
RUN cd /tmp/torrust-actix && git checkout tags/v4.0.2
66
WORKDIR /tmp/torrust-actix
77
RUN cd /tmp/torrust-actix
88
RUN cargo build --release && rm -Rf target/release/.fingerprint target/release/build target/release/deps target/release/examples target/release/incremental

src/api/api_blacklists.rs

+17
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::api::api::{api_parse_body, api_service_token, api_validation};
88
use crate::api::structs::api_service_data::ApiServiceData;
99
use crate::api::structs::query_token::QueryToken;
1010
use crate::common::common::hex2bin;
11+
use crate::tracker::enums::updates_action::UpdatesAction;
1112
use crate::tracker::structs::info_hash::InfoHash;
1213

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

92+
if data.torrent_tracker.config.database.clone().unwrap().persistent {
93+
let _ = data.torrent_tracker.add_blacklist_update(info_hash, UpdatesAction::Add);
94+
}
95+
9196
return match data.torrent_tracker.add_blacklist(info_hash) {
9297
true => { HttpResponse::Ok().content_type(ContentType::json()).json(json!({"status": "ok"})) }
9398
false => { HttpResponse::NotModified().content_type(ContentType::json()).json(json!({"status": format!("info_hash updated {}", info)})) }
@@ -124,6 +129,10 @@ pub async fn api_service_blacklists_post(request: HttpRequest, payload: web::Pay
124129
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid info_hash {}", info)})) }
125130
};
126131

132+
if data.torrent_tracker.config.database.clone().unwrap().persistent {
133+
let _ = data.torrent_tracker.add_blacklist_update(info_hash, UpdatesAction::Add);
134+
}
135+
127136
match data.torrent_tracker.add_blacklist(info_hash) {
128137
true => { blacklists_output.insert(info_hash, json!({"status": "ok"})); }
129138
false => { blacklists_output.insert(info_hash, json!({"status": "info_hash updated"})); }
@@ -153,6 +162,10 @@ pub async fn api_service_blacklist_delete(request: HttpRequest, path: web::Path<
153162
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid info_hash {}", info)})); }
154163
};
155164

165+
if data.torrent_tracker.config.database.clone().unwrap().persistent {
166+
let _ = data.torrent_tracker.add_blacklist_update(info_hash, UpdatesAction::Remove);
167+
}
168+
156169
return match data.torrent_tracker.remove_blacklist(info_hash) {
157170
true => { HttpResponse::Ok().content_type(ContentType::json()).json(json!({"status": "ok"})) }
158171
false => { HttpResponse::NotModified().content_type(ContentType::json()).json(json!({"status": format!("unknown info_hash {}", info)})) }
@@ -189,6 +202,10 @@ pub async fn api_service_blacklists_delete(request: HttpRequest, payload: web::P
189202
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid info_hash {}", info)})) }
190203
};
191204

205+
if data.torrent_tracker.config.database.clone().unwrap().persistent {
206+
let _ = data.torrent_tracker.add_blacklist_update(info_hash, UpdatesAction::Remove);
207+
}
208+
192209
match data.torrent_tracker.remove_blacklist(info_hash) {
193210
true => { blacklists_output.insert(info_hash, json!({"status": "ok"})); }
194211
false => { blacklists_output.insert(info_hash, json!({"status": "unknown info_hash"})); }

src/api/api_keys.rs

+21-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::api::api::{api_parse_body, api_service_token, api_validation};
88
use crate::api::structs::api_service_data::ApiServiceData;
99
use crate::api::structs::query_token::QueryToken;
1010
use crate::common::common::hex2bin;
11+
use crate::tracker::enums::updates_action::UpdatesAction;
1112
use crate::tracker::structs::info_hash::InfoHash;
1213

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

102+
if data.torrent_tracker.config.database.clone().unwrap().persistent {
103+
let _ = data.torrent_tracker.add_key_update(key_hash, timeout as i64, UpdatesAction::Add);
104+
}
105+
101106
return match data.torrent_tracker.add_key(key_hash, timeout as i64) {
102107
true => { HttpResponse::Ok().content_type(ContentType::json()).json(json!({"status": "ok"})) }
103108
false => { HttpResponse::NotModified().content_type(ContentType::json()).json(json!({"status": format!("key_hash updated {}", key)})) }
@@ -134,6 +139,10 @@ pub async fn api_service_keys_post(request: HttpRequest, payload: web::Payload,
134139
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid key_hash {}", key)})) }
135140
};
136141

142+
if data.torrent_tracker.config.database.clone().unwrap().persistent {
143+
let _ = data.torrent_tracker.add_key_update(key_hash, timeout as i64, UpdatesAction::Add);
144+
}
145+
137146
match data.torrent_tracker.add_key(key_hash, timeout as i64) {
138147
true => { keys_output.insert(key, json!({"status": "ok"})); }
139148
false => { keys_output.insert(key, json!({"status": "key_hash updated"})); }
@@ -163,6 +172,10 @@ pub async fn api_service_key_delete(request: HttpRequest, path: web::Path<String
163172
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid key {}", key)})); }
164173
};
165174

175+
if data.torrent_tracker.config.database.clone().unwrap().persistent {
176+
let _ = data.torrent_tracker.add_key_update(key_hash, 0i64, UpdatesAction::Remove);
177+
}
178+
166179
return match data.torrent_tracker.remove_key(key_hash) {
167180
true => { HttpResponse::Ok().content_type(ContentType::json()).json(json!({"status": "ok"})) }
168181
false => { HttpResponse::NotModified().content_type(ContentType::json()).json(json!({"status": format!("unknown key_hash {}", key)})) }
@@ -194,14 +207,18 @@ pub async fn api_service_keys_delete(request: HttpRequest, payload: web::Payload
194207
let mut keys_output = HashMap::new();
195208
for key_item in keys {
196209
if key_item.len() == 40 {
197-
let key = match hex2bin(key_item.clone()) {
210+
let key_hash = match hex2bin(key_item.clone()) {
198211
Ok(key) => { InfoHash(key) }
199212
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid key {}", key_item)})) }
200213
};
201214

202-
match data.torrent_tracker.remove_key(key) {
203-
true => { keys_output.insert(key, json!({"status": "ok"})); }
204-
false => { keys_output.insert(key, json!({"status": "unknown key_hash"})); }
215+
if data.torrent_tracker.config.database.clone().unwrap().persistent {
216+
let _ = data.torrent_tracker.add_key_update(key_hash, 0i64, UpdatesAction::Remove);
217+
}
218+
219+
match data.torrent_tracker.remove_key(key_hash) {
220+
true => { keys_output.insert(key_hash, json!({"status": "ok"})); }
221+
false => { keys_output.insert(key_hash, json!({"status": "unknown key_hash"})); }
205222
}
206223
}
207224
}

src/api/api_torrents.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::api::api::{api_parse_body, api_service_token, api_validation};
99
use crate::api::structs::api_service_data::ApiServiceData;
1010
use crate::api::structs::query_token::QueryToken;
1111
use crate::common::common::hex2bin;
12+
use crate::tracker::enums::updates_action::UpdatesAction;
1213
use crate::tracker::structs::info_hash::InfoHash;
1314
use crate::tracker::structs::torrent_entry::TorrentEntry;
1415

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

103104
if data.torrent_tracker.config.database.clone().unwrap().persistent {
104-
let _ = data.torrent_tracker.add_torrent_update(info_hash, torrent_entry.clone());
105+
let _ = data.torrent_tracker.add_torrent_update(info_hash, torrent_entry.clone(), UpdatesAction::Add);
105106
}
106107

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

150151
if data.torrent_tracker.config.database.clone().unwrap().persistent {
151-
let _ = data.torrent_tracker.add_torrent_update(info_hash, torrent_entry.clone());
152+
let _ = data.torrent_tracker.add_torrent_update(info_hash, torrent_entry.clone(), UpdatesAction::Add);
152153
}
153154

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

184+
if data.torrent_tracker.config.database.clone().unwrap().persistent {
185+
let _ = data.torrent_tracker.add_torrent_update(info_hash, TorrentEntry::default(), UpdatesAction::Remove);
186+
}
187+
183188
return match data.torrent_tracker.remove_torrent(info_hash) {
184189
None => { HttpResponse::NotModified().content_type(ContentType::json()).json(json!({"status": format!("unknown info_hash {}", info)})) }
185190
Some(_) => { HttpResponse::Ok().content_type(ContentType::json()).json(json!({"status": "ok"})) }
@@ -216,6 +221,10 @@ pub async fn api_service_torrents_delete(request: HttpRequest, payload: web::Pay
216221
Err(_) => { return HttpResponse::BadRequest().content_type(ContentType::json()).json(json!({"status": format!("invalid info_hash {}", info)})) }
217222
};
218223

224+
if data.torrent_tracker.config.database.clone().unwrap().persistent {
225+
let _ = data.torrent_tracker.add_torrent_update(info_hash, TorrentEntry::default(), UpdatesAction::Remove);
226+
}
227+
219228
match data.torrent_tracker.remove_torrent(info_hash) {
220229
None => { torrents_output.insert(info_hash, json!({"status": "unknown info_hash"})); }
221230
Some(_) => { torrents_output.insert(info_hash, json!({"status": "ok"})); }

0 commit comments

Comments
 (0)