From 55149bcf97ad261e0ef36334520ce4cc73082ecc Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Thu, 29 May 2025 10:16:12 +0100 Subject: [PATCH 1/9] refactor: [#1519] rename dir torrent-repository --- Cargo.toml | 2 +- packages/axum-http-tracker-server/Cargo.toml | 2 +- packages/axum-rest-tracker-api-server/Cargo.toml | 2 +- packages/http-tracker-core/Cargo.toml | 2 +- packages/rest-tracker-api-core/Cargo.toml | 2 +- .../.gitignore | 0 .../Cargo.toml | 0 .../README.md | 0 .../src/container.rs | 0 .../src/event.rs | 0 .../src/lib.rs | 0 .../src/statistics/activity_metrics_updater.rs | 0 .../src/statistics/event/handler.rs | 0 .../src/statistics/event/listener.rs | 0 .../src/statistics/event/mod.rs | 0 .../src/statistics/metrics.rs | 0 .../src/statistics/mod.rs | 0 .../src/statistics/repository.rs | 0 .../src/swarm.rs | 0 .../src/swarms.rs | 0 packages/torrent-repository-benchmarking/README.md | 2 +- packages/tracker-core/Cargo.toml | 2 +- packages/udp-tracker-core/Cargo.toml | 2 +- packages/udp-tracker-server/Cargo.toml | 2 +- 24 files changed, 9 insertions(+), 9 deletions(-) rename packages/{torrent-repository => swarm-coordination-registry}/.gitignore (100%) rename packages/{torrent-repository => swarm-coordination-registry}/Cargo.toml (100%) rename packages/{torrent-repository => swarm-coordination-registry}/README.md (100%) rename packages/{torrent-repository => swarm-coordination-registry}/src/container.rs (100%) rename packages/{torrent-repository => swarm-coordination-registry}/src/event.rs (100%) rename packages/{torrent-repository => swarm-coordination-registry}/src/lib.rs (100%) rename packages/{torrent-repository => swarm-coordination-registry}/src/statistics/activity_metrics_updater.rs (100%) rename packages/{torrent-repository => swarm-coordination-registry}/src/statistics/event/handler.rs (100%) rename packages/{torrent-repository => swarm-coordination-registry}/src/statistics/event/listener.rs (100%) rename packages/{torrent-repository => swarm-coordination-registry}/src/statistics/event/mod.rs (100%) rename packages/{torrent-repository => swarm-coordination-registry}/src/statistics/metrics.rs (100%) rename packages/{torrent-repository => swarm-coordination-registry}/src/statistics/mod.rs (100%) rename packages/{torrent-repository => swarm-coordination-registry}/src/statistics/repository.rs (100%) rename packages/{torrent-repository => swarm-coordination-registry}/src/swarm.rs (100%) rename packages/{torrent-repository => swarm-coordination-registry}/src/swarms.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 219701d03..3e6e3e073 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,7 @@ torrust-rest-tracker-api-core = { version = "3.0.0-develop", path = "packages/re torrust-server-lib = { version = "3.0.0-develop", path = "packages/server-lib" } torrust-tracker-clock = { version = "3.0.0-develop", path = "packages/clock" } torrust-tracker-configuration = { version = "3.0.0-develop", path = "packages/configuration" } -torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "packages/torrent-repository" } +torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "packages/swarm-coordination-registry" } torrust-udp-tracker-server = { version = "3.0.0-develop", path = "packages/udp-tracker-server" } tracing = "0" tracing-subscriber = { version = "0", features = ["json"] } diff --git a/packages/axum-http-tracker-server/Cargo.toml b/packages/axum-http-tracker-server/Cargo.toml index 81831a614..51283ee01 100644 --- a/packages/axum-http-tracker-server/Cargo.toml +++ b/packages/axum-http-tracker-server/Cargo.toml @@ -33,7 +33,7 @@ torrust-server-lib = { version = "3.0.0-develop", path = "../server-lib" } torrust-tracker-clock = { version = "3.0.0-develop", path = "../clock" } torrust-tracker-configuration = { version = "3.0.0-develop", path = "../configuration" } torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" } -torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../torrent-repository" } +torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } tower = { version = "0", features = ["timeout"] } tower-http = { version = "0", features = ["compression-full", "cors", "propagate-header", "request-id", "trace"] } tracing = "0" diff --git a/packages/axum-rest-tracker-api-server/Cargo.toml b/packages/axum-rest-tracker-api-server/Cargo.toml index 296f77d61..558dbf6c1 100644 --- a/packages/axum-rest-tracker-api-server/Cargo.toml +++ b/packages/axum-rest-tracker-api-server/Cargo.toml @@ -39,7 +39,7 @@ torrust-tracker-clock = { version = "3.0.0-develop", path = "../clock" } torrust-tracker-configuration = { version = "3.0.0-develop", path = "../configuration" } torrust-tracker-metrics = { version = "3.0.0-develop", path = "../metrics" } torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" } -torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../torrent-repository" } +torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } torrust-udp-tracker-server = { version = "3.0.0-develop", path = "../udp-tracker-server" } tower = { version = "0", features = ["timeout"] } tower-http = { version = "0", features = ["compression-full", "cors", "propagate-header", "request-id", "trace"] } diff --git a/packages/http-tracker-core/Cargo.toml b/packages/http-tracker-core/Cargo.toml index 37b540e39..008aa92c6 100644 --- a/packages/http-tracker-core/Cargo.toml +++ b/packages/http-tracker-core/Cargo.toml @@ -28,7 +28,7 @@ torrust-tracker-configuration = { version = "3.0.0-develop", path = "../configur torrust-tracker-events = { version = "3.0.0-develop", path = "../events" } torrust-tracker-metrics = { version = "3.0.0-develop", path = "../metrics" } torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" } -torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../torrent-repository" } +torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } tracing = "0" [dev-dependencies] diff --git a/packages/rest-tracker-api-core/Cargo.toml b/packages/rest-tracker-api-core/Cargo.toml index 8cfe601b2..9a086ad19 100644 --- a/packages/rest-tracker-api-core/Cargo.toml +++ b/packages/rest-tracker-api-core/Cargo.toml @@ -21,7 +21,7 @@ tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal torrust-tracker-configuration = { version = "3.0.0-develop", path = "../configuration" } torrust-tracker-metrics = { version = "3.0.0-develop", path = "../metrics" } torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" } -torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../torrent-repository" } +torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } torrust-udp-tracker-server = { version = "3.0.0-develop", path = "../udp-tracker-server" } [dev-dependencies] diff --git a/packages/torrent-repository/.gitignore b/packages/swarm-coordination-registry/.gitignore similarity index 100% rename from packages/torrent-repository/.gitignore rename to packages/swarm-coordination-registry/.gitignore diff --git a/packages/torrent-repository/Cargo.toml b/packages/swarm-coordination-registry/Cargo.toml similarity index 100% rename from packages/torrent-repository/Cargo.toml rename to packages/swarm-coordination-registry/Cargo.toml diff --git a/packages/torrent-repository/README.md b/packages/swarm-coordination-registry/README.md similarity index 100% rename from packages/torrent-repository/README.md rename to packages/swarm-coordination-registry/README.md diff --git a/packages/torrent-repository/src/container.rs b/packages/swarm-coordination-registry/src/container.rs similarity index 100% rename from packages/torrent-repository/src/container.rs rename to packages/swarm-coordination-registry/src/container.rs diff --git a/packages/torrent-repository/src/event.rs b/packages/swarm-coordination-registry/src/event.rs similarity index 100% rename from packages/torrent-repository/src/event.rs rename to packages/swarm-coordination-registry/src/event.rs diff --git a/packages/torrent-repository/src/lib.rs b/packages/swarm-coordination-registry/src/lib.rs similarity index 100% rename from packages/torrent-repository/src/lib.rs rename to packages/swarm-coordination-registry/src/lib.rs diff --git a/packages/torrent-repository/src/statistics/activity_metrics_updater.rs b/packages/swarm-coordination-registry/src/statistics/activity_metrics_updater.rs similarity index 100% rename from packages/torrent-repository/src/statistics/activity_metrics_updater.rs rename to packages/swarm-coordination-registry/src/statistics/activity_metrics_updater.rs diff --git a/packages/torrent-repository/src/statistics/event/handler.rs b/packages/swarm-coordination-registry/src/statistics/event/handler.rs similarity index 100% rename from packages/torrent-repository/src/statistics/event/handler.rs rename to packages/swarm-coordination-registry/src/statistics/event/handler.rs diff --git a/packages/torrent-repository/src/statistics/event/listener.rs b/packages/swarm-coordination-registry/src/statistics/event/listener.rs similarity index 100% rename from packages/torrent-repository/src/statistics/event/listener.rs rename to packages/swarm-coordination-registry/src/statistics/event/listener.rs diff --git a/packages/torrent-repository/src/statistics/event/mod.rs b/packages/swarm-coordination-registry/src/statistics/event/mod.rs similarity index 100% rename from packages/torrent-repository/src/statistics/event/mod.rs rename to packages/swarm-coordination-registry/src/statistics/event/mod.rs diff --git a/packages/torrent-repository/src/statistics/metrics.rs b/packages/swarm-coordination-registry/src/statistics/metrics.rs similarity index 100% rename from packages/torrent-repository/src/statistics/metrics.rs rename to packages/swarm-coordination-registry/src/statistics/metrics.rs diff --git a/packages/torrent-repository/src/statistics/mod.rs b/packages/swarm-coordination-registry/src/statistics/mod.rs similarity index 100% rename from packages/torrent-repository/src/statistics/mod.rs rename to packages/swarm-coordination-registry/src/statistics/mod.rs diff --git a/packages/torrent-repository/src/statistics/repository.rs b/packages/swarm-coordination-registry/src/statistics/repository.rs similarity index 100% rename from packages/torrent-repository/src/statistics/repository.rs rename to packages/swarm-coordination-registry/src/statistics/repository.rs diff --git a/packages/torrent-repository/src/swarm.rs b/packages/swarm-coordination-registry/src/swarm.rs similarity index 100% rename from packages/torrent-repository/src/swarm.rs rename to packages/swarm-coordination-registry/src/swarm.rs diff --git a/packages/torrent-repository/src/swarms.rs b/packages/swarm-coordination-registry/src/swarms.rs similarity index 100% rename from packages/torrent-repository/src/swarms.rs rename to packages/swarm-coordination-registry/src/swarms.rs diff --git a/packages/torrent-repository-benchmarking/README.md b/packages/torrent-repository-benchmarking/README.md index f248ca0da..a0556a58f 100644 --- a/packages/torrent-repository-benchmarking/README.md +++ b/packages/torrent-repository-benchmarking/README.md @@ -1,4 +1,4 @@ -# Torrust Tracker Torrent Repository Benchmarking +# Torrust Tracker Swarm Coordination Registry Benchmarking A library to runt benchmarking for different implementations of a repository of torrents files and their peers. Torrent repositories are used by the [Torrust Tracker](https://github.com/torrust/torrust-tracker). diff --git a/packages/tracker-core/Cargo.toml b/packages/tracker-core/Cargo.toml index a2d08dfa0..8c9bf7769 100644 --- a/packages/tracker-core/Cargo.toml +++ b/packages/tracker-core/Cargo.toml @@ -33,7 +33,7 @@ torrust-tracker-events = { version = "3.0.0-develop", path = "../events" } torrust-tracker-located-error = { version = "3.0.0-develop", path = "../located-error" } torrust-tracker-metrics = { version = "3.0.0-develop", path = "../metrics" } torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" } -torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../torrent-repository" } +torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } tracing = "0" [dev-dependencies] diff --git a/packages/udp-tracker-core/Cargo.toml b/packages/udp-tracker-core/Cargo.toml index 9a27ec826..2933a7e70 100644 --- a/packages/udp-tracker-core/Cargo.toml +++ b/packages/udp-tracker-core/Cargo.toml @@ -33,7 +33,7 @@ torrust-tracker-configuration = { version = "3.0.0-develop", path = "../configur torrust-tracker-events = { version = "3.0.0-develop", path = "../events" } torrust-tracker-metrics = { version = "3.0.0-develop", path = "../metrics" } torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" } -torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../torrent-repository" } +torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } tracing = "0" zerocopy = "0.7" diff --git a/packages/udp-tracker-server/Cargo.toml b/packages/udp-tracker-server/Cargo.toml index a0c129acb..396dc0805 100644 --- a/packages/udp-tracker-server/Cargo.toml +++ b/packages/udp-tracker-server/Cargo.toml @@ -33,7 +33,7 @@ torrust-tracker-events = { version = "3.0.0-develop", path = "../events" } torrust-tracker-located-error = { version = "3.0.0-develop", path = "../located-error" } torrust-tracker-metrics = { version = "3.0.0-develop", path = "../metrics" } torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" } -torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../torrent-repository" } +torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } tracing = "0" url = { version = "2", features = ["serde"] } uuid = { version = "1", features = ["v4"] } From 2b7a25163a6a0d21aa0defe9e2999be1c5105ae0 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Thu, 29 May 2025 10:42:57 +0100 Subject: [PATCH 2/9] refactor: [#1519] rename crate torrust-tracker-torrent-repository to torrust-tracker-swarm-coordination-registry --- .github/workflows/deployment.yaml | 2 +- Cargo.lock | 40 +++++++++---------- Cargo.toml | 2 +- packages/axum-http-tracker-server/Cargo.toml | 2 +- .../src/environment.rs | 2 +- .../axum-http-tracker-server/src/server.rs | 2 +- .../axum-rest-tracker-api-server/Cargo.toml | 2 +- .../src/environment.rs | 2 +- .../src/v1/context/stats/handlers.rs | 2 +- packages/http-tracker-core/Cargo.toml | 2 +- packages/http-tracker-core/src/container.rs | 2 +- packages/rest-tracker-api-core/Cargo.toml | 2 +- .../rest-tracker-api-core/src/container.rs | 2 +- .../src/statistics/services.rs | 4 +- .../swarm-coordination-registry/Cargo.toml | 2 +- packages/tracker-core/Cargo.toml | 2 +- packages/tracker-core/src/container.rs | 2 +- .../src/statistics/event/handler.rs | 2 +- .../src/statistics/event/listener.rs | 2 +- packages/tracker-core/src/torrent/manager.rs | 2 +- .../src/torrent/repository/in_memory.rs | 2 +- .../tracker-core/tests/common/test_env.rs | 6 +-- packages/udp-tracker-core/Cargo.toml | 2 +- packages/udp-tracker-core/src/container.rs | 2 +- packages/udp-tracker-server/Cargo.toml | 2 +- .../udp-tracker-server/src/environment.rs | 2 +- .../jobs/activity_metrics_updater.rs | 2 +- src/bootstrap/jobs/torrent_repository.rs | 2 +- src/container.rs | 2 +- 29 files changed, 50 insertions(+), 52 deletions(-) diff --git a/.github/workflows/deployment.yaml b/.github/workflows/deployment.yaml index d62b4bbcc..4e8fd579b 100644 --- a/.github/workflows/deployment.yaml +++ b/.github/workflows/deployment.yaml @@ -77,7 +77,7 @@ jobs: cargo publish -p torrust-tracker-located-error cargo publish -p torrust-tracker-metrics cargo publish -p torrust-tracker-primitives + cargo publish -p torrust-tracker-swarm-coordination-registry cargo publish -p torrust-tracker-test-helpers cargo publish -p torrust-tracker-torrent-benchmarking - cargo publish -p torrust-tracker-torrent-repository cargo publish -p torrust-udp-tracker-server diff --git a/Cargo.lock b/Cargo.lock index 009b1e458..ecf178a59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -592,8 +592,8 @@ dependencies = [ "torrust-tracker-events", "torrust-tracker-metrics", "torrust-tracker-primitives", + "torrust-tracker-swarm-coordination-registry", "torrust-tracker-test-helpers", - "torrust-tracker-torrent-repository", "tracing", ] @@ -680,8 +680,8 @@ dependencies = [ "torrust-tracker-located-error", "torrust-tracker-metrics", "torrust-tracker-primitives", + "torrust-tracker-swarm-coordination-registry", "torrust-tracker-test-helpers", - "torrust-tracker-torrent-repository", "tracing", "url", ] @@ -710,8 +710,8 @@ dependencies = [ "torrust-tracker-events", "torrust-tracker-metrics", "torrust-tracker-primitives", + "torrust-tracker-swarm-coordination-registry", "torrust-tracker-test-helpers", - "torrust-tracker-torrent-repository", "tracing", "zerocopy 0.7.35", ] @@ -4555,8 +4555,8 @@ dependencies = [ "torrust-tracker-configuration", "torrust-tracker-events", "torrust-tracker-primitives", + "torrust-tracker-swarm-coordination-registry", "torrust-tracker-test-helpers", - "torrust-tracker-torrent-repository", "tower", "tower-http", "tracing", @@ -4595,8 +4595,8 @@ dependencies = [ "torrust-tracker-configuration", "torrust-tracker-metrics", "torrust-tracker-primitives", + "torrust-tracker-swarm-coordination-registry", "torrust-tracker-test-helpers", - "torrust-tracker-torrent-repository", "torrust-udp-tracker-server", "tower", "tower-http", @@ -4649,8 +4649,8 @@ dependencies = [ "torrust-tracker-events", "torrust-tracker-metrics", "torrust-tracker-primitives", + "torrust-tracker-swarm-coordination-registry", "torrust-tracker-test-helpers", - "torrust-tracker-torrent-repository", "torrust-udp-tracker-server", ] @@ -4697,8 +4697,8 @@ dependencies = [ "torrust-server-lib", "torrust-tracker-clock", "torrust-tracker-configuration", + "torrust-tracker-swarm-coordination-registry", "torrust-tracker-test-helpers", - "torrust-tracker-torrent-repository", "torrust-udp-tracker-server", "tracing", "tracing-subscriber", @@ -4819,17 +4819,7 @@ dependencies = [ ] [[package]] -name = "torrust-tracker-test-helpers" -version = "3.0.0-develop" -dependencies = [ - "rand 0.9.1", - "torrust-tracker-configuration", - "tracing", - "tracing-subscriber", -] - -[[package]] -name = "torrust-tracker-torrent-repository" +name = "torrust-tracker-swarm-coordination-registry" version = "3.0.0-develop" dependencies = [ "aquatic_udp_protocol", @@ -4840,7 +4830,7 @@ dependencies = [ "crossbeam-skiplist", "futures", "mockall", - "rand 0.9.1", + "rand 0.8.5", "rstest", "serde", "thiserror 2.0.12", @@ -4854,6 +4844,16 @@ dependencies = [ "tracing", ] +[[package]] +name = "torrust-tracker-test-helpers" +version = "3.0.0-develop" +dependencies = [ + "rand 0.9.1", + "torrust-tracker-configuration", + "tracing", + "tracing-subscriber", +] + [[package]] name = "torrust-tracker-torrent-repository-benchmarking" version = "3.0.0-develop" @@ -4900,8 +4900,8 @@ dependencies = [ "torrust-tracker-located-error", "torrust-tracker-metrics", "torrust-tracker-primitives", + "torrust-tracker-swarm-coordination-registry", "torrust-tracker-test-helpers", - "torrust-tracker-torrent-repository", "tracing", "url", "uuid", diff --git a/Cargo.toml b/Cargo.toml index 3e6e3e073..976176155 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,7 @@ torrust-rest-tracker-api-core = { version = "3.0.0-develop", path = "packages/re torrust-server-lib = { version = "3.0.0-develop", path = "packages/server-lib" } torrust-tracker-clock = { version = "3.0.0-develop", path = "packages/clock" } torrust-tracker-configuration = { version = "3.0.0-develop", path = "packages/configuration" } -torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "packages/swarm-coordination-registry" } +torrust-tracker-swarm-coordination-registry = { version = "3.0.0-develop", path = "packages/swarm-coordination-registry" } torrust-udp-tracker-server = { version = "3.0.0-develop", path = "packages/udp-tracker-server" } tracing = "0" tracing-subscriber = { version = "0", features = ["json"] } diff --git a/packages/axum-http-tracker-server/Cargo.toml b/packages/axum-http-tracker-server/Cargo.toml index 51283ee01..fa195489c 100644 --- a/packages/axum-http-tracker-server/Cargo.toml +++ b/packages/axum-http-tracker-server/Cargo.toml @@ -33,7 +33,7 @@ torrust-server-lib = { version = "3.0.0-develop", path = "../server-lib" } torrust-tracker-clock = { version = "3.0.0-develop", path = "../clock" } torrust-tracker-configuration = { version = "3.0.0-develop", path = "../configuration" } torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" } -torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } +torrust-tracker-swarm-coordination-registry = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } tower = { version = "0", features = ["timeout"] } tower-http = { version = "0", features = ["compression-full", "cors", "propagate-header", "request-id", "trace"] } tracing = "0" diff --git a/packages/axum-http-tracker-server/src/environment.rs b/packages/axum-http-tracker-server/src/environment.rs index 0c1431db5..54c6b7767 100644 --- a/packages/axum-http-tracker-server/src/environment.rs +++ b/packages/axum-http-tracker-server/src/environment.rs @@ -10,7 +10,7 @@ use torrust_axum_server::tsl::make_rust_tls; use torrust_server_lib::registar::Registar; use torrust_tracker_configuration::{logging, Configuration}; use torrust_tracker_primitives::peer; -use torrust_tracker_torrent_repository::container::TorrentRepositoryContainer; +use torrust_tracker_swarm_coordination_registry::container::TorrentRepositoryContainer; use crate::server::{HttpServer, Launcher, Running, Stopped}; diff --git a/packages/axum-http-tracker-server/src/server.rs b/packages/axum-http-tracker-server/src/server.rs index f7d1ed7ea..b8ece8086 100644 --- a/packages/axum-http-tracker-server/src/server.rs +++ b/packages/axum-http-tracker-server/src/server.rs @@ -259,8 +259,8 @@ mod tests { use torrust_axum_server::tsl::make_rust_tls; use torrust_server_lib::registar::Registar; use torrust_tracker_configuration::{logging, Configuration}; + use torrust_tracker_swarm_coordination_registry::container::TorrentRepositoryContainer; use torrust_tracker_test_helpers::configuration::ephemeral_public; - use torrust_tracker_torrent_repository::container::TorrentRepositoryContainer; use crate::server::{HttpServer, Launcher}; diff --git a/packages/axum-rest-tracker-api-server/Cargo.toml b/packages/axum-rest-tracker-api-server/Cargo.toml index 558dbf6c1..9493b8693 100644 --- a/packages/axum-rest-tracker-api-server/Cargo.toml +++ b/packages/axum-rest-tracker-api-server/Cargo.toml @@ -39,7 +39,7 @@ torrust-tracker-clock = { version = "3.0.0-develop", path = "../clock" } torrust-tracker-configuration = { version = "3.0.0-develop", path = "../configuration" } torrust-tracker-metrics = { version = "3.0.0-develop", path = "../metrics" } torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" } -torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } +torrust-tracker-swarm-coordination-registry = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } torrust-udp-tracker-server = { version = "3.0.0-develop", path = "../udp-tracker-server" } tower = { version = "0", features = ["timeout"] } tower-http = { version = "0", features = ["compression-full", "cors", "propagate-header", "request-id", "trace"] } diff --git a/packages/axum-rest-tracker-api-server/src/environment.rs b/packages/axum-rest-tracker-api-server/src/environment.rs index be93a8723..6be4cc53c 100644 --- a/packages/axum-rest-tracker-api-server/src/environment.rs +++ b/packages/axum-rest-tracker-api-server/src/environment.rs @@ -12,7 +12,7 @@ use torrust_rest_tracker_api_core::container::TrackerHttpApiCoreContainer; use torrust_server_lib::registar::Registar; use torrust_tracker_configuration::{logging, Configuration}; use torrust_tracker_primitives::peer; -use torrust_tracker_torrent_repository::container::TorrentRepositoryContainer; +use torrust_tracker_swarm_coordination_registry::container::TorrentRepositoryContainer; use torrust_udp_tracker_server::container::UdpTrackerServerContainer; use crate::server::{ApiServer, Launcher, Running, Stopped}; diff --git a/packages/axum-rest-tracker-api-server/src/v1/context/stats/handlers.rs b/packages/axum-rest-tracker-api-server/src/v1/context/stats/handlers.rs index 47bb5ad16..b907b861a 100644 --- a/packages/axum-rest-tracker-api-server/src/v1/context/stats/handlers.rs +++ b/packages/axum-rest-tracker-api-server/src/v1/context/stats/handlers.rs @@ -77,7 +77,7 @@ pub async fn get_metrics_handler( State(state): State<( Arc, Arc>, - Arc, + Arc, Arc, Arc, Arc, diff --git a/packages/http-tracker-core/Cargo.toml b/packages/http-tracker-core/Cargo.toml index 008aa92c6..45af59baa 100644 --- a/packages/http-tracker-core/Cargo.toml +++ b/packages/http-tracker-core/Cargo.toml @@ -28,7 +28,7 @@ torrust-tracker-configuration = { version = "3.0.0-develop", path = "../configur torrust-tracker-events = { version = "3.0.0-develop", path = "../events" } torrust-tracker-metrics = { version = "3.0.0-develop", path = "../metrics" } torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" } -torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } +torrust-tracker-swarm-coordination-registry = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } tracing = "0" [dev-dependencies] diff --git a/packages/http-tracker-core/src/container.rs b/packages/http-tracker-core/src/container.rs index f063c0061..35f75e1fe 100644 --- a/packages/http-tracker-core/src/container.rs +++ b/packages/http-tracker-core/src/container.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use bittorrent_tracker_core::container::TrackerCoreContainer; use torrust_tracker_configuration::{Core, HttpTracker}; -use torrust_tracker_torrent_repository::container::TorrentRepositoryContainer; +use torrust_tracker_swarm_coordination_registry::container::TorrentRepositoryContainer; use crate::event::bus::EventBus; use crate::event::sender::Broadcaster; diff --git a/packages/rest-tracker-api-core/Cargo.toml b/packages/rest-tracker-api-core/Cargo.toml index 9a086ad19..cc8eda903 100644 --- a/packages/rest-tracker-api-core/Cargo.toml +++ b/packages/rest-tracker-api-core/Cargo.toml @@ -21,7 +21,7 @@ tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal torrust-tracker-configuration = { version = "3.0.0-develop", path = "../configuration" } torrust-tracker-metrics = { version = "3.0.0-develop", path = "../metrics" } torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" } -torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } +torrust-tracker-swarm-coordination-registry = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } torrust-udp-tracker-server = { version = "3.0.0-develop", path = "../udp-tracker-server" } [dev-dependencies] diff --git a/packages/rest-tracker-api-core/src/container.rs b/packages/rest-tracker-api-core/src/container.rs index 1c4a08e26..f76c2ece3 100644 --- a/packages/rest-tracker-api-core/src/container.rs +++ b/packages/rest-tracker-api-core/src/container.rs @@ -7,7 +7,7 @@ use bittorrent_udp_tracker_core::services::banning::BanService; use bittorrent_udp_tracker_core::{self}; use tokio::sync::RwLock; use torrust_tracker_configuration::{Core, HttpApi, HttpTracker, UdpTracker}; -use torrust_tracker_torrent_repository::container::TorrentRepositoryContainer; +use torrust_tracker_swarm_coordination_registry::container::TorrentRepositoryContainer; use torrust_udp_tracker_server::container::UdpTrackerServerContainer; pub struct TrackerHttpApiCoreContainer { diff --git a/packages/rest-tracker-api-core/src/statistics/services.rs b/packages/rest-tracker-api-core/src/statistics/services.rs index 9a2eb3667..56536a02f 100644 --- a/packages/rest-tracker-api-core/src/statistics/services.rs +++ b/packages/rest-tracker-api-core/src/statistics/services.rs @@ -113,7 +113,7 @@ pub struct TrackerLabeledMetrics { pub async fn get_labeled_metrics( in_memory_torrent_repository: Arc, ban_service: Arc>, - swarms_stats_repository: Arc, + swarms_stats_repository: Arc, tracker_core_stats_repository: Arc, http_stats_repository: Arc, udp_stats_repository: Arc, @@ -165,8 +165,8 @@ mod tests { use tokio::sync::RwLock; use torrust_tracker_configuration::Configuration; use torrust_tracker_events::bus::SenderStatus; + use torrust_tracker_swarm_coordination_registry::container::TorrentRepositoryContainer; use torrust_tracker_test_helpers::configuration; - use torrust_tracker_torrent_repository::container::TorrentRepositoryContainer; use crate::statistics::metrics::{ProtocolMetrics, TorrentsMetrics}; use crate::statistics::services::{get_metrics, TrackerMetrics}; diff --git a/packages/swarm-coordination-registry/Cargo.toml b/packages/swarm-coordination-registry/Cargo.toml index 510a59e9d..074562a47 100644 --- a/packages/swarm-coordination-registry/Cargo.toml +++ b/packages/swarm-coordination-registry/Cargo.toml @@ -1,7 +1,7 @@ [package] description = "A library that provides a repository of torrents files and their peers." keywords = ["library", "repository", "torrents"] -name = "torrust-tracker-torrent-repository" +name = "torrust-tracker-swarm-coordination-registry" readme = "README.md" authors.workspace = true diff --git a/packages/tracker-core/Cargo.toml b/packages/tracker-core/Cargo.toml index 8c9bf7769..f04a3b89b 100644 --- a/packages/tracker-core/Cargo.toml +++ b/packages/tracker-core/Cargo.toml @@ -33,7 +33,7 @@ torrust-tracker-events = { version = "3.0.0-develop", path = "../events" } torrust-tracker-located-error = { version = "3.0.0-develop", path = "../located-error" } torrust-tracker-metrics = { version = "3.0.0-develop", path = "../metrics" } torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" } -torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } +torrust-tracker-swarm-coordination-registry = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } tracing = "0" [dev-dependencies] diff --git a/packages/tracker-core/src/container.rs b/packages/tracker-core/src/container.rs index 02af67118..949761553 100644 --- a/packages/tracker-core/src/container.rs +++ b/packages/tracker-core/src/container.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use torrust_tracker_configuration::Core; -use torrust_tracker_torrent_repository::container::TorrentRepositoryContainer; +use torrust_tracker_swarm_coordination_registry::container::TorrentRepositoryContainer; use crate::announce_handler::AnnounceHandler; use crate::authentication::handler::KeysHandler; diff --git a/packages/tracker-core/src/statistics/event/handler.rs b/packages/tracker-core/src/statistics/event/handler.rs index 0909dc184..9a5182f25 100644 --- a/packages/tracker-core/src/statistics/event/handler.rs +++ b/packages/tracker-core/src/statistics/event/handler.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use torrust_tracker_metrics::label::LabelSet; use torrust_tracker_metrics::metric_name; use torrust_tracker_primitives::DurationSinceUnixEpoch; -use torrust_tracker_torrent_repository::event::Event; +use torrust_tracker_swarm_coordination_registry::event::Event; use crate::statistics::persisted::downloads::DatabaseDownloadsMetricRepository; use crate::statistics::repository::Repository; diff --git a/packages/tracker-core/src/statistics/event/listener.rs b/packages/tracker-core/src/statistics/event/listener.rs index 2702aa858..d3beaf41f 100644 --- a/packages/tracker-core/src/statistics/event/listener.rs +++ b/packages/tracker-core/src/statistics/event/listener.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use tokio::task::JoinHandle; use torrust_tracker_clock::clock::Time; use torrust_tracker_events::receiver::RecvError; -use torrust_tracker_torrent_repository::event::receiver::Receiver; +use torrust_tracker_swarm_coordination_registry::event::receiver::Receiver; use super::handler::handle_event; use crate::statistics::persisted::downloads::DatabaseDownloadsMetricRepository; diff --git a/packages/tracker-core/src/torrent/manager.rs b/packages/tracker-core/src/torrent/manager.rs index 766fa5c4a..cbdf01193 100644 --- a/packages/tracker-core/src/torrent/manager.rs +++ b/packages/tracker-core/src/torrent/manager.rs @@ -148,7 +148,7 @@ mod tests { use std::sync::Arc; use torrust_tracker_configuration::Core; - use torrust_tracker_torrent_repository::Swarms; + use torrust_tracker_swarm_coordination_registry::Swarms; use super::{DatabaseDownloadsMetricRepository, TorrentsManager}; use crate::databases::setup::initialize_database; diff --git a/packages/tracker-core/src/torrent/repository/in_memory.rs b/packages/tracker-core/src/torrent/repository/in_memory.rs index cc873726d..47b34ad26 100644 --- a/packages/tracker-core/src/torrent/repository/in_memory.rs +++ b/packages/tracker-core/src/torrent/repository/in_memory.rs @@ -7,7 +7,7 @@ use torrust_tracker_configuration::{TrackerPolicy, TORRENT_PEERS_LIMIT}; use torrust_tracker_primitives::pagination::Pagination; use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata}; use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads, NumberOfDownloadsBTreeMap}; -use torrust_tracker_torrent_repository::{SwarmHandle, Swarms}; +use torrust_tracker_swarm_coordination_registry::{SwarmHandle, Swarms}; /// In-memory repository for torrent entries. /// diff --git a/packages/tracker-core/tests/common/test_env.rs b/packages/tracker-core/tests/common/test_env.rs index 2aafbbbad..64bdcaad8 100644 --- a/packages/tracker-core/tests/common/test_env.rs +++ b/packages/tracker-core/tests/common/test_env.rs @@ -14,7 +14,7 @@ use torrust_tracker_primitives::core::{AnnounceData, ScrapeData}; use torrust_tracker_primitives::peer::Peer; use torrust_tracker_primitives::swarm_metadata::SwarmMetadata; use torrust_tracker_primitives::DurationSinceUnixEpoch; -use torrust_tracker_torrent_repository::container::TorrentRepositoryContainer; +use torrust_tracker_swarm_coordination_registry::container::TorrentRepositoryContainer; pub struct TestEnv { pub torrent_repository_container: Arc, @@ -67,11 +67,10 @@ impl TestEnv { async fn run_jobs(&self) { let mut jobs = vec![]; - let job = torrust_tracker_torrent_repository::statistics::event::listener::run_event_listener( + let job = torrust_tracker_swarm_coordination_registry::statistics::event::listener::run_event_listener( self.torrent_repository_container.event_bus.receiver(), &self.torrent_repository_container.stats_repository, ); - jobs.push(job); let job = bittorrent_tracker_core::statistics::event::listener::run_event_listener( @@ -83,7 +82,6 @@ impl TestEnv { .tracker_policy .persistent_torrent_completed_stat, ); - jobs.push(job); // Give the event listeners some time to start diff --git a/packages/udp-tracker-core/Cargo.toml b/packages/udp-tracker-core/Cargo.toml index 2933a7e70..290c5fbfd 100644 --- a/packages/udp-tracker-core/Cargo.toml +++ b/packages/udp-tracker-core/Cargo.toml @@ -33,7 +33,7 @@ torrust-tracker-configuration = { version = "3.0.0-develop", path = "../configur torrust-tracker-events = { version = "3.0.0-develop", path = "../events" } torrust-tracker-metrics = { version = "3.0.0-develop", path = "../metrics" } torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" } -torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } +torrust-tracker-swarm-coordination-registry = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } tracing = "0" zerocopy = "0.7" diff --git a/packages/udp-tracker-core/src/container.rs b/packages/udp-tracker-core/src/container.rs index 07a8a09ef..c4be395fc 100644 --- a/packages/udp-tracker-core/src/container.rs +++ b/packages/udp-tracker-core/src/container.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use bittorrent_tracker_core::container::TrackerCoreContainer; use tokio::sync::RwLock; use torrust_tracker_configuration::{Core, UdpTracker}; -use torrust_tracker_torrent_repository::container::TorrentRepositoryContainer; +use torrust_tracker_swarm_coordination_registry::container::TorrentRepositoryContainer; use crate::event::bus::EventBus; use crate::event::sender::Broadcaster; diff --git a/packages/udp-tracker-server/Cargo.toml b/packages/udp-tracker-server/Cargo.toml index 396dc0805..72fa520ba 100644 --- a/packages/udp-tracker-server/Cargo.toml +++ b/packages/udp-tracker-server/Cargo.toml @@ -33,7 +33,7 @@ torrust-tracker-events = { version = "3.0.0-develop", path = "../events" } torrust-tracker-located-error = { version = "3.0.0-develop", path = "../located-error" } torrust-tracker-metrics = { version = "3.0.0-develop", path = "../metrics" } torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" } -torrust-tracker-torrent-repository = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } +torrust-tracker-swarm-coordination-registry = { version = "3.0.0-develop", path = "../swarm-coordination-registry" } tracing = "0" url = { version = "2", features = ["serde"] } uuid = { version = "1", features = ["v4"] } diff --git a/packages/udp-tracker-server/src/environment.rs b/packages/udp-tracker-server/src/environment.rs index 94a166e4e..3f479a02d 100644 --- a/packages/udp-tracker-server/src/environment.rs +++ b/packages/udp-tracker-server/src/environment.rs @@ -8,7 +8,7 @@ use tokio::task::JoinHandle; use torrust_server_lib::registar::Registar; use torrust_tracker_configuration::{logging, Configuration, DEFAULT_TIMEOUT}; use torrust_tracker_primitives::peer; -use torrust_tracker_torrent_repository::container::TorrentRepositoryContainer; +use torrust_tracker_swarm_coordination_registry::container::TorrentRepositoryContainer; use crate::container::UdpTrackerServerContainer; use crate::server::spawner::Spawner; diff --git a/src/bootstrap/jobs/activity_metrics_updater.rs b/src/bootstrap/jobs/activity_metrics_updater.rs index 7411c05cf..9813fed65 100644 --- a/src/bootstrap/jobs/activity_metrics_updater.rs +++ b/src/bootstrap/jobs/activity_metrics_updater.rs @@ -11,7 +11,7 @@ use crate::CurrentClock; #[must_use] pub fn start_job(config: &Configuration, app_container: &Arc) -> JoinHandle<()> { - torrust_tracker_torrent_repository::statistics::activity_metrics_updater::start_job( + torrust_tracker_swarm_coordination_registry::statistics::activity_metrics_updater::start_job( &app_container.torrent_repository_container.swarms.clone(), &app_container.torrent_repository_container.stats_repository.clone(), peer_inactivity_cutoff_timestamp(config.core.tracker_policy.max_peer_timeout), diff --git a/src/bootstrap/jobs/torrent_repository.rs b/src/bootstrap/jobs/torrent_repository.rs index ea0d215ee..c64917ea6 100644 --- a/src/bootstrap/jobs/torrent_repository.rs +++ b/src/bootstrap/jobs/torrent_repository.rs @@ -7,7 +7,7 @@ use crate::container::AppContainer; pub fn start_event_listener(config: &Configuration, app_container: &Arc) -> Option> { if config.core.tracker_usage_statistics { - let job = torrust_tracker_torrent_repository::statistics::event::listener::run_event_listener( + let job = torrust_tracker_swarm_coordination_registry::statistics::event::listener::run_event_listener( app_container.torrent_repository_container.event_bus.receiver(), &app_container.torrent_repository_container.stats_repository, ); diff --git a/src/container.rs b/src/container.rs index 98c455780..bb5873fb2 100644 --- a/src/container.rs +++ b/src/container.rs @@ -9,7 +9,7 @@ use bittorrent_udp_tracker_core::{self}; use torrust_rest_tracker_api_core::container::TrackerHttpApiCoreContainer; use torrust_server_lib::registar::Registar; use torrust_tracker_configuration::{Configuration, HttpApi}; -use torrust_tracker_torrent_repository::container::TorrentRepositoryContainer; +use torrust_tracker_swarm_coordination_registry::container::TorrentRepositoryContainer; use torrust_udp_tracker_server::container::UdpTrackerServerContainer; use tracing::instrument; From 2768306a8b5db288f27dedac6ce59a11efc61bcb Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Thu, 29 May 2025 10:50:56 +0100 Subject: [PATCH 3/9] refactor: [#1519] rename Swarm to Coordinator --- .../swarm-coordination-registry/src/lib.rs | 4 +- .../swarm-coordination-registry/src/swarm.rs | 102 +++++++++--------- .../swarm-coordination-registry/src/swarms.rs | 12 +-- 3 files changed, 59 insertions(+), 59 deletions(-) diff --git a/packages/swarm-coordination-registry/src/lib.rs b/packages/swarm-coordination-registry/src/lib.rs index 3adf2f18d..c93f553fa 100644 --- a/packages/swarm-coordination-registry/src/lib.rs +++ b/packages/swarm-coordination-registry/src/lib.rs @@ -10,8 +10,8 @@ use tokio::sync::Mutex; use torrust_tracker_clock::clock; pub type Swarms = swarms::Swarms; -pub type SwarmHandle = Arc>; -pub type Swarm = swarm::Swarm; +pub type SwarmHandle = Arc>; +pub type Coordinator = swarm::Coordinator; /// Working version, for production. #[cfg(not(test))] diff --git a/packages/swarm-coordination-registry/src/swarm.rs b/packages/swarm-coordination-registry/src/swarm.rs index 362fc6153..81e454d8b 100644 --- a/packages/swarm-coordination-registry/src/swarm.rs +++ b/packages/swarm-coordination-registry/src/swarm.rs @@ -15,14 +15,14 @@ use crate::event::sender::Sender; use crate::event::Event; #[derive(Clone)] -pub struct Swarm { +pub struct Coordinator { info_hash: InfoHash, peers: BTreeMap>, metadata: SwarmMetadata, event_sender: Sender, } -impl Swarm { +impl Coordinator { #[must_use] pub fn new(info_hash: &InfoHash, downloaded: u32, event_sender: Sender) -> Self { Self { @@ -326,26 +326,26 @@ mod tests { use torrust_tracker_primitives::swarm_metadata::SwarmMetadata; use torrust_tracker_primitives::DurationSinceUnixEpoch; - use crate::swarm::Swarm; + use crate::swarm::Coordinator; use crate::tests::sample_info_hash; #[test] fn it_should_be_empty_when_no_peers_have_been_inserted() { - let swarm = Swarm::new(&sample_info_hash(), 0, None); + let swarm = Coordinator::new(&sample_info_hash(), 0, None); assert!(swarm.is_empty()); } #[test] fn it_should_have_zero_length_when_no_peers_have_been_inserted() { - let swarm = Swarm::new(&sample_info_hash(), 0, None); + let swarm = Coordinator::new(&sample_info_hash(), 0, None); assert_eq!(swarm.len(), 0); } #[tokio::test] async fn it_should_allow_inserting_a_new_peer() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let peer = PeerBuilder::default().build(); @@ -354,7 +354,7 @@ mod tests { #[tokio::test] async fn it_should_allow_updating_a_preexisting_peer() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let peer = PeerBuilder::default().build(); @@ -365,7 +365,7 @@ mod tests { #[tokio::test] async fn it_should_allow_getting_all_peers() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let peer = PeerBuilder::default().build(); @@ -376,7 +376,7 @@ mod tests { #[tokio::test] async fn it_should_allow_getting_one_peer_by_id() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let peer = PeerBuilder::default().build(); @@ -387,7 +387,7 @@ mod tests { #[tokio::test] async fn it_should_increase_the_number_of_peers_after_inserting_a_new_one() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let peer = PeerBuilder::default().build(); @@ -398,7 +398,7 @@ mod tests { #[tokio::test] async fn it_should_decrease_the_number_of_peers_after_removing_one() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let peer = PeerBuilder::default().build(); @@ -411,7 +411,7 @@ mod tests { #[tokio::test] async fn it_should_allow_removing_an_existing_peer() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let peer = PeerBuilder::default().build(); @@ -425,7 +425,7 @@ mod tests { #[tokio::test] async fn it_should_allow_removing_a_non_existing_peer() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let peer = PeerBuilder::default().build(); @@ -434,7 +434,7 @@ mod tests { #[tokio::test] async fn it_should_allow_getting_all_peers_excluding_peers_with_a_given_address() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let peer1 = PeerBuilder::default() .with_peer_id(&PeerId(*b"-qB00000000000000001")) @@ -453,7 +453,7 @@ mod tests { #[tokio::test] async fn it_should_count_inactive_peers() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let one_second = DurationSinceUnixEpoch::new(1, 0); @@ -469,7 +469,7 @@ mod tests { #[tokio::test] async fn it_should_remove_inactive_peers() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let one_second = DurationSinceUnixEpoch::new(1, 0); @@ -486,7 +486,7 @@ mod tests { #[tokio::test] async fn it_should_not_remove_active_peers() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let one_second = DurationSinceUnixEpoch::new(1, 0); @@ -507,20 +507,20 @@ mod tests { use torrust_tracker_primitives::peer::fixture::PeerBuilder; use crate::tests::sample_info_hash; - use crate::Swarm; + use crate::Coordinator; - fn empty_swarm() -> Swarm { - Swarm::new(&sample_info_hash(), 0, None) + fn empty_swarm() -> Coordinator { + Coordinator::new(&sample_info_hash(), 0, None) } - async fn not_empty_swarm() -> Swarm { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + async fn not_empty_swarm() -> Coordinator { + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); swarm.upsert_peer(PeerBuilder::default().build().into()).await; swarm } - async fn not_empty_swarm_with_downloads() -> Swarm { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + async fn not_empty_swarm_with_downloads() -> Coordinator { + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let mut peer = PeerBuilder::leecher().build(); @@ -602,7 +602,7 @@ mod tests { #[tokio::test] async fn it_should_allow_inserting_two_identical_peers_except_for_the_socket_address() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let peer1 = PeerBuilder::default() .with_peer_addr(&SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 6969)) @@ -619,7 +619,7 @@ mod tests { #[tokio::test] async fn it_should_not_allow_inserting_two_peers_with_different_peer_id_but_the_same_socket_address() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); // When that happens the peer ID will be changed in the swarm. // In practice, it's like if the peer had changed its ID. @@ -641,7 +641,7 @@ mod tests { #[tokio::test] async fn it_should_return_the_swarm_metadata() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let seeder = PeerBuilder::seeder().build(); let leecher = PeerBuilder::leecher().build(); @@ -661,7 +661,7 @@ mod tests { #[tokio::test] async fn it_should_return_the_number_of_seeders_in_the_list() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let seeder = PeerBuilder::seeder().build(); let leecher = PeerBuilder::leecher().build(); @@ -676,7 +676,7 @@ mod tests { #[tokio::test] async fn it_should_return_the_number_of_leechers_in_the_list() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let seeder = PeerBuilder::seeder().build(); let leecher = PeerBuilder::leecher().build(); @@ -691,7 +691,7 @@ mod tests { #[tokio::test] async fn it_should_be_a_peerless_swarm_when_it_does_not_contain_any_peers() { - let swarm = Swarm::new(&sample_info_hash(), 0, None); + let swarm = Coordinator::new(&sample_info_hash(), 0, None); assert!(swarm.is_peerless()); } @@ -700,12 +700,12 @@ mod tests { mod when_a_new_peer_is_added { use torrust_tracker_primitives::peer::fixture::PeerBuilder; - use crate::swarm::Swarm; + use crate::swarm::Coordinator; use crate::tests::sample_info_hash; #[tokio::test] async fn it_should_increase_the_number_of_leechers_if_the_new_peer_is_a_leecher_() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let leechers = swarm.metadata().leechers(); @@ -718,7 +718,7 @@ mod tests { #[tokio::test] async fn it_should_increase_the_number_of_seeders_if_the_new_peer_is_a_seeder() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let seeders = swarm.metadata().seeders(); @@ -732,7 +732,7 @@ mod tests { #[tokio::test] async fn it_should_not_increasing_the_number_of_downloads_if_the_new_peer_has_completed_downloading_as_it_was_not_previously_known( ) { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let downloads = swarm.metadata().downloads(); @@ -747,12 +747,12 @@ mod tests { mod when_a_peer_is_removed { use torrust_tracker_primitives::peer::fixture::PeerBuilder; - use crate::swarm::Swarm; + use crate::swarm::Coordinator; use crate::tests::sample_info_hash; #[tokio::test] async fn it_should_decrease_the_number_of_leechers_if_the_removed_peer_was_a_leecher() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let leecher = PeerBuilder::leecher().build(); @@ -767,7 +767,7 @@ mod tests { #[tokio::test] async fn it_should_decrease_the_number_of_seeders_if_the_removed_peer_was_a_seeder() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let seeder = PeerBuilder::seeder().build(); @@ -786,12 +786,12 @@ mod tests { use torrust_tracker_primitives::peer::fixture::PeerBuilder; - use crate::swarm::Swarm; + use crate::swarm::Coordinator; use crate::tests::sample_info_hash; #[tokio::test] async fn it_should_decrease_the_number_of_leechers_when_a_removed_peer_is_a_leecher() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let leecher = PeerBuilder::leecher().build(); @@ -806,7 +806,7 @@ mod tests { #[tokio::test] async fn it_should_decrease_the_number_of_seeders_when_the_removed_peer_is_a_seeder() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let seeder = PeerBuilder::seeder().build(); @@ -824,12 +824,12 @@ mod tests { use aquatic_udp_protocol::NumberOfBytes; use torrust_tracker_primitives::peer::fixture::PeerBuilder; - use crate::swarm::Swarm; + use crate::swarm::Coordinator; use crate::tests::sample_info_hash; #[tokio::test] async fn it_should_increase_seeders_and_decreasing_leechers_when_the_peer_changes_from_leecher_to_seeder_() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let mut peer = PeerBuilder::leecher().build(); @@ -848,7 +848,7 @@ mod tests { #[tokio::test] async fn it_should_increase_leechers_and_decreasing_seeders_when_the_peer_changes_from_seeder_to_leecher() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let mut peer = PeerBuilder::seeder().build(); @@ -867,7 +867,7 @@ mod tests { #[tokio::test] async fn it_should_increase_the_number_of_downloads_when_the_peer_announces_completed_downloading() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let mut peer = PeerBuilder::leecher().build(); @@ -884,7 +884,7 @@ mod tests { #[tokio::test] async fn it_should_not_increasing_the_number_of_downloads_when_the_peer_announces_completed_downloading_twice_() { - let mut swarm = Swarm::new(&sample_info_hash(), 0, None); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, None); let mut peer = PeerBuilder::leecher().build(); @@ -913,7 +913,7 @@ mod tests { use crate::event::sender::tests::{expect_event_sequence, MockEventSender}; use crate::event::Event; - use crate::swarm::Swarm; + use crate::swarm::Coordinator; use crate::tests::sample_info_hash; #[tokio::test] @@ -925,7 +925,7 @@ mod tests { expect_event_sequence(&mut event_sender_mock, vec![Event::PeerAdded { info_hash, peer }]); - let mut swarm = Swarm::new(&sample_info_hash(), 0, Some(Arc::new(event_sender_mock))); + let mut swarm = Coordinator::new(&sample_info_hash(), 0, Some(Arc::new(event_sender_mock))); swarm.upsert_peer(peer.into()).await; } @@ -942,7 +942,7 @@ mod tests { vec![Event::PeerAdded { info_hash, peer }, Event::PeerRemoved { info_hash, peer }], ); - let mut swarm = Swarm::new(&info_hash, 0, Some(Arc::new(event_sender_mock))); + let mut swarm = Coordinator::new(&info_hash, 0, Some(Arc::new(event_sender_mock))); // Insert the peer swarm.upsert_peer(peer.into()).await; @@ -962,7 +962,7 @@ mod tests { vec![Event::PeerAdded { info_hash, peer }, Event::PeerRemoved { info_hash, peer }], ); - let mut swarm = Swarm::new(&info_hash, 0, Some(Arc::new(event_sender_mock))); + let mut swarm = Coordinator::new(&info_hash, 0, Some(Arc::new(event_sender_mock))); // Insert the peer swarm.upsert_peer(peer.into()).await; @@ -992,7 +992,7 @@ mod tests { ], ); - let mut swarm = Swarm::new(&info_hash, 0, Some(Arc::new(event_sender_mock))); + let mut swarm = Coordinator::new(&info_hash, 0, Some(Arc::new(event_sender_mock))); // Insert the peer swarm.upsert_peer(peer.into()).await; @@ -1028,7 +1028,7 @@ mod tests { ], ); - let mut swarm = Swarm::new(&info_hash, 0, Some(Arc::new(event_sender_mock))); + let mut swarm = Coordinator::new(&info_hash, 0, Some(Arc::new(event_sender_mock))); // Insert the peer swarm.upsert_peer(started_peer.into()).await; diff --git a/packages/swarm-coordination-registry/src/swarms.rs b/packages/swarm-coordination-registry/src/swarms.rs index 8e7bc24de..12fe2190d 100644 --- a/packages/swarm-coordination-registry/src/swarms.rs +++ b/packages/swarm-coordination-registry/src/swarms.rs @@ -11,7 +11,7 @@ use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads use crate::event::sender::Sender; use crate::event::Event; -use crate::swarm::Swarm; +use crate::swarm::Coordinator; use crate::SwarmHandle; #[derive(Default)] @@ -60,7 +60,7 @@ impl Swarms { let number_of_downloads = opt_persistent_torrent.unwrap_or_default(); let new_swarm_handle = - SwarmHandle::new(Swarm::new(info_hash, number_of_downloads, self.event_sender.clone()).into()); + SwarmHandle::new(Coordinator::new(info_hash, number_of_downloads, self.event_sender.clone()).into()); let new_swarm_handle = self.swarms.get_or_insert(*info_hash, new_swarm_handle); @@ -86,7 +86,7 @@ impl Swarms { } /// Inserts a new swarm. Only used for testing purposes. - pub fn insert(&self, info_hash: &InfoHash, swarm: Swarm) { + pub fn insert(&self, info_hash: &InfoHash, swarm: Coordinator) { // code-review: swarms builder? or constructor from vec? // It's only used for testing purposes. It allows to pre-define the // initial state of the swarm without having to go through the upsert @@ -366,7 +366,7 @@ impl Swarms { continue; } - let entry = SwarmHandle::new(Swarm::new(info_hash, *completed, self.event_sender.clone()).into()); + let entry = SwarmHandle::new(Coordinator::new(info_hash, *completed, self.event_sender.clone()).into()); // Since SkipMap is lock-free the torrent could have been inserted // after checking if it exists. @@ -853,7 +853,7 @@ mod tests { use crate::swarms::Swarms; use crate::tests::{sample_info_hash, sample_peer}; - use crate::{Swarm, SwarmHandle}; + use crate::{Coordinator, SwarmHandle}; /// `TorrentEntry` data is not directly accessible. It's only /// accessible through the trait methods. We need this temporary @@ -871,7 +871,7 @@ mod tests { } #[allow(clippy::from_over_into)] - impl Into for Swarm { + impl Into for Coordinator { fn into(self) -> TorrentEntryInfo { let torrent_entry_info = TorrentEntryInfo { swarm_metadata: self.metadata(), From ba37801d3c62b2b2c4ad1df1785609e6543d7d61 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Thu, 29 May 2025 10:55:08 +0100 Subject: [PATCH 4/9] refactor: [#1519] rename Swarms to Registry --- .../swarm-coordination-registry/src/lib.rs | 2 +- .../swarm-coordination-registry/src/swarms.rs | 110 +++++++++--------- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/packages/swarm-coordination-registry/src/lib.rs b/packages/swarm-coordination-registry/src/lib.rs index c93f553fa..f3926331a 100644 --- a/packages/swarm-coordination-registry/src/lib.rs +++ b/packages/swarm-coordination-registry/src/lib.rs @@ -9,7 +9,7 @@ use std::sync::Arc; use tokio::sync::Mutex; use torrust_tracker_clock::clock; -pub type Swarms = swarms::Swarms; +pub type Swarms = swarms::Registry; pub type SwarmHandle = Arc>; pub type Coordinator = swarm::Coordinator; diff --git a/packages/swarm-coordination-registry/src/swarms.rs b/packages/swarm-coordination-registry/src/swarms.rs index 12fe2190d..c14cb66b7 100644 --- a/packages/swarm-coordination-registry/src/swarms.rs +++ b/packages/swarm-coordination-registry/src/swarms.rs @@ -15,12 +15,12 @@ use crate::swarm::Coordinator; use crate::SwarmHandle; #[derive(Default)] -pub struct Swarms { +pub struct Registry { swarms: SkipMap, event_sender: Sender, } -impl Swarms { +impl Registry { #[must_use] pub fn new(event_sender: Sender) -> Self { Self { @@ -510,7 +510,7 @@ mod tests { use aquatic_udp_protocol::PeerId; - use crate::swarms::Swarms; + use crate::swarms::Registry; use crate::tests::{sample_info_hash, sample_peer}; /// It generates a peer id from a number where the number is the last @@ -543,13 +543,13 @@ mod tests { #[tokio::test] async fn it_should_return_zero_length_when_it_has_no_swarms() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); assert_eq!(swarms.len(), 0); } #[tokio::test] async fn it_should_return_the_length_when_it_has_swarms() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let info_hash = sample_info_hash(); let peer = sample_peer(); swarms.handle_announcement(&info_hash, &peer, None).await.unwrap(); @@ -558,7 +558,7 @@ mod tests { #[tokio::test] async fn it_should_be_empty_when_it_has_no_swarms() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); assert!(swarms.is_empty()); let info_hash = sample_info_hash(); @@ -569,7 +569,7 @@ mod tests { #[tokio::test] async fn it_should_not_be_empty_when_it_has_at_least_one_swarm() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let info_hash = sample_info_hash(); let peer = sample_peer(); swarms.handle_announcement(&info_hash, &peer, None).await.unwrap(); @@ -581,12 +581,12 @@ mod tests { use std::sync::Arc; - use crate::swarms::Swarms; + use crate::swarms::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] async fn it_should_add_the_first_peer_to_the_torrent_peer_list() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let info_hash = sample_info_hash(); @@ -597,7 +597,7 @@ mod tests { #[tokio::test] async fn it_should_allow_adding_the_same_peer_twice_to_the_torrent_peer_list() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let info_hash = sample_info_hash(); @@ -618,12 +618,12 @@ mod tests { use torrust_tracker_primitives::DurationSinceUnixEpoch; use crate::swarms::tests::the_swarm_repository::numeric_peer_id; - use crate::swarms::Swarms; + use crate::swarms::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] async fn it_should_return_the_peers_for_a_given_torrent() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let info_hash = sample_info_hash(); let peer = sample_peer(); @@ -637,7 +637,7 @@ mod tests { #[tokio::test] async fn it_should_return_an_empty_list_or_peers_for_a_non_existing_torrent() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let peers = swarms.get_swarm_peers(&sample_info_hash(), 74).await.unwrap(); @@ -646,7 +646,7 @@ mod tests { #[tokio::test] async fn it_should_return_74_peers_at_the_most_for_a_given_torrent() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let info_hash = sample_info_hash(); @@ -680,12 +680,12 @@ mod tests { use torrust_tracker_primitives::DurationSinceUnixEpoch; use crate::swarms::tests::the_swarm_repository::numeric_peer_id; - use crate::swarms::Swarms; + use crate::swarms::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] async fn it_should_return_an_empty_peer_list_for_a_non_existing_torrent() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let peers = swarms .get_peers_peers_excluding(&sample_info_hash(), &sample_peer(), TORRENT_PEERS_LIMIT) @@ -697,7 +697,7 @@ mod tests { #[tokio::test] async fn it_should_return_the_peers_for_a_given_torrent_excluding_a_given_peer() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let info_hash = sample_info_hash(); let peer = sample_peer(); @@ -714,7 +714,7 @@ mod tests { #[tokio::test] async fn it_should_return_74_peers_at_the_most_for_a_given_torrent_when_it_filters_out_a_given_peer() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let info_hash = sample_info_hash(); @@ -757,12 +757,12 @@ mod tests { use torrust_tracker_configuration::TrackerPolicy; use torrust_tracker_primitives::DurationSinceUnixEpoch; - use crate::swarms::Swarms; + use crate::swarms::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] async fn it_should_remove_a_torrent_entry() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let info_hash = sample_info_hash(); swarms.handle_announcement(&info_hash, &sample_peer(), None).await.unwrap(); @@ -774,7 +774,7 @@ mod tests { #[tokio::test] async fn it_should_count_inactive_peers() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let info_hash = sample_info_hash(); let mut peer = sample_peer(); @@ -790,7 +790,7 @@ mod tests { #[tokio::test] async fn it_should_remove_peers_that_have_not_been_updated_after_a_cutoff_time() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let info_hash = sample_info_hash(); let mut peer = sample_peer(); @@ -811,8 +811,8 @@ mod tests { .contains(&Arc::new(peer))); } - async fn initialize_repository_with_one_torrent_without_peers(info_hash: &InfoHash) -> Arc { - let swarms = Arc::new(Swarms::default()); + async fn initialize_repository_with_one_torrent_without_peers(info_hash: &InfoHash) -> Arc { + let swarms = Arc::new(Registry::default()); // Insert a sample peer for the torrent to force adding the torrent entry let mut peer = sample_peer(); @@ -851,7 +851,7 @@ mod tests { use torrust_tracker_primitives::peer::Peer; use torrust_tracker_primitives::swarm_metadata::SwarmMetadata; - use crate::swarms::Swarms; + use crate::swarms::Registry; use crate::tests::{sample_info_hash, sample_peer}; use crate::{Coordinator, SwarmHandle}; @@ -884,7 +884,7 @@ mod tests { #[tokio::test] async fn it_should_return_one_torrent_entry_by_infohash() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let info_hash = sample_info_hash(); let peer = sample_peer(); @@ -915,12 +915,12 @@ mod tests { use crate::swarms::tests::the_swarm_repository::returning_torrent_entries::{ torrent_entry_info, TorrentEntryInfo, }; - use crate::swarms::Swarms; + use crate::swarms::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] async fn without_pagination() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let info_hash = sample_info_hash(); let peer = sample_peer(); @@ -955,7 +955,7 @@ mod tests { use crate::swarms::tests::the_swarm_repository::returning_torrent_entries::{ torrent_entry_info, TorrentEntryInfo, }; - use crate::swarms::Swarms; + use crate::swarms::Registry; use crate::tests::{ sample_info_hash_alphabetically_ordered_after_sample_info_hash_one, sample_info_hash_one, sample_peer_one, sample_peer_two, @@ -963,7 +963,7 @@ mod tests { #[tokio::test] async fn it_should_return_the_first_page() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); // Insert one torrent entry let info_hash_one = sample_info_hash_one(); @@ -998,7 +998,7 @@ mod tests { #[tokio::test] async fn it_should_return_the_second_page() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); // Insert one torrent entry let info_hash_one = sample_info_hash_one(); @@ -1033,7 +1033,7 @@ mod tests { #[tokio::test] async fn it_should_allow_changing_the_page_size() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); // Insert one torrent entry let info_hash_one = sample_info_hash_one(); @@ -1061,14 +1061,14 @@ mod tests { use bittorrent_primitives::info_hash::fixture::gen_seeded_infohash; use torrust_tracker_primitives::swarm_metadata::AggregateActiveSwarmMetadata; - use crate::swarms::Swarms; + use crate::swarms::Registry; use crate::tests::{complete_peer, leecher, sample_info_hash, seeder}; // todo: refactor to use test parametrization #[tokio::test] async fn it_should_get_empty_aggregate_swarm_metadata_when_there_are_no_torrents() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let aggregate_swarm_metadata = swarms.get_aggregate_swarm_metadata().await.unwrap(); @@ -1085,7 +1085,7 @@ mod tests { #[tokio::test] async fn it_should_return_the_aggregate_swarm_metadata_when_there_is_a_leecher() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); swarms .handle_announcement(&sample_info_hash(), &leecher(), None) @@ -1107,7 +1107,7 @@ mod tests { #[tokio::test] async fn it_should_return_the_aggregate_swarm_metadata_when_there_is_a_seeder() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); swarms .handle_announcement(&sample_info_hash(), &seeder(), None) @@ -1129,7 +1129,7 @@ mod tests { #[tokio::test] async fn it_should_return_the_aggregate_swarm_metadata_when_there_is_a_completed_peer() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); swarms .handle_announcement(&sample_info_hash(), &complete_peer(), None) @@ -1151,7 +1151,7 @@ mod tests { #[tokio::test] async fn it_should_return_the_aggregate_swarm_metadata_when_there_are_multiple_torrents() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let start_time = std::time::Instant::now(); for i in 0..1_000_000 { @@ -1183,12 +1183,12 @@ mod tests { use torrust_tracker_primitives::DurationSinceUnixEpoch; - use crate::swarms::Swarms; + use crate::swarms::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] async fn no_peerless_torrents() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); assert_eq!(swarms.count_peerless_torrents().await.unwrap(), 0); } @@ -1197,7 +1197,7 @@ mod tests { let info_hash = sample_info_hash(); let peer = sample_peer(); - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); swarms.handle_announcement(&info_hash, &peer, None).await.unwrap(); let current_cutoff = peer.updated + DurationSinceUnixEpoch::from_secs(1); @@ -1210,12 +1210,12 @@ mod tests { mod it_should_count_peers { use std::sync::Arc; - use crate::swarms::Swarms; + use crate::swarms::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] async fn no_peers() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); assert_eq!(swarms.count_peers().await.unwrap(), 0); } @@ -1224,7 +1224,7 @@ mod tests { let info_hash = sample_info_hash(); let peer = sample_peer(); - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); swarms.handle_announcement(&info_hash, &peer, None).await.unwrap(); assert_eq!(swarms.count_peers().await.unwrap(), 1); @@ -1238,12 +1238,12 @@ mod tests { use torrust_tracker_primitives::swarm_metadata::SwarmMetadata; - use crate::swarms::Swarms; + use crate::swarms::Registry; use crate::tests::{leecher, sample_info_hash}; #[tokio::test] async fn it_should_get_swarm_metadata_for_an_existing_torrent() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let infohash = sample_info_hash(); @@ -1263,7 +1263,7 @@ mod tests { #[tokio::test] async fn it_should_return_zeroed_swarm_metadata_for_a_non_existing_torrent() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let swarm_metadata = swarms.get_swarm_metadata_or_default(&sample_info_hash()).await.unwrap(); @@ -1277,12 +1277,12 @@ mod tests { use torrust_tracker_primitives::NumberOfDownloadsBTreeMap; - use crate::swarms::Swarms; + use crate::swarms::Registry; use crate::tests::{leecher, sample_info_hash}; #[tokio::test] async fn it_should_allow_importing_persisted_torrent_entries() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let infohash = sample_info_hash(); @@ -1302,7 +1302,7 @@ mod tests { async fn it_should_allow_overwriting_a_previously_imported_persisted_torrent() { // code-review: do we want to allow this? - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let infohash = sample_info_hash(); @@ -1321,7 +1321,7 @@ mod tests { #[tokio::test] async fn it_should_now_allow_importing_a_persisted_torrent_if_it_already_exists() { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let infohash = sample_info_hash(); @@ -1353,7 +1353,7 @@ mod tests { use crate::event::sender::tests::{expect_event_sequence, MockEventSender}; use crate::event::Event; - use crate::swarms::Swarms; + use crate::swarms::Registry; use crate::tests::sample_info_hash; #[tokio::test] @@ -1374,7 +1374,7 @@ mod tests { ], ); - let swarms = Swarms::new(Some(Arc::new(event_sender_mock))); + let swarms = Registry::new(Some(Arc::new(event_sender_mock))); swarms.handle_announcement(&info_hash, &peer, None).await.unwrap(); } @@ -1398,7 +1398,7 @@ mod tests { ], ); - let swarms = Swarms::new(Some(Arc::new(event_sender_mock))); + let swarms = Registry::new(Some(Arc::new(event_sender_mock))); swarms.handle_announcement(&info_hash, &peer, None).await.unwrap(); @@ -1425,7 +1425,7 @@ mod tests { ], ); - let swarms = Swarms::new(Some(Arc::new(event_sender_mock))); + let swarms = Registry::new(Some(Arc::new(event_sender_mock))); // Add the new torrent swarms.handle_announcement(&info_hash, &peer, None).await.unwrap(); From 63f04e57ffbf27644692fd0fb4b7527415188f4c Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Thu, 29 May 2025 11:04:27 +0100 Subject: [PATCH 5/9] refactor: [#1519] extract mod coordinator --- packages/swarm-coordination-registry/src/lib.rs | 2 +- .../src/{swarm.rs => swarm/coordinator.rs} | 16 ++++++++-------- .../swarm-coordination-registry/src/swarm/mod.rs | 1 + .../swarm-coordination-registry/src/swarms.rs | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) rename packages/swarm-coordination-registry/src/{swarm.rs => swarm/coordinator.rs} (98%) create mode 100644 packages/swarm-coordination-registry/src/swarm/mod.rs diff --git a/packages/swarm-coordination-registry/src/lib.rs b/packages/swarm-coordination-registry/src/lib.rs index f3926331a..2e591f41c 100644 --- a/packages/swarm-coordination-registry/src/lib.rs +++ b/packages/swarm-coordination-registry/src/lib.rs @@ -11,7 +11,7 @@ use torrust_tracker_clock::clock; pub type Swarms = swarms::Registry; pub type SwarmHandle = Arc>; -pub type Coordinator = swarm::Coordinator; +pub type Coordinator = swarm::coordinator::Coordinator; /// Working version, for production. #[cfg(not(test))] diff --git a/packages/swarm-coordination-registry/src/swarm.rs b/packages/swarm-coordination-registry/src/swarm/coordinator.rs similarity index 98% rename from packages/swarm-coordination-registry/src/swarm.rs rename to packages/swarm-coordination-registry/src/swarm/coordinator.rs index 81e454d8b..1ddf3e60b 100644 --- a/packages/swarm-coordination-registry/src/swarm.rs +++ b/packages/swarm-coordination-registry/src/swarm/coordinator.rs @@ -326,7 +326,7 @@ mod tests { use torrust_tracker_primitives::swarm_metadata::SwarmMetadata; use torrust_tracker_primitives::DurationSinceUnixEpoch; - use crate::swarm::Coordinator; + use crate::swarm::coordinator::Coordinator; use crate::tests::sample_info_hash; #[test] @@ -553,7 +553,7 @@ mod tests { use torrust_tracker_configuration::TrackerPolicy; - use crate::swarm::tests::for_retaining_policy::{ + use crate::swarm::coordinator::tests::for_retaining_policy::{ empty_swarm, not_empty_swarm, not_empty_swarm_with_downloads, remove_peerless_torrents_policy, }; @@ -582,7 +582,7 @@ mod tests { mod when_removing_peerless_torrents_is_disabled { - use crate::swarm::tests::for_retaining_policy::{ + use crate::swarm::coordinator::tests::for_retaining_policy::{ don_not_remove_peerless_torrents_policy, empty_swarm, not_empty_swarm, }; @@ -700,7 +700,7 @@ mod tests { mod when_a_new_peer_is_added { use torrust_tracker_primitives::peer::fixture::PeerBuilder; - use crate::swarm::Coordinator; + use crate::swarm::coordinator::Coordinator; use crate::tests::sample_info_hash; #[tokio::test] @@ -747,7 +747,7 @@ mod tests { mod when_a_peer_is_removed { use torrust_tracker_primitives::peer::fixture::PeerBuilder; - use crate::swarm::Coordinator; + use crate::swarm::coordinator::Coordinator; use crate::tests::sample_info_hash; #[tokio::test] @@ -786,7 +786,7 @@ mod tests { use torrust_tracker_primitives::peer::fixture::PeerBuilder; - use crate::swarm::Coordinator; + use crate::swarm::coordinator::Coordinator; use crate::tests::sample_info_hash; #[tokio::test] @@ -824,7 +824,7 @@ mod tests { use aquatic_udp_protocol::NumberOfBytes; use torrust_tracker_primitives::peer::fixture::PeerBuilder; - use crate::swarm::Coordinator; + use crate::swarm::coordinator::Coordinator; use crate::tests::sample_info_hash; #[tokio::test] @@ -913,7 +913,7 @@ mod tests { use crate::event::sender::tests::{expect_event_sequence, MockEventSender}; use crate::event::Event; - use crate::swarm::Coordinator; + use crate::swarm::coordinator::Coordinator; use crate::tests::sample_info_hash; #[tokio::test] diff --git a/packages/swarm-coordination-registry/src/swarm/mod.rs b/packages/swarm-coordination-registry/src/swarm/mod.rs new file mode 100644 index 000000000..115b2c7c9 --- /dev/null +++ b/packages/swarm-coordination-registry/src/swarm/mod.rs @@ -0,0 +1 @@ +pub mod coordinator; diff --git a/packages/swarm-coordination-registry/src/swarms.rs b/packages/swarm-coordination-registry/src/swarms.rs index c14cb66b7..158cc88c7 100644 --- a/packages/swarm-coordination-registry/src/swarms.rs +++ b/packages/swarm-coordination-registry/src/swarms.rs @@ -11,7 +11,7 @@ use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads use crate::event::sender::Sender; use crate::event::Event; -use crate::swarm::Coordinator; +use crate::swarm::coordinator::Coordinator; use crate::SwarmHandle; #[derive(Default)] From cfc5b342180ccfa5e2388403ede3d7a33ac35af3 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Thu, 29 May 2025 11:05:25 +0100 Subject: [PATCH 6/9] refactor: [#1519] rename mod swarms to resgistry --- .../swarm-coordination-registry/src/lib.rs | 4 +-- .../src/{swarms.rs => registry.rs} | 36 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) rename packages/swarm-coordination-registry/src/{swarms.rs => registry.rs} (98%) diff --git a/packages/swarm-coordination-registry/src/lib.rs b/packages/swarm-coordination-registry/src/lib.rs index 2e591f41c..82a29b867 100644 --- a/packages/swarm-coordination-registry/src/lib.rs +++ b/packages/swarm-coordination-registry/src/lib.rs @@ -2,14 +2,14 @@ pub mod container; pub mod event; pub mod statistics; pub mod swarm; -pub mod swarms; +pub mod registry; use std::sync::Arc; use tokio::sync::Mutex; use torrust_tracker_clock::clock; -pub type Swarms = swarms::Registry; +pub type Swarms = registry::Registry; pub type SwarmHandle = Arc>; pub type Coordinator = swarm::coordinator::Coordinator; diff --git a/packages/swarm-coordination-registry/src/swarms.rs b/packages/swarm-coordination-registry/src/registry.rs similarity index 98% rename from packages/swarm-coordination-registry/src/swarms.rs rename to packages/swarm-coordination-registry/src/registry.rs index 158cc88c7..970b664ec 100644 --- a/packages/swarm-coordination-registry/src/swarms.rs +++ b/packages/swarm-coordination-registry/src/registry.rs @@ -510,7 +510,7 @@ mod tests { use aquatic_udp_protocol::PeerId; - use crate::swarms::Registry; + use crate::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; /// It generates a peer id from a number where the number is the last @@ -581,7 +581,7 @@ mod tests { use std::sync::Arc; - use crate::swarms::Registry; + use crate::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] @@ -617,8 +617,8 @@ mod tests { use torrust_tracker_primitives::peer::Peer; use torrust_tracker_primitives::DurationSinceUnixEpoch; - use crate::swarms::tests::the_swarm_repository::numeric_peer_id; - use crate::swarms::Registry; + use crate::registry::tests::the_swarm_repository::numeric_peer_id; + use crate::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] @@ -679,8 +679,8 @@ mod tests { use torrust_tracker_primitives::peer::Peer; use torrust_tracker_primitives::DurationSinceUnixEpoch; - use crate::swarms::tests::the_swarm_repository::numeric_peer_id; - use crate::swarms::Registry; + use crate::registry::tests::the_swarm_repository::numeric_peer_id; + use crate::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] @@ -757,7 +757,7 @@ mod tests { use torrust_tracker_configuration::TrackerPolicy; use torrust_tracker_primitives::DurationSinceUnixEpoch; - use crate::swarms::Registry; + use crate::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] @@ -851,7 +851,7 @@ mod tests { use torrust_tracker_primitives::peer::Peer; use torrust_tracker_primitives::swarm_metadata::SwarmMetadata; - use crate::swarms::Registry; + use crate::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; use crate::{Coordinator, SwarmHandle}; @@ -912,10 +912,10 @@ mod tests { use torrust_tracker_primitives::swarm_metadata::SwarmMetadata; - use crate::swarms::tests::the_swarm_repository::returning_torrent_entries::{ + use crate::registry::tests::the_swarm_repository::returning_torrent_entries::{ torrent_entry_info, TorrentEntryInfo, }; - use crate::swarms::Registry; + use crate::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] @@ -952,10 +952,10 @@ mod tests { use torrust_tracker_primitives::pagination::Pagination; use torrust_tracker_primitives::swarm_metadata::SwarmMetadata; - use crate::swarms::tests::the_swarm_repository::returning_torrent_entries::{ + use crate::registry::tests::the_swarm_repository::returning_torrent_entries::{ torrent_entry_info, TorrentEntryInfo, }; - use crate::swarms::Registry; + use crate::registry::Registry; use crate::tests::{ sample_info_hash_alphabetically_ordered_after_sample_info_hash_one, sample_info_hash_one, sample_peer_one, sample_peer_two, @@ -1061,7 +1061,7 @@ mod tests { use bittorrent_primitives::info_hash::fixture::gen_seeded_infohash; use torrust_tracker_primitives::swarm_metadata::AggregateActiveSwarmMetadata; - use crate::swarms::Registry; + use crate::registry::Registry; use crate::tests::{complete_peer, leecher, sample_info_hash, seeder}; // todo: refactor to use test parametrization @@ -1183,7 +1183,7 @@ mod tests { use torrust_tracker_primitives::DurationSinceUnixEpoch; - use crate::swarms::Registry; + use crate::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] @@ -1210,7 +1210,7 @@ mod tests { mod it_should_count_peers { use std::sync::Arc; - use crate::swarms::Registry; + use crate::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] @@ -1238,7 +1238,7 @@ mod tests { use torrust_tracker_primitives::swarm_metadata::SwarmMetadata; - use crate::swarms::Registry; + use crate::registry::Registry; use crate::tests::{leecher, sample_info_hash}; #[tokio::test] @@ -1277,7 +1277,7 @@ mod tests { use torrust_tracker_primitives::NumberOfDownloadsBTreeMap; - use crate::swarms::Registry; + use crate::registry::Registry; use crate::tests::{leecher, sample_info_hash}; #[tokio::test] @@ -1353,7 +1353,7 @@ mod tests { use crate::event::sender::tests::{expect_event_sequence, MockEventSender}; use crate::event::Event; - use crate::swarms::Registry; + use crate::registry::Registry; use crate::tests::sample_info_hash; #[tokio::test] From 9146681a798ce22df46e069e4ea357e6c18ce8b7 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Thu, 29 May 2025 11:08:21 +0100 Subject: [PATCH 7/9] refactor: [#1519] move mod registry --- .../swarm-coordination-registry/src/lib.rs | 3 +- .../src/swarm/mod.rs | 1 + .../src/{ => swarm}/registry.rs | 36 +++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) rename packages/swarm-coordination-registry/src/{ => swarm}/registry.rs (97%) diff --git a/packages/swarm-coordination-registry/src/lib.rs b/packages/swarm-coordination-registry/src/lib.rs index 82a29b867..bbeb5e924 100644 --- a/packages/swarm-coordination-registry/src/lib.rs +++ b/packages/swarm-coordination-registry/src/lib.rs @@ -2,14 +2,13 @@ pub mod container; pub mod event; pub mod statistics; pub mod swarm; -pub mod registry; use std::sync::Arc; use tokio::sync::Mutex; use torrust_tracker_clock::clock; -pub type Swarms = registry::Registry; +pub type Swarms = swarm::registry::Registry; pub type SwarmHandle = Arc>; pub type Coordinator = swarm::coordinator::Coordinator; diff --git a/packages/swarm-coordination-registry/src/swarm/mod.rs b/packages/swarm-coordination-registry/src/swarm/mod.rs index 115b2c7c9..925ae4948 100644 --- a/packages/swarm-coordination-registry/src/swarm/mod.rs +++ b/packages/swarm-coordination-registry/src/swarm/mod.rs @@ -1 +1,2 @@ pub mod coordinator; +pub mod registry; diff --git a/packages/swarm-coordination-registry/src/registry.rs b/packages/swarm-coordination-registry/src/swarm/registry.rs similarity index 97% rename from packages/swarm-coordination-registry/src/registry.rs rename to packages/swarm-coordination-registry/src/swarm/registry.rs index 970b664ec..30652537b 100644 --- a/packages/swarm-coordination-registry/src/registry.rs +++ b/packages/swarm-coordination-registry/src/swarm/registry.rs @@ -510,7 +510,7 @@ mod tests { use aquatic_udp_protocol::PeerId; - use crate::registry::Registry; + use crate::swarm::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; /// It generates a peer id from a number where the number is the last @@ -581,7 +581,7 @@ mod tests { use std::sync::Arc; - use crate::registry::Registry; + use crate::swarm::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] @@ -617,8 +617,8 @@ mod tests { use torrust_tracker_primitives::peer::Peer; use torrust_tracker_primitives::DurationSinceUnixEpoch; - use crate::registry::tests::the_swarm_repository::numeric_peer_id; - use crate::registry::Registry; + use crate::swarm::registry::tests::the_swarm_repository::numeric_peer_id; + use crate::swarm::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] @@ -679,8 +679,8 @@ mod tests { use torrust_tracker_primitives::peer::Peer; use torrust_tracker_primitives::DurationSinceUnixEpoch; - use crate::registry::tests::the_swarm_repository::numeric_peer_id; - use crate::registry::Registry; + use crate::swarm::registry::tests::the_swarm_repository::numeric_peer_id; + use crate::swarm::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] @@ -757,7 +757,7 @@ mod tests { use torrust_tracker_configuration::TrackerPolicy; use torrust_tracker_primitives::DurationSinceUnixEpoch; - use crate::registry::Registry; + use crate::swarm::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] @@ -851,7 +851,7 @@ mod tests { use torrust_tracker_primitives::peer::Peer; use torrust_tracker_primitives::swarm_metadata::SwarmMetadata; - use crate::registry::Registry; + use crate::swarm::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; use crate::{Coordinator, SwarmHandle}; @@ -912,10 +912,10 @@ mod tests { use torrust_tracker_primitives::swarm_metadata::SwarmMetadata; - use crate::registry::tests::the_swarm_repository::returning_torrent_entries::{ + use crate::swarm::registry::tests::the_swarm_repository::returning_torrent_entries::{ torrent_entry_info, TorrentEntryInfo, }; - use crate::registry::Registry; + use crate::swarm::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] @@ -952,10 +952,10 @@ mod tests { use torrust_tracker_primitives::pagination::Pagination; use torrust_tracker_primitives::swarm_metadata::SwarmMetadata; - use crate::registry::tests::the_swarm_repository::returning_torrent_entries::{ + use crate::swarm::registry::tests::the_swarm_repository::returning_torrent_entries::{ torrent_entry_info, TorrentEntryInfo, }; - use crate::registry::Registry; + use crate::swarm::registry::Registry; use crate::tests::{ sample_info_hash_alphabetically_ordered_after_sample_info_hash_one, sample_info_hash_one, sample_peer_one, sample_peer_two, @@ -1061,7 +1061,7 @@ mod tests { use bittorrent_primitives::info_hash::fixture::gen_seeded_infohash; use torrust_tracker_primitives::swarm_metadata::AggregateActiveSwarmMetadata; - use crate::registry::Registry; + use crate::swarm::registry::Registry; use crate::tests::{complete_peer, leecher, sample_info_hash, seeder}; // todo: refactor to use test parametrization @@ -1183,7 +1183,7 @@ mod tests { use torrust_tracker_primitives::DurationSinceUnixEpoch; - use crate::registry::Registry; + use crate::swarm::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] @@ -1210,7 +1210,7 @@ mod tests { mod it_should_count_peers { use std::sync::Arc; - use crate::registry::Registry; + use crate::swarm::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; #[tokio::test] @@ -1238,7 +1238,7 @@ mod tests { use torrust_tracker_primitives::swarm_metadata::SwarmMetadata; - use crate::registry::Registry; + use crate::swarm::registry::Registry; use crate::tests::{leecher, sample_info_hash}; #[tokio::test] @@ -1277,7 +1277,7 @@ mod tests { use torrust_tracker_primitives::NumberOfDownloadsBTreeMap; - use crate::registry::Registry; + use crate::swarm::registry::Registry; use crate::tests::{leecher, sample_info_hash}; #[tokio::test] @@ -1353,7 +1353,7 @@ mod tests { use crate::event::sender::tests::{expect_event_sequence, MockEventSender}; use crate::event::Event; - use crate::registry::Registry; + use crate::swarm::registry::Registry; use crate::tests::sample_info_hash; #[tokio::test] From 290c9eb491373ada84e9b3b2baa9bb596cbaffcc Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Thu, 29 May 2025 11:09:02 +0100 Subject: [PATCH 8/9] refactor: [#1519] rename Swarms to Registry --- packages/swarm-coordination-registry/src/container.rs | 6 +++--- packages/swarm-coordination-registry/src/lib.rs | 2 +- .../src/statistics/activity_metrics_updater.rs | 6 +++--- packages/tracker-core/src/torrent/manager.rs | 4 ++-- packages/tracker-core/src/torrent/repository/in_memory.rs | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/swarm-coordination-registry/src/container.rs b/packages/swarm-coordination-registry/src/container.rs index d185180b1..1b56b3d4b 100644 --- a/packages/swarm-coordination-registry/src/container.rs +++ b/packages/swarm-coordination-registry/src/container.rs @@ -6,10 +6,10 @@ use crate::event::bus::EventBus; use crate::event::sender::Broadcaster; use crate::event::{self}; use crate::statistics::repository::Repository; -use crate::{statistics, Swarms}; +use crate::{statistics, Registry}; pub struct TorrentRepositoryContainer { - pub swarms: Arc, + pub swarms: Arc, pub event_bus: Arc, pub stats_event_sender: event::sender::Sender, pub stats_repository: Arc, @@ -26,7 +26,7 @@ impl TorrentRepositoryContainer { let stats_event_sender = event_bus.sender(); - let swarms = Arc::new(Swarms::new(stats_event_sender.clone())); + let swarms = Arc::new(Registry::new(stats_event_sender.clone())); Self { swarms, diff --git a/packages/swarm-coordination-registry/src/lib.rs b/packages/swarm-coordination-registry/src/lib.rs index bbeb5e924..0382c14fa 100644 --- a/packages/swarm-coordination-registry/src/lib.rs +++ b/packages/swarm-coordination-registry/src/lib.rs @@ -8,7 +8,7 @@ use std::sync::Arc; use tokio::sync::Mutex; use torrust_tracker_clock::clock; -pub type Swarms = swarm::registry::Registry; +pub type Registry = swarm::registry::Registry; pub type SwarmHandle = Arc>; pub type Coordinator = swarm::coordinator::Coordinator; diff --git a/packages/swarm-coordination-registry/src/statistics/activity_metrics_updater.rs b/packages/swarm-coordination-registry/src/statistics/activity_metrics_updater.rs index 2dfa5fb4e..016e230ec 100644 --- a/packages/swarm-coordination-registry/src/statistics/activity_metrics_updater.rs +++ b/packages/swarm-coordination-registry/src/statistics/activity_metrics_updater.rs @@ -11,12 +11,12 @@ use tracing::instrument; use super::repository::Repository; use crate::statistics::{TORRENT_REPOSITORY_PEERS_INACTIVE_TOTAL, TORRENT_REPOSITORY_TORRENTS_INACTIVE_TOTAL}; -use crate::{CurrentClock, Swarms}; +use crate::{CurrentClock, Registry}; #[must_use] #[instrument(skip(swarms, stats_repository))] pub fn start_job( - swarms: &Arc, + swarms: &Arc, stats_repository: &Arc, inactivity_cutoff: DurationSinceUnixEpoch, ) -> JoinHandle<()> { @@ -51,7 +51,7 @@ pub fn start_job( async fn update_activity_metrics( interval_in_secs: u64, - swarms: &Arc, + swarms: &Arc, stats_repository: &Arc, inactivity_cutoff: DurationSinceUnixEpoch, ) { diff --git a/packages/tracker-core/src/torrent/manager.rs b/packages/tracker-core/src/torrent/manager.rs index cbdf01193..5acc27980 100644 --- a/packages/tracker-core/src/torrent/manager.rs +++ b/packages/tracker-core/src/torrent/manager.rs @@ -148,7 +148,7 @@ mod tests { use std::sync::Arc; use torrust_tracker_configuration::Core; - use torrust_tracker_swarm_coordination_registry::Swarms; + use torrust_tracker_swarm_coordination_registry::Registry; use super::{DatabaseDownloadsMetricRepository, TorrentsManager}; use crate::databases::setup::initialize_database; @@ -167,7 +167,7 @@ mod tests { } fn initialize_torrents_manager_with(config: Core) -> (Arc, Arc) { - let swarms = Arc::new(Swarms::default()); + let swarms = Arc::new(Registry::default()); let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::new(swarms)); let database = initialize_database(&config); let database_persistent_torrent_repository = Arc::new(DatabaseDownloadsMetricRepository::new(&database)); diff --git a/packages/tracker-core/src/torrent/repository/in_memory.rs b/packages/tracker-core/src/torrent/repository/in_memory.rs index 47b34ad26..ead05a32d 100644 --- a/packages/tracker-core/src/torrent/repository/in_memory.rs +++ b/packages/tracker-core/src/torrent/repository/in_memory.rs @@ -7,7 +7,7 @@ use torrust_tracker_configuration::{TrackerPolicy, TORRENT_PEERS_LIMIT}; use torrust_tracker_primitives::pagination::Pagination; use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata}; use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads, NumberOfDownloadsBTreeMap}; -use torrust_tracker_swarm_coordination_registry::{SwarmHandle, Swarms}; +use torrust_tracker_swarm_coordination_registry::{Registry, SwarmHandle}; /// In-memory repository for torrent entries. /// @@ -21,12 +21,12 @@ use torrust_tracker_swarm_coordination_registry::{SwarmHandle, Swarms}; #[derive(Default)] pub struct InMemoryTorrentRepository { /// The underlying in-memory data structure that stores swarms data. - swarms: Arc, + swarms: Arc, } impl InMemoryTorrentRepository { #[must_use] - pub fn new(swarms: Arc) -> Self { + pub fn new(swarms: Arc) -> Self { Self { swarms } } From bbe974de3537246dad431826fd3dc8764dd44375 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Thu, 29 May 2025 11:11:23 +0100 Subject: [PATCH 9/9] refactor: [#1519] rename SwarmHandle to CoordinatorHandle --- .../swarm-coordination-registry/src/lib.rs | 2 +- .../src/swarm/registry.rs | 18 +++++++++--------- .../src/torrent/repository/in_memory.rs | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/swarm-coordination-registry/src/lib.rs b/packages/swarm-coordination-registry/src/lib.rs index 0382c14fa..fc7996817 100644 --- a/packages/swarm-coordination-registry/src/lib.rs +++ b/packages/swarm-coordination-registry/src/lib.rs @@ -9,7 +9,7 @@ use tokio::sync::Mutex; use torrust_tracker_clock::clock; pub type Registry = swarm::registry::Registry; -pub type SwarmHandle = Arc>; +pub type CoordinatorHandle = Arc>; pub type Coordinator = swarm::coordinator::Coordinator; /// Working version, for production. diff --git a/packages/swarm-coordination-registry/src/swarm/registry.rs b/packages/swarm-coordination-registry/src/swarm/registry.rs index 30652537b..c8e98f307 100644 --- a/packages/swarm-coordination-registry/src/swarm/registry.rs +++ b/packages/swarm-coordination-registry/src/swarm/registry.rs @@ -12,11 +12,11 @@ use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads use crate::event::sender::Sender; use crate::event::Event; use crate::swarm::coordinator::Coordinator; -use crate::SwarmHandle; +use crate::CoordinatorHandle; #[derive(Default)] pub struct Registry { - swarms: SkipMap, + swarms: SkipMap, event_sender: Sender, } @@ -60,7 +60,7 @@ impl Registry { let number_of_downloads = opt_persistent_torrent.unwrap_or_default(); let new_swarm_handle = - SwarmHandle::new(Coordinator::new(info_hash, number_of_downloads, self.event_sender.clone()).into()); + CoordinatorHandle::new(Coordinator::new(info_hash, number_of_downloads, self.event_sender.clone()).into()); let new_swarm_handle = self.swarms.get_or_insert(*info_hash, new_swarm_handle); @@ -107,7 +107,7 @@ impl Registry { /// /// An `Option` containing the removed torrent entry if it existed. #[must_use] - pub async fn remove(&self, key: &InfoHash) -> Option { + pub async fn remove(&self, key: &InfoHash) -> Option { let swarm_handle = self.swarms.remove(key).map(|entry| entry.value().clone()); if let Some(event_sender) = self.event_sender.as_deref() { @@ -123,7 +123,7 @@ impl Registry { /// /// An `Option` containing the tracked torrent handle if found. #[must_use] - pub fn get(&self, key: &InfoHash) -> Option { + pub fn get(&self, key: &InfoHash) -> Option { let maybe_entry = self.swarms.get(key); maybe_entry.map(|entry| entry.value().clone()) } @@ -138,7 +138,7 @@ impl Registry { /// /// A vector of `(InfoHash, TorrentEntry)` tuples. #[must_use] - pub fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, SwarmHandle)> { + pub fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, CoordinatorHandle)> { match pagination { Some(pagination) => self .swarms @@ -366,7 +366,7 @@ impl Registry { continue; } - let entry = SwarmHandle::new(Coordinator::new(info_hash, *completed, self.event_sender.clone()).into()); + let entry = CoordinatorHandle::new(Coordinator::new(info_hash, *completed, self.event_sender.clone()).into()); // Since SkipMap is lock-free the torrent could have been inserted // after checking if it exists. @@ -853,7 +853,7 @@ mod tests { use crate::swarm::registry::Registry; use crate::tests::{sample_info_hash, sample_peer}; - use crate::{Coordinator, SwarmHandle}; + use crate::{Coordinator, CoordinatorHandle}; /// `TorrentEntry` data is not directly accessible. It's only /// accessible through the trait methods. We need this temporary @@ -865,7 +865,7 @@ mod tests { number_of_peers: usize, } - async fn torrent_entry_info(swarm_handle: SwarmHandle) -> TorrentEntryInfo { + async fn torrent_entry_info(swarm_handle: CoordinatorHandle) -> TorrentEntryInfo { let torrent_guard = swarm_handle.lock().await; torrent_guard.clone().into() } diff --git a/packages/tracker-core/src/torrent/repository/in_memory.rs b/packages/tracker-core/src/torrent/repository/in_memory.rs index ead05a32d..e50a82933 100644 --- a/packages/tracker-core/src/torrent/repository/in_memory.rs +++ b/packages/tracker-core/src/torrent/repository/in_memory.rs @@ -7,7 +7,7 @@ use torrust_tracker_configuration::{TrackerPolicy, TORRENT_PEERS_LIMIT}; use torrust_tracker_primitives::pagination::Pagination; use torrust_tracker_primitives::swarm_metadata::{AggregateActiveSwarmMetadata, SwarmMetadata}; use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch, NumberOfDownloads, NumberOfDownloadsBTreeMap}; -use torrust_tracker_swarm_coordination_registry::{Registry, SwarmHandle}; +use torrust_tracker_swarm_coordination_registry::{CoordinatorHandle, Registry}; /// In-memory repository for torrent entries. /// @@ -110,7 +110,7 @@ impl InMemoryTorrentRepository { /// /// An `Option` containing the torrent entry if found. #[must_use] - pub(crate) fn get(&self, key: &InfoHash) -> Option { + pub(crate) fn get(&self, key: &InfoHash) -> Option { self.swarms.get(key) } @@ -128,7 +128,7 @@ impl InMemoryTorrentRepository { /// /// A vector of `(InfoHash, TorrentEntry)` tuples. #[must_use] - pub(crate) fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, SwarmHandle)> { + pub(crate) fn get_paginated(&self, pagination: Option<&Pagination>) -> Vec<(InfoHash, CoordinatorHandle)> { self.swarms.get_paginated(pagination) }