Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul core Tracker: review whitelist functionality (part 2) #1274

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: [#1270] extract fn to new package udp-protocol
josecelano committed Feb 17, 2025

Verified

This commit was signed with the committer’s verified signature.
josecelano Jose Celano
commit dbee7ad3a103624a47f5b3b917961d1741a5cd4d
1 change: 1 addition & 0 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@ jobs:
cargo publish -p bittorrent-http-protocol
cargo publish -p bittorrent-tracker-client
cargo publish -p bittorrent-tracker-core
cargo publish -p bittorrent-udp-protocol
cargo publish -p torrust-tracker
cargo publish -p torrust-tracker-api-client
cargo publish -p torrust-tracker-client
10 changes: 10 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ bittorrent-http-protocol = { version = "3.0.0-develop", path = "packages/http-pr
bittorrent-primitives = "0.1.0"
bittorrent-tracker-client = { version = "3.0.0-develop", path = "packages/tracker-client" }
bittorrent-tracker-core = { version = "3.0.0-develop", path = "packages/tracker-core" }
bittorrent-udp-protocol = { version = "3.0.0-develop", path = "packages/udp-protocol" }
bloom = "0.3.2"
blowfish = "0"
camino = { version = "1", features = ["serde", "serde1"] }
20 changes: 20 additions & 0 deletions packages/udp-protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
description = "A library with the primitive types and functions for the BitTorrent UDP tracker protocol."
keywords = ["bittorrent", "library", "primitives", "udp"]
name = "bittorrent-udp-protocol"
readme = "README.md"

authors.workspace = true
documentation.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
publish.workspace = true
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[dependencies]
aquatic_udp_protocol = "0"
torrust-tracker-clock = { version = "3.0.0-develop", path = "../clock" }
torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" }
661 changes: 661 additions & 0 deletions packages/udp-protocol/LICENSE

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions packages/udp-protocol/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# BitTorrent UDP Tracker Protocol

A library with the primitive types and functions used by BitTorrent UDP trackers.

## Documentation

[Crate documentation](https://docs.rs/bittorrent-udp-protocol).

## License

The project is licensed under the terms of the [GNU AFFERO GENERAL PUBLIC LICENSE](./LICENSE).
15 changes: 15 additions & 0 deletions packages/udp-protocol/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! Primitive types and functions for `BitTorrent` UDP trackers.
pub mod peer_builder;

use torrust_tracker_clock::clock;

/// This code needs to be copied into each crate.
/// Working version, for production.
#[cfg(not(test))]
#[allow(dead_code)]
pub(crate) type CurrentClock = clock::Working;

/// Stopped version, for testing.
#[cfg(test)]
#[allow(dead_code)]
pub(crate) type CurrentClock = clock::Stopped;
File renamed without changes.
1 change: 0 additions & 1 deletion src/packages/udp_tracker_core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod peer_builder;
pub mod services;
pub mod statistics;
3 changes: 2 additions & 1 deletion src/packages/udp_tracker_core/services/announce.rs
Original file line number Diff line number Diff line change
@@ -15,10 +15,11 @@ use bittorrent_primitives::info_hash::InfoHash;
use bittorrent_tracker_core::announce_handler::{AnnounceHandler, PeersWanted};
use bittorrent_tracker_core::error::AnnounceError;
use bittorrent_tracker_core::whitelist;
use bittorrent_udp_protocol::peer_builder;
use torrust_tracker_primitives::core::AnnounceData;
use torrust_tracker_primitives::peer;

use crate::packages::udp_tracker_core::{self, peer_builder};
use crate::packages::udp_tracker_core::{self};

/// It handles the `Announce` request.
///
3 changes: 3 additions & 0 deletions src/servers/udp/handlers/announce.rs
Original file line number Diff line number Diff line change
@@ -261,6 +261,7 @@ mod tests {
let expected_peer = TorrentPeerBuilder::new()
.with_peer_id(peer_id)
.with_peer_address(SocketAddr::new(IpAddr::V4(client_ip), client_port))
.updated_on(peers[0].updated)
.into();

assert_eq!(peers[0], Arc::new(expected_peer));
@@ -495,6 +496,7 @@ mod tests {
let expected_peer = TorrentPeerBuilder::new()
.with_peer_id(peer_id)
.with_peer_address(SocketAddr::new(external_ip_in_tracker_configuration, client_port))
.updated_on(peers[0].updated)
.into();

assert_eq!(peers[0], Arc::new(expected_peer));
@@ -567,6 +569,7 @@ mod tests {
let expected_peer = TorrentPeerBuilder::new()
.with_peer_id(peer_id)
.with_peer_address(SocketAddr::new(IpAddr::V6(client_ip_v6), client_port))
.updated_on(peers[0].updated)
.into();

assert_eq!(peers[0], Arc::new(expected_peer));
8 changes: 7 additions & 1 deletion src/servers/udp/handlers/mod.rs
Original file line number Diff line number Diff line change
@@ -196,7 +196,7 @@ pub(crate) mod tests {
use tokio::sync::mpsc::error::SendError;
use torrust_tracker_clock::clock::Time;
use torrust_tracker_configuration::{Configuration, Core};
use torrust_tracker_primitives::peer;
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch};
use torrust_tracker_test_helpers::configuration;

use super::gen_remote_fingerprint;
@@ -330,6 +330,12 @@ pub(crate) mod tests {
self
}

#[must_use]
pub fn updated_on(mut self, updated: DurationSinceUnixEpoch) -> Self {
self.peer.updated = updated;
self
}

#[must_use]
pub fn into(self) -> peer::Peer {
self.peer