Skip to content

Commit

Permalink
Merge #1292: Refactor packages: extract tracker-api-core package
Browse files Browse the repository at this point in the history
97d2629 refactor: [#1280] extract tracker-api-core package (Jose Celano)

Pull request description:

  Refactor packages:  extract `tracker-api-core` package

ACKs for top commit:
  josecelano:
    ACK 97d2629

Tree-SHA512: dc839f1a0adf78f33a213d17f40ad6af097558d23aef7dcf5260fa689c3cf7572b05f137992e220d53ce816ec017e80def9035b5ab7a908164df54682f4763b2
  • Loading branch information
josecelano committed Feb 18, 2025
2 parents 236c3bf + 97d2629 commit 991d680
Show file tree
Hide file tree
Showing 16 changed files with 724 additions and 19 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
cargo publish -p bittorrent-udp-tracker-core
cargo publish -p torrust-tracker
cargo publish -p torrust-tracker-api-client
cargo publish -p torrust-tracker-api-core
cargo publish -p torrust-tracker-client
cargo publish -p torrust-tracker-clock
cargo publish -p torrust-tracker-configuration
Expand Down
16 changes: 15 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ serde_repr = "0"
serde_with = { version = "3", features = ["json"] }
thiserror = "2"
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
torrust-tracker-api-core = { version = "3.0.0-develop", path = "packages/tracker-api-core" }
torrust-tracker-clock = { version = "3.0.0-develop", path = "packages/clock" }
torrust-tracker-configuration = { version = "3.0.0-develop", path = "packages/configuration" }
torrust-tracker-located-error = { version = "3.0.0-develop", path = "packages/located-error" }
Expand Down
25 changes: 25 additions & 0 deletions packages/tracker-api-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
authors.workspace = true
description = "A library with the core functionality needed to implement a BitTorrent UDP tracker."
documentation.workspace = true
edition.workspace = true
homepage.workspace = true
keywords = ["api", "bittorrent", "core", "library", "tracker"]
license.workspace = true
name = "torrust-tracker-api-core"
publish.workspace = true
readme = "README.md"
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[dependencies]
bittorrent-http-tracker-core = { version = "3.0.0-develop", path = "../http-tracker-core" }
bittorrent-tracker-core = { version = "3.0.0-develop", path = "../tracker-core" }
bittorrent-udp-tracker-core = { version = "3.0.0-develop", path = "../udp-tracker-core" }
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
torrust-tracker-configuration = { version = "3.0.0-develop", path = "../configuration" }
torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" }

[dev-dependencies]
torrust-tracker-test-helpers = { version = "3.0.0-develop", path = "../test-helpers" }
661 changes: 661 additions & 0 deletions packages/tracker-api-core/LICENSE

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions packages/tracker-api-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# BitTorrent UDP Tracker Core library

A library with the core functionality needed to implement the Torrust Tracker API

## Documentation

[Crate documentation](https://docs.rs/torrust-tracker-api-core).

## License

The project is licensed under the terms of the [GNU AFFERO GENERAL PUBLIC LICENSE](./LICENSE).
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ use std::sync::Arc;
use bittorrent_tracker_core::torrent::repository::in_memory::InMemoryTorrentRepository;
use bittorrent_udp_tracker_core::services::banning::BanService;
use bittorrent_udp_tracker_core::{self, statistics};
use packages::tracker_api_core::statistics::metrics::Metrics;
use tokio::sync::RwLock;
use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics;

use crate::packages::{self};
use crate::statistics::metrics::Metrics;

/// All the metrics collected by the tracker.
#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -84,8 +83,8 @@ mod tests {
use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics;
use torrust_tracker_test_helpers::configuration;

use crate::packages::tracker_api_core::statistics::metrics::Metrics;
use crate::packages::tracker_api_core::statistics::services::{get_metrics, TrackerMetrics};
use crate::statistics::metrics::Metrics;
use crate::statistics::services::{get_metrics, TrackerMetrics};

pub fn tracker_configuration() -> Configuration {
configuration::ephemeral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ lazy_static! {
/// The random static seed.
pub static ref RANDOM_SEED: Seed = {
let mut rng = ThreadRng::default();
rng.gen::<Seed>()
rng.random::<Seed>()
};

/// The random cipher from the seed.
pub static ref RANDOM_CIPHER_BLOWFISH: CipherBlowfish = {
let mut rng = ThreadRng::default();
let seed: Seed = rng.gen();
let seed: Seed = rng.random();
CipherBlowfish::new_from_slice(&seed).expect("it could not generate key")
};

Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,6 @@ pub mod app;
pub mod bootstrap;
pub mod console;
pub mod container;
pub mod packages;
pub mod servers;
pub mod shared;

Expand Down
4 changes: 0 additions & 4 deletions src/packages/mod.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/servers/apis/v1/context/stats/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use bittorrent_tracker_core::torrent::repository::in_memory::InMemoryTorrentRepo
use bittorrent_udp_tracker_core::services::banning::BanService;
use serde::Deserialize;
use tokio::sync::RwLock;
use torrust_tracker_api_core::statistics::services::get_metrics;

use super::responses::{metrics_response, stats_response};
use crate::packages::tracker_api_core::statistics::services::get_metrics;

#[derive(Deserialize, Debug, Default)]
#[serde(rename_all = "lowercase")]
Expand Down
8 changes: 3 additions & 5 deletions src/servers/apis/v1/context/stats/resources.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! API resources for the [`stats`](crate::servers::apis::v1::context::stats)
//! API context.
use serde::{Deserialize, Serialize};

use crate::packages::tracker_api_core::statistics::services::TrackerMetrics;
use torrust_tracker_api_core::statistics::services::TrackerMetrics;

/// It contains all the statistics generated by the tracker.
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -118,12 +117,11 @@ impl From<TrackerMetrics> for Stats {

#[cfg(test)]
mod tests {
use packages::tracker_api_core::statistics::metrics::Metrics;
use torrust_tracker_api_core::statistics::metrics::Metrics;
use torrust_tracker_api_core::statistics::services::TrackerMetrics;
use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics;

use super::Stats;
use crate::packages::tracker_api_core::statistics::services::TrackerMetrics;
use crate::packages::{self};

#[test]
fn stats_resource_should_be_converted_from_tracker_metrics() {
Expand Down
2 changes: 1 addition & 1 deletion src/servers/apis/v1/context/stats/responses.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! API responses for the [`stats`](crate::servers::apis::v1::context::stats)
//! API context.
use axum::response::{IntoResponse, Json, Response};
use torrust_tracker_api_core::statistics::services::TrackerMetrics;

use super::resources::Stats;
use crate::packages::tracker_api_core::statistics::services::TrackerMetrics;

/// `200` response that contains the [`Stats`] resource as json.
#[must_use]
Expand Down

0 comments on commit 991d680

Please sign in to comment.