Skip to content

Commit 236c3bf

Browse files
committed
Merge #1291: Refactor packages: extract http-tracker-core package
8958609 refactor: [#1281] extract http-tracker-core package (Jose Celano) Pull request description: Refactor packages: extract `http-tracker-core` package ACKs for top commit: josecelano: ACK 8958609 Tree-SHA512: 048e7c076f3a21c773c31f3f2770e06685d685a9034c0309e4de3ec9094f64b03a023583fbc6b2d386f4fa50c0704ddceea2cb9b9e25bf957c3d7a55c5a15bb5
2 parents 321ce19 + 8958609 commit 236c3bf

File tree

29 files changed

+836
-119
lines changed

29 files changed

+836
-119
lines changed

.github/workflows/deployment.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ jobs:
5656
CARGO_REGISTRY_TOKEN: "${{ secrets.TORRUST_UPDATE_CARGO_REGISTRY_TOKEN }}"
5757
run: |
5858
cargo publish -p bittorrent-http-protocol
59+
cargo publish -p bittorrent-http-tracker-core
5960
cargo publish -p bittorrent-tracker-client
6061
cargo publish -p bittorrent-tracker-core
6162
cargo publish -p bittorrent-udp-protocol

Cargo.lock

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

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ axum-client-ip = "0"
4040
axum-extra = { version = "0", features = ["query"] }
4141
axum-server = { version = "0", features = ["tls-rustls-no-provider"] }
4242
bittorrent-http-protocol = { version = "3.0.0-develop", path = "packages/http-protocol" }
43+
bittorrent-http-tracker-core = { version = "3.0.0-develop", path = "packages/http-tracker-core" }
4344
bittorrent-primitives = "0.1.0"
4445
bittorrent-tracker-client = { version = "3.0.0-develop", path = "packages/tracker-client" }
4546
bittorrent-tracker-core = { version = "3.0.0-develop", path = "packages/tracker-core" }

packages/http-tracker-core/Cargo.toml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[package]
2+
authors.workspace = true
3+
description = "A library with the core functionality needed to implement a BitTorrent HTTP tracker."
4+
documentation.workspace = true
5+
edition.workspace = true
6+
homepage.workspace = true
7+
keywords = ["api", "bittorrent", "core", "library", "tracker"]
8+
license.workspace = true
9+
name = "bittorrent-http-tracker-core"
10+
publish.workspace = true
11+
readme = "README.md"
12+
repository.workspace = true
13+
rust-version.workspace = true
14+
version.workspace = true
15+
16+
[dependencies]
17+
aquatic_udp_protocol = "0"
18+
bittorrent-http-protocol = { version = "3.0.0-develop", path = "../http-protocol" }
19+
bittorrent-primitives = "0.1.0"
20+
bittorrent-tracker-core = { version = "3.0.0-develop", path = "../tracker-core" }
21+
futures = "0"
22+
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
23+
torrust-tracker-configuration = { version = "3.0.0-develop", path = "../configuration" }
24+
torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" }
25+
tracing = "0"
26+
27+
[dev-dependencies]
28+
mockall = "0"
29+
torrust-tracker-test-helpers = { version = "3.0.0-develop", path = "../test-helpers" }

packages/http-tracker-core/LICENSE

+661
Large diffs are not rendered by default.

packages/http-tracker-core/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# BitTorrent HTTP Tracker Core library
2+
3+
A library with the core functionality needed to implement a BitTorrent HTTP tracker.
4+
5+
You usually don’t need to use this library directly. Instead, you should use the [Torrust Tracker](https://github.com/torrust/torrust-tracker). If you want to build your own tracker, you can use this library as the core functionality.
6+
7+
> **Disclaimer**: This library is actively under development. We’re currently extracting and refining common types from the[Torrust Tracker](https://github.com/torrust/torrust-tracker) to make them available to the BitTorrent community in Rust. While these types are functional, they are not yet ready for use in production or third-party projects.
8+
9+
## Documentation
10+
11+
[Crate documentation](https://docs.rs/bittorrent-http-tracker-core).
12+
13+
## License
14+
15+
The project is licensed under the terms of the [GNU AFFERO GENERAL PUBLIC LICENSE](./LICENSE).

packages/http-tracker-core/src/lib.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
pub mod services;
2+
pub mod statistics;
3+
4+
#[cfg(test)]
5+
pub(crate) mod tests {
6+
use bittorrent_primitives::info_hash::InfoHash;
7+
8+
/// # Panics
9+
///
10+
/// Will panic if the string representation of the info hash is not a valid info hash.
11+
#[must_use]
12+
pub fn sample_info_hash() -> InfoHash {
13+
"3b245504cf5f11bbdbe1201cea6a6bf45aee1bc0" // DevSkim: ignore DS173237
14+
.parse::<InfoHash>()
15+
.expect("String should be a valid info hash")
16+
}
17+
}

src/packages/http_tracker_core/services/announce.rs packages/http-tracker-core/src/services/announce.rs

+19-20
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use bittorrent_tracker_core::whitelist;
2121
use torrust_tracker_configuration::Core;
2222
use torrust_tracker_primitives::core::AnnounceData;
2323

24-
use crate::packages::http_tracker_core;
24+
use crate::statistics;
2525

2626
/// The HTTP tracker `announce` service.
2727
///
@@ -46,7 +46,7 @@ pub async fn handle_announce(
4646
announce_handler: &Arc<AnnounceHandler>,
4747
authentication_service: &Arc<AuthenticationService>,
4848
whitelist_authorization: &Arc<whitelist::authorization::WhitelistAuthorization>,
49-
opt_http_stats_event_sender: &Arc<Option<Box<dyn http_tracker_core::statistics::event::sender::Sender>>>,
49+
opt_http_stats_event_sender: &Arc<Option<Box<dyn statistics::event::sender::Sender>>>,
5050
announce_request: &Announce,
5151
client_ip_sources: &ClientIpSources,
5252
maybe_key: Option<Key>,
@@ -95,12 +95,12 @@ pub async fn handle_announce(
9595
match original_peer_ip {
9696
IpAddr::V4(_) => {
9797
http_stats_event_sender
98-
.send_event(http_tracker_core::statistics::event::Event::Tcp4Announce)
98+
.send_event(statistics::event::Event::Tcp4Announce)
9999
.await;
100100
}
101101
IpAddr::V6(_) => {
102102
http_stats_event_sender
103-
.send_event(http_tracker_core::statistics::event::Event::Tcp6Announce)
103+
.send_event(statistics::event::Event::Tcp6Announce)
104104
.await;
105105
}
106106
}
@@ -138,7 +138,7 @@ mod tests {
138138
}
139139

140140
struct CoreHttpTrackerServices {
141-
pub http_stats_event_sender: Arc<Option<Box<dyn http_tracker_core::statistics::event::sender::Sender>>>,
141+
pub http_stats_event_sender: Arc<Option<Box<dyn statistics::event::sender::Sender>>>,
142142
}
143143

144144
fn initialize_core_tracker_services() -> (CoreTrackerServices, CoreHttpTrackerServices) {
@@ -163,8 +163,7 @@ mod tests {
163163
));
164164

165165
// HTTP stats
166-
let (http_stats_event_sender, http_stats_repository) =
167-
http_tracker_core::statistics::setup::factory(config.core.tracker_usage_statistics);
166+
let (http_stats_event_sender, http_stats_repository) = statistics::setup::factory(config.core.tracker_usage_statistics);
168167
let http_stats_event_sender = Arc::new(http_stats_event_sender);
169168
let _http_stats_repository = Arc::new(http_stats_repository);
170169

@@ -229,13 +228,13 @@ mod tests {
229228
use mockall::mock;
230229
use tokio::sync::mpsc::error::SendError;
231230

232-
use crate::packages::http_tracker_core;
233-
use crate::servers::http::test_helpers::tests::sample_info_hash;
231+
use crate::statistics;
232+
use crate::tests::sample_info_hash;
234233

235234
mock! {
236235
HttpStatsEventSender {}
237-
impl http_tracker_core::statistics::event::sender::Sender for HttpStatsEventSender {
238-
fn send_event(&self, event: http_tracker_core::statistics::event::Event) -> BoxFuture<'static,Option<Result<(),SendError<http_tracker_core::statistics::event::Event> > > > ;
236+
impl statistics::event::sender::Sender for HttpStatsEventSender {
237+
fn send_event(&self, event: statistics::event::Event) -> BoxFuture<'static,Option<Result<(),SendError<statistics::event::Event> > > > ;
239238
}
240239
}
241240

@@ -252,12 +251,12 @@ mod tests {
252251
use torrust_tracker_test_helpers::configuration;
253252

254253
use super::{sample_peer_using_ipv4, sample_peer_using_ipv6};
255-
use crate::packages::http_tracker_core;
256-
use crate::packages::http_tracker_core::services::announce::handle_announce;
257-
use crate::packages::http_tracker_core::services::announce::tests::{
254+
use crate::services::announce::handle_announce;
255+
use crate::services::announce::tests::{
258256
initialize_core_tracker_services, initialize_core_tracker_services_with_config, sample_announce_request_for_peer,
259257
sample_peer, MockHttpStatsEventSender,
260258
};
259+
use crate::statistics;
261260

262261
#[tokio::test]
263262
async fn it_should_return_the_announce_data() {
@@ -298,10 +297,10 @@ mod tests {
298297
let mut http_stats_event_sender_mock = MockHttpStatsEventSender::new();
299298
http_stats_event_sender_mock
300299
.expect_send_event()
301-
.with(eq(http_tracker_core::statistics::event::Event::Tcp4Announce))
300+
.with(eq(statistics::event::Event::Tcp4Announce))
302301
.times(1)
303302
.returning(|_| Box::pin(future::ready(Some(Ok(())))));
304-
let http_stats_event_sender: Arc<Option<Box<dyn http_tracker_core::statistics::event::sender::Sender>>> =
303+
let http_stats_event_sender: Arc<Option<Box<dyn statistics::event::sender::Sender>>> =
305304
Arc::new(Some(Box::new(http_stats_event_sender_mock)));
306305

307306
let (core_tracker_services, mut core_http_tracker_services) = initialize_core_tracker_services();
@@ -349,10 +348,10 @@ mod tests {
349348
let mut http_stats_event_sender_mock = MockHttpStatsEventSender::new();
350349
http_stats_event_sender_mock
351350
.expect_send_event()
352-
.with(eq(http_tracker_core::statistics::event::Event::Tcp4Announce))
351+
.with(eq(statistics::event::Event::Tcp4Announce))
353352
.times(1)
354353
.returning(|_| Box::pin(future::ready(Some(Ok(())))));
355-
let http_stats_event_sender: Arc<Option<Box<dyn http_tracker_core::statistics::event::sender::Sender>>> =
354+
let http_stats_event_sender: Arc<Option<Box<dyn statistics::event::sender::Sender>>> =
356355
Arc::new(Some(Box::new(http_stats_event_sender_mock)));
357356

358357
let (core_tracker_services, mut core_http_tracker_services) =
@@ -383,10 +382,10 @@ mod tests {
383382
let mut http_stats_event_sender_mock = MockHttpStatsEventSender::new();
384383
http_stats_event_sender_mock
385384
.expect_send_event()
386-
.with(eq(http_tracker_core::statistics::event::Event::Tcp6Announce))
385+
.with(eq(statistics::event::Event::Tcp6Announce))
387386
.times(1)
388387
.returning(|_| Box::pin(future::ready(Some(Ok(())))));
389-
let http_stats_event_sender: Arc<Option<Box<dyn http_tracker_core::statistics::event::sender::Sender>>> =
388+
let http_stats_event_sender: Arc<Option<Box<dyn statistics::event::sender::Sender>>> =
390389
Arc::new(Some(Box::new(http_stats_event_sender_mock)));
391390

392391
let (core_tracker_services, mut core_http_tracker_services) = initialize_core_tracker_services();

0 commit comments

Comments
 (0)