You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//! `completed` | 20 | The number of peers that have ever completed downloading the torrent associated to this entry. See [`Entry`](torrust_tracker_torrent_repository::entry::Entry) for more information.
//! This module defines the primary data structures used to store and manage
4
+
//! swarm data within the tracker. In `BitTorrent` terminology, a "swarm" is
5
+
//! the collection of peers that are sharing or downloading a given torrent.
4
6
//!
5
-
//! - A torrent [`Entry`](torrust_tracker_torrent_repository::entry::Entry): it contains all the information stored by the tracker for one torrent.
6
-
//! - The [`SwarmMetadata`](torrust_tracker_primitives::swarm_metadata::SwarmMetadata): it contains aggregate information that can me derived from the torrent entries.
7
+
//! There are two main types of data stored:
7
8
//!
8
-
//! A "swarm" is a network of peers that are trying to download the same torrent.
9
+
//! - **Torrent Entry** (`Entry`): Contains all the information the tracker
10
+
//! stores for a single torrent, including the list of peers currently in the
11
+
//! swarm. This data is crucial for peers to locate each other and initiate
12
+
//! downloads.
9
13
//!
10
-
//! The torrent entry contains the "swarm" data, which is basically the list of peers in the swarm.
11
-
//! That's the most valuable information the peer want to get from the tracker, because it allows them to
12
-
//! start downloading torrent from those peers.
14
+
//! - **Swarm Metadata** (`SwarmMetadata`): Contains aggregate data derived from
15
+
//! all torrent entries. This metadata is split into:
16
+
//! - **Active Peers Data:** Metrics related to the peers that are currently
17
+
//! active in the swarm.
18
+
//! - **Historical Data:** Metrics collected since the tracker started, such
19
+
//! as the total number of completed downloads.
13
20
//!
14
-
//! The "swarm metadata" contains aggregate data derived from the torrent entries. There two types of data:
21
+
//! ## Metrics Collected
15
22
//!
16
-
//! - For **active peers**: metrics related to the current active peers in the swarm.
17
-
//! - **Historical data**: since the tracker started running.
23
+
//! The tracker collects and aggregates the following metrics:
18
24
//!
19
-
//! The tracker collects metrics for:
25
+
//! - The total number of peers that have completed downloading the torrent
26
+
//! since the tracker began collecting metrics.
27
+
//! - The number of completed downloads from peers that remain active (i.e., seeders).
28
+
//! - The number of active peers that have not completed downloading the torrent (i.e., leechers).
20
29
//!
21
-
//! - The number of peers that have completed downloading the torrent since the tracker started collecting metrics.
22
-
//! - The number of peers that have completed downloading the torrent and are still active, that means they are actively participating in the network,
23
-
//! by announcing themselves periodically to the tracker. Since they have completed downloading they have a full copy of the torrent data. Peers with a
24
-
//! full copy of the data are called "seeders".
25
-
//! - The number of peers that have NOT completed downloading the torrent and are still active, that means they are actively participating in the network.
26
-
//! Peer that don not have a full copy of the torrent data are called "leechers".
30
+
//! This information is used both to inform peers about available connections
31
+
//! and to provide overall swarm statistics.
27
32
//!
33
+
//! This module re-exports core types from the torrent repository crate to
34
+
//! simplify integration.
35
+
//!
36
+
//! ## Internal Data Structures
37
+
//!
38
+
//! The [`torrent`](crate::torrent) module contains all the data structures
39
+
//! stored by the tracker except for peers.
40
+
//!
41
+
//! We can represent the data stored in memory internally by the tracker with
42
+
//! this JSON object:
43
+
//!
44
+
//! ```json
45
+
//! {
46
+
//! "c1277613db1d28709b034a017ab2cae4be07ae10": {
47
+
//! "completed": 0,
48
+
//! "peers": {
49
+
//! "-qB00000000000000001": {
50
+
//! "peer_id": "-qB00000000000000001",
51
+
//! "peer_addr": "2.137.87.41:1754",
52
+
//! "updated": 1672419840,
53
+
//! "uploaded": 120,
54
+
//! "downloaded": 60,
55
+
//! "left": 60,
56
+
//! "event": "started"
57
+
//! },
58
+
//! "-qB00000000000000002": {
59
+
//! "peer_id": "-qB00000000000000002",
60
+
//! "peer_addr": "23.17.287.141:2345",
61
+
//! "updated": 1679415984,
62
+
//! "uploaded": 80,
63
+
//! "downloaded": 20,
64
+
//! "left": 40,
65
+
//! "event": "started"
66
+
//! }
67
+
//! }
68
+
//! }
69
+
//! }
70
+
//! ```
71
+
//!
72
+
//! The tracker maintains an indexed-by-info-hash list of torrents. For each
73
+
//! torrent, it stores a torrent `Entry`. The torrent entry has two attributes:
74
+
//!
75
+
//! - `completed`: which is hte number of peers that have completed downloading
76
+
//! the torrent file/s. As they have completed downloading, they have a full
77
+
//! version of the torrent data, and they can provide the full data to other
78
+
//! peers. That's why they are also known as "seeders".
79
+
//! - `peers`: an indexed and orderer list of peer for the torrent. Each peer
80
+
//! contains the data received from the peer in the `announce` request.
81
+
//!
82
+
//! The [`crate::torrent`] module not only contains the original data obtained
83
+
//! from peer via `announce` requests, it also contains aggregate data that can
84
+
//! be derived from the original data. For example:
85
+
//!
86
+
//! ```rust,no_run
87
+
//! pub struct SwarmMetadata {
88
+
//! pub complete: u32, // The number of active peers that have completed downloading (seeders)
89
+
//! pub downloaded: u32, // The number of peers that have ever completed downloading
90
+
//! pub incomplete: u32, // The number of active peers that have not completed downloading (leechers)
91
+
//! }
92
+
//! ```
93
+
//!
94
+
//! > **NOTICE**: that `complete` or `completed` peers are the peers that have
95
+
//! > completed downloading, but only the active ones are considered "seeders".
96
+
//!
97
+
//! `SwarmMetadata` struct follows name conventions for `scrape` responses. See
98
+
//! [BEP 48](https://www.bittorrent.org/beps/bep_0048.html), while `SwarmMetadata`
99
+
//! is used for the rest of cases.
100
+
//!
101
+
//! ## Peers
102
+
//!
103
+
//! A `Peer` is the struct used by the tracker to keep peers data:
104
+
//!
105
+
//! ```rust,no_run
106
+
//! use std::net::SocketAddr;
107
+
//! use aquatic_udp_protocol::PeerId;
108
+
//! use torrust_tracker_primitives::DurationSinceUnixEpoch;
//! The `Tracker` keeps an in-memory ordered data structure with all the torrents and a list of peers for each torrent, together with some swarm metrics.
129
+
//!
130
+
//! We can represent the data stored in memory with this JSON object:
131
+
//!
132
+
//! ```json
133
+
//! {
134
+
//! "c1277613db1d28709b034a017ab2cae4be07ae10": {
135
+
//! "completed": 0,
136
+
//! "peers": {
137
+
//! "-qB00000000000000001": {
138
+
//! "peer_id": "-qB00000000000000001",
139
+
//! "peer_addr": "2.137.87.41:1754",
140
+
//! "updated": 1672419840,
141
+
//! "uploaded": 120,
142
+
//! "downloaded": 60,
143
+
//! "left": 60,
144
+
//! "event": "started"
145
+
//! },
146
+
//! "-qB00000000000000002": {
147
+
//! "peer_id": "-qB00000000000000002",
148
+
//! "peer_addr": "23.17.287.141:2345",
149
+
//! "updated": 1679415984,
150
+
//! "uploaded": 80,
151
+
//! "downloaded": 20,
152
+
//! "left": 40,
153
+
//! "event": "started"
154
+
//! }
155
+
//! }
156
+
//! }
157
+
//! }
158
+
//! ```
159
+
//!
160
+
//! That JSON object does not exist, it's only a representation of the `Tracker` torrents data.
161
+
//!
162
+
//! `c1277613db1d28709b034a017ab2cae4be07ae10` is the torrent infohash and `completed` contains the number of peers
163
+
//! that have a full version of the torrent data, also known as seeders.
164
+
//!
165
+
//! Refer to [`peer`](torrust_tracker_primitives::peer) for more information about peers.
28
166
pubmod manager;
29
167
pubmod repository;
30
168
pubmod services;
@@ -33,7 +171,11 @@ pub mod services;
33
171
use torrust_tracker_torrent_repository::EntryMutexStd;
34
172
use torrust_tracker_torrent_repository::TorrentsSkipMapMutexStd;
35
173
36
-
// Currently used types from the torrent repository crate.
174
+
/// Alias for the primary torrent collection type, implemented as a skip map
175
+
/// wrapped in a mutex. This type is used internally by the tracker to manage
0 commit comments