-
Notifications
You must be signed in to change notification settings - Fork 51
Cleanup Announce Response #563
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
Merged
josecelano
merged 4 commits into
torrust:develop
from
da2ce7:20240101_cleanup_response_announce
Jan 12, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,7 @@ | |
| "Hydranode", | ||
| "Icelake", | ||
| "imdl", | ||
| "impls", | ||
| "incompletei", | ||
| "infohash", | ||
| "infohashes", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,12 +98,12 @@ | |
| //! | ||
| //! ```rust,no_run | ||
| //! use torrust_tracker::core::peer::Peer; | ||
| //! use torrust_tracker_configuration::AnnouncePolicy; | ||
| //! | ||
| //! pub struct AnnounceData { | ||
| //! pub peers: Vec<Peer>, | ||
| //! pub swarm_stats: SwarmStats, | ||
| //! pub interval: u32, // Option `announce_interval` from core tracker configuration | ||
| //! pub interval_min: u32, // Option `min_announce_interval` from core tracker configuration | ||
| //! pub policy: AnnouncePolicy, // the tracker announce policy. | ||
| //! } | ||
| //! | ||
| //! pub struct SwarmStats { | ||
|
|
@@ -445,9 +445,10 @@ use std::panic::Location; | |
| use std::sync::Arc; | ||
| use std::time::Duration; | ||
|
|
||
| use derive_more::Constructor; | ||
| use futures::future::join_all; | ||
| use tokio::sync::mpsc::error::SendError; | ||
| use torrust_tracker_configuration::Configuration; | ||
| use torrust_tracker_configuration::{AnnouncePolicy, Configuration}; | ||
| use torrust_tracker_primitives::TrackerMode; | ||
|
|
||
| use self::auth::Key; | ||
|
|
@@ -487,7 +488,7 @@ pub struct Tracker { | |
| /// Structure that holds general `Tracker` torrents metrics. | ||
| /// | ||
| /// Metrics are aggregate values for all torrents. | ||
| #[derive(Debug, PartialEq, Default)] | ||
| #[derive(Copy, Clone, Debug, PartialEq, Default)] | ||
| pub struct TorrentsMetrics { | ||
| /// Total number of seeders for all torrents | ||
| pub seeders: u64, | ||
|
|
@@ -500,20 +501,14 @@ pub struct TorrentsMetrics { | |
| } | ||
|
|
||
| /// Structure that holds the data returned by the `announce` request. | ||
| #[derive(Debug, PartialEq, Default)] | ||
| #[derive(Clone, Debug, PartialEq, Constructor, Default)] | ||
| pub struct AnnounceData { | ||
| /// The list of peers that are downloading the same torrent. | ||
| /// It excludes the peer that made the request. | ||
| pub peers: Vec<Peer>, | ||
| /// Swarm statistics | ||
| pub swarm_stats: SwarmStats, | ||
| /// The interval in seconds that the client should wait between sending | ||
| /// regular requests to the tracker. | ||
| /// Refer to [`announce_interval`](torrust_tracker_configuration::Configuration::announce_interval). | ||
| pub interval: u32, | ||
| /// The minimum announce interval in seconds that the client should wait. | ||
| /// Refer to [`min_announce_interval`](torrust_tracker_configuration::Configuration::min_announce_interval). | ||
| pub interval_min: u32, | ||
| pub stats: SwarmStats, | ||
| pub policy: AnnouncePolicy, | ||
|
Comment on lines
+510
to
+511
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏼 |
||
| } | ||
|
|
||
| /// Structure that holds the data returned by the `scrape` request. | ||
|
|
@@ -628,11 +623,12 @@ impl Tracker { | |
|
|
||
| let peers = self.get_torrent_peers_for_peer(info_hash, peer).await; | ||
|
|
||
| let policy = AnnouncePolicy::new(self.config.announce_interval, self.config.min_announce_interval); | ||
|
|
||
| AnnounceData { | ||
| peers, | ||
| swarm_stats, | ||
| interval: self.config.announce_interval, | ||
| interval_min: self.config.min_announce_interval, | ||
| stats: swarm_stats, | ||
| policy, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -732,7 +728,7 @@ impl Tracker { | |
| let (stats, stats_updated) = self.torrents.update_torrent_with_peer_and_get_stats(info_hash, peer).await; | ||
|
|
||
| if self.config.persistent_torrent_completed_stat && stats_updated { | ||
| let completed = stats.completed; | ||
| let completed = stats.downloaded; | ||
| let info_hash = *info_hash; | ||
|
|
||
| drop(self.database.save_persistent_torrent(&info_hash, completed).await); | ||
|
|
@@ -1390,7 +1386,7 @@ mod tests { | |
|
|
||
| let announce_data = tracker.announce(&sample_info_hash(), &mut peer, &peer_ip()).await; | ||
|
|
||
| assert_eq!(announce_data.swarm_stats.seeders, 1); | ||
| assert_eq!(announce_data.stats.complete, 1); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
|
|
@@ -1401,7 +1397,7 @@ mod tests { | |
|
|
||
| let announce_data = tracker.announce(&sample_info_hash(), &mut peer, &peer_ip()).await; | ||
|
|
||
| assert_eq!(announce_data.swarm_stats.leechers, 1); | ||
| assert_eq!(announce_data.stats.incomplete, 1); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
|
|
@@ -1415,7 +1411,7 @@ mod tests { | |
| let mut completed_peer = completed_peer(); | ||
| let announce_data = tracker.announce(&sample_info_hash(), &mut completed_peer, &peer_ip()).await; | ||
|
|
||
| assert_eq!(announce_data.swarm_stats.completed, 1); | ||
| assert_eq!(announce_data.stats.downloaded, 1); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -1739,11 +1735,11 @@ mod tests { | |
|
|
||
| peer.event = AnnounceEvent::Started; | ||
| let swarm_stats = tracker.update_torrent_with_peer_and_get_stats(&info_hash, &peer).await; | ||
| assert_eq!(swarm_stats.completed, 0); | ||
| assert_eq!(swarm_stats.downloaded, 0); | ||
|
|
||
| peer.event = AnnounceEvent::Completed; | ||
| let swarm_stats = tracker.update_torrent_with_peer_and_get_stats(&info_hash, &peer).await; | ||
| assert_eq!(swarm_stats.completed, 1); | ||
| assert_eq!(swarm_stats.downloaded, 1); | ||
|
|
||
| // Remove the newly updated torrent from memory | ||
| tracker.torrents.get_torrents_mut().await.remove(&info_hash); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @da2ce7 I see you have renamed stats fields.
SwarmMetadata: https://github.com/torrust/torrust-tracker/blob/develop/src/core/torrent/mod.rs#L55-L67SwarmStats: https://github.com/torrust/torrust-tracker/blob/develop/src/core/torrent/mod.rs#L76-L87SwarmMetadatacontains the names defined in the BRP 48. AndSwarmStatsthe names we were using in the Tracker.