Skip to content

Commit

Permalink
Merge pull request #44 from Power2All/v4.0.3
Browse files Browse the repository at this point in the history
Library update & Sentry interation v4.0.3
  • Loading branch information
Power2All authored Nov 15, 2024
2 parents dd78b72 + 17f90d2 commit cfb2664
Show file tree
Hide file tree
Showing 9 changed files with 1,290 additions and 426 deletions.
1,030 changes: 915 additions & 115 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "torrust-actix"
version = "4.0.2"
version = "4.0.3"
edition = "2021"
license = "AGPL-3.0"
authors = [
Expand Down Expand Up @@ -31,7 +31,7 @@ byteorder = "^1.5"
chrono = "^0.4"
clap = { version = "^4.5", features = ["derive"] }
clap_builder = "^4.5"
fern = { version = "^0.6", features = ["colored"] }
fern = { version = "^0.7", features = ["colored"] }
futures-util = "^0.3"
hex = "^0.4"
log = "^0.4"
Expand All @@ -42,13 +42,15 @@ rcgen = "^0.13"
regex = "^1.11"
rustls = { version = "^0.23", default-features = false, features = ["std", "ring"] }
rustls-pemfile = "^2.2"
sentry = "0.34.0"
sentry-actix = "0.34.0"
serde = { version = "^1.0", features = ["derive"] }
serde_json = { version = "^1.0", features = ["preserve_order"] }
serde_millis = "^0.1"
sha1 = "^0.10"
sqlx = { version = "^0.8", features = ["mysql", "postgres", "sqlite", "runtime-tokio-rustls"] }
thiserror = "^1.0"
tokio = { version = "^1.40", features = ["full"] }
thiserror = "^2.0"
tokio = { version = "^1.41", features = ["full"] }
tokio-shutdown = "^0.1"
toml = "^0.8"
utoipa = { version = "^5", features = ["actix_extras"] }
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ Swagger UI is introduced, and when enabled in the configuration, is accessible t

### ChangeLog

#### v4.0.3
* Fixing announce and scrape paths, since it is the wrong way.
* Fixing various smaller bugs that isn't app-breaking, but should be handled better.
* Preparing work for version v4.1.0, which will introduce LUA support for middleware.

#### v4.0.2
* Added option that the system will remove data from database.
* Added updates variables for the white/black list and keys tables.
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.2
RUN cd /tmp/torrust-actix && git checkout tags/v4.0.3
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
33 changes: 25 additions & 8 deletions src/api/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,38 @@ pub async fn api_service(
exit(1);
}

let key_file = &mut BufReader::new(File::open(api_server_object.ssl_key.clone().unwrap()).unwrap());
let certs_file = &mut BufReader::new(File::open(api_server_object.ssl_cert.clone().unwrap()).unwrap());
let key_file = &mut BufReader::new(match File::open(match api_server_object.ssl_key.clone() {
None => { panic!("[APIS] SSL key not set!"); }
Some(data) => { data }
}) {
Ok(data) => { data }
Err(data) => { panic!("[APIS] SSL key unreadable: {}", data); }
});
let certs_file = &mut BufReader::new(match File::open(match api_server_object.ssl_cert.clone() {
None => { panic!("[APIS] SSL cert not set!"); }
Some(data) => { data }
}) {
Ok(data) => { data }
Err(data) => { panic!("[APIS] SSL cert unreadable: {}", data); }
});

let tls_certs = rustls_pemfile::certs(certs_file).collect::<Result<Vec<_>, _>>().unwrap();
let tls_certs = match rustls_pemfile::certs(certs_file).collect::<Result<Vec<_>, _>>() {
Ok(data) => { data }
Err(data) => { panic!("[APIS] SSL cert couldn't be extracted: {}", data); }
};
let tls_key = match rustls_pemfile::pkcs8_private_keys(key_file).next().unwrap() {
Err(_) => { exit(1); }
Ok(data) => { data }
Err(data) => { panic!("[APIS] SSL key couldn't be extracted: {}", data); }
};

let tls_config = rustls::ServerConfig::builder()
.with_no_client_auth()
.with_single_cert(tls_certs, rustls::pki_types::PrivateKeyDer::Pkcs8(tls_key))
.unwrap();
let tls_config = match rustls::ServerConfig::builder().with_no_client_auth().with_single_cert(tls_certs, rustls::pki_types::PrivateKeyDer::Pkcs8(tls_key)) {
Ok(data) => { data }
Err(data) => { panic!("[APIS] SSL config couldn't be created: {}", data); }
};

let server = HttpServer::new(move || {
App::new()
.wrap(sentry_actix::Sentry::new())
.wrap(api_service_cors())
.configure(api_service_routes(Arc::new(ApiServiceData {
torrent_tracker: data.clone(),
Expand All @@ -177,6 +193,7 @@ pub async fn api_service(
info!("[API] Starting server listener on {}", addr);
let server = HttpServer::new(move || {
App::new()
.wrap(sentry_actix::Sentry::new())
.wrap(api_service_cors())
.configure(api_service_routes(Arc::new(ApiServiceData {
torrent_tracker: data.clone(),
Expand Down
2 changes: 2 additions & 0 deletions src/config/impls/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ impl Configuration {
peers_cleanup_interval: Some(900),
total_downloads: 0,
swagger: Some(false),
sentry: Some(false),
sentry_url: None
}),
database: Some(DatabaseConfig {
engine: Some(DatabaseDrivers::sqlite3),
Expand Down
4 changes: 3 additions & 1 deletion src/config/structs/tracker_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ pub struct TrackerConfig {
pub peers_timeout: Option<u64>,
pub peers_cleanup_interval: Option<u64>,
pub total_downloads: u64,
pub swagger: Option<bool>
pub swagger: Option<bool>,
pub sentry: Option<bool>,
pub sentry_url: Option<String>
}
39 changes: 28 additions & 11 deletions src/http/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ pub fn http_service_routes(data: Arc<HttpServiceData>) -> Box<dyn Fn(&mut Servic
cfg.service(web::resource("/announce")
.route(web::get().to(http_service_announce))
);
cfg.service(web::resource("/announce/{key}")
cfg.service(web::resource("/{key/announce")
.route(web::get().to(http_service_announce_key))
);
cfg.service(web::resource("/announce/{key}/{userkey}")
cfg.service(web::resource("/{key}/{userkey}announce")
.route(web::get().to(http_service_announce_userkey))
);
cfg.service(web::resource("/scrape")
.route(web::get().to(http_service_scrape))
);
cfg.service(web::resource("/scrape/{key}")
cfg.service(web::resource("/{key}/scrape")
.route(web::get().to(http_service_scrape_key))
);
cfg.default_service(web::route().to(http_service_not_found));
Expand All @@ -76,22 +76,38 @@ pub async fn http_service(
exit(1);
}

let key_file = &mut BufReader::new(File::open(http_server_object.ssl_key.clone().unwrap()).unwrap());
let certs_file = &mut BufReader::new(File::open(http_server_object.ssl_cert.clone().unwrap()).unwrap());
let key_file = &mut BufReader::new(match File::open(match http_server_object.ssl_key.clone() {
None => { panic!("[HTTPS] SSL key not set!"); }
Some(data) => { data }
}) {
Ok(data) => { data }
Err(data) => { panic!("[HTTPS] SSL key unreadable: {}", data); }
});
let certs_file = &mut BufReader::new(match File::open(match http_server_object.ssl_cert.clone() {
None => { panic!("[HTTPS] SSL cert not set!"); }
Some(data) => { data }
}) {
Ok(data) => { data }
Err(data) => { panic!("[HTTPS] SSL cert unreadable: {}", data); }
});

let tls_certs = rustls_pemfile::certs(certs_file).collect::<Result<Vec<_>, _>>().unwrap();
let tls_certs = match rustls_pemfile::certs(certs_file).collect::<Result<Vec<_>, _>>() {
Ok(data) => { data }
Err(data) => { panic!("[HTTPS] SSL cert couldn't be extracted: {}", data); }
};
let tls_key = match rustls_pemfile::pkcs8_private_keys(key_file).next().unwrap() {
Err(_) => { exit(1); }
Ok(data) => { data }
Err(data) => { panic!("[HTTPS] SSL key couldn't be extracted: {}", data); }
};

let tls_config = rustls::ServerConfig::builder()
.with_no_client_auth()
.with_single_cert(tls_certs, rustls::pki_types::PrivateKeyDer::Pkcs8(tls_key))
.unwrap();
let tls_config = match rustls::ServerConfig::builder().with_no_client_auth().with_single_cert(tls_certs, rustls::pki_types::PrivateKeyDer::Pkcs8(tls_key)) {
Ok(data) => { data }
Err(data) => { panic!("[HTTPS] SSL config couldn't be created: {}", data); }
};

let server = HttpServer::new(move || {
App::new()
.wrap(sentry_actix::Sentry::new())
.wrap(http_service_cors())
.configure(http_service_routes(Arc::new(HttpServiceData {
torrent_tracker: data.clone(),
Expand All @@ -113,6 +129,7 @@ pub async fn http_service(
info!("[HTTP] Starting server listener on {}", addr);
let server = HttpServer::new(move || {
App::new()
.wrap(sentry_actix::Sentry::new())
.wrap(http_service_cors())
.configure(http_service_routes(Arc::new(HttpServiceData {
torrent_tracker: data.clone(),
Expand Down
Loading

0 comments on commit cfb2664

Please sign in to comment.