Skip to content

Commit efe7e98

Browse files
committed
Merge torrust#1259: Overhaul core Tracker: review public methods for tracker-core package
6639c98 refactor: [torrust#1258] make things private or pub(crate) when possible. (Jose Celano) Pull request description: Overhaul core Tracker: review public methods for `tracker-core` package. ACKs for top commit: josecelano: ACK 6639c98 Tree-SHA512: 0f45460320a3bd587e0e51eb92f2bfb73d5c889f1279d48668680b886c612d9af96fe1710a1526c6fd67ec540d85110f5031eaf5fe078980c043024caa943d47
2 parents ea2d73d + 6639c98 commit efe7e98

30 files changed

+357
-320
lines changed

packages/tracker-core/src/announce_handler.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ mod tests {
182182
use torrust_tracker_test_helpers::configuration;
183183

184184
use crate::announce_handler::AnnounceHandler;
185-
use crate::core_tests::initialize_handlers;
186185
use crate::scrape_handler::ScrapeHandler;
186+
use crate::test_helpers::tests::initialize_handlers;
187187

188188
fn public_tracker() -> (Arc<AnnounceHandler>, Arc<ScrapeHandler>) {
189189
let config = configuration::ephemeral_public();
@@ -244,7 +244,7 @@ mod tests {
244244
peer_ip, public_tracker, sample_peer_1, sample_peer_2, sample_peer_3,
245245
};
246246
use crate::announce_handler::PeersWanted;
247-
use crate::core_tests::{sample_info_hash, sample_peer};
247+
use crate::test_helpers::tests::{sample_info_hash, sample_peer};
248248

249249
mod should_assign_the_ip_to_the_peer {
250250

@@ -411,7 +411,7 @@ mod tests {
411411

412412
use crate::announce_handler::tests::the_announce_handler::{peer_ip, public_tracker};
413413
use crate::announce_handler::PeersWanted;
414-
use crate::core_tests::{completed_peer, leecher, sample_info_hash, seeder, started_peer};
414+
use crate::test_helpers::tests::{completed_peer, leecher, sample_info_hash, seeder, started_peer};
415415

416416
#[tokio::test]
417417
async fn when_the_peer_is_a_seeder() {
@@ -474,8 +474,8 @@ mod tests {
474474

475475
use crate::announce_handler::tests::the_announce_handler::peer_ip;
476476
use crate::announce_handler::{AnnounceHandler, PeersWanted};
477-
use crate::core_tests::{sample_info_hash, sample_peer};
478477
use crate::databases::setup::initialize_database;
478+
use crate::test_helpers::tests::{sample_info_hash, sample_peer};
479479
use crate::torrent::manager::TorrentsManager;
480480
use crate::torrent::repository::in_memory::InMemoryTorrentRepository;
481481
use crate::torrent::repository::persisted::DatabasePersistentTorrentRepository;

packages/tracker-core/src/authentication/handler.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl KeysHandler {
132132
/// # Errors
133133
///
134134
/// Will return a `database::Error` if unable to add the `auth_key` to the database.
135-
pub async fn generate_permanent_peer_key(&self) -> Result<PeerKey, databases::error::Error> {
135+
pub(crate) async fn generate_permanent_peer_key(&self) -> Result<PeerKey, databases::error::Error> {
136136
self.generate_expiring_peer_key(None).await
137137
}
138138

@@ -170,7 +170,7 @@ impl KeysHandler {
170170
/// # Arguments
171171
///
172172
/// * `key` - The pre-generated key.
173-
pub async fn add_permanent_peer_key(&self, key: Key) -> Result<PeerKey, databases::error::Error> {
173+
pub(crate) async fn add_permanent_peer_key(&self, key: Key) -> Result<PeerKey, databases::error::Error> {
174174
self.add_expiring_peer_key(key, None).await
175175
}
176176

@@ -188,7 +188,7 @@ impl KeysHandler {
188188
/// * `key` - The pre-generated key.
189189
/// * `lifetime` - The duration in seconds for the new key. The key will be
190190
/// no longer valid after `lifetime` seconds.
191-
pub async fn add_expiring_peer_key(
191+
pub(crate) async fn add_expiring_peer_key(
192192
&self,
193193
key: Key,
194194
valid_until: Option<DurationSinceUnixEpoch>,
@@ -219,7 +219,7 @@ impl KeysHandler {
219219
}
220220

221221
/// It removes an authentication key from memory.
222-
pub async fn remove_in_memory_auth_key(&self, key: &Key) {
222+
pub(crate) async fn remove_in_memory_auth_key(&self, key: &Key) {
223223
self.in_memory_key_repository.remove(key).await;
224224
}
225225

packages/tracker-core/src/authentication/key/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,19 @@ pub type ParseKeyError = peer_key::ParseKeyError;
5959
///
6060
/// For more information see function [`generate_key`](crate::authentication::key::generate_key) to generate the
6161
/// [`PeerKey`](crate::authentication::PeerKey).
62-
pub const AUTH_KEY_LENGTH: usize = 32;
62+
pub(crate) const AUTH_KEY_LENGTH: usize = 32;
6363

6464
/// It generates a new permanent random key [`PeerKey`].
65+
#[cfg(test)]
6566
#[must_use]
66-
pub fn generate_permanent_key() -> PeerKey {
67+
pub(crate) fn generate_permanent_key() -> PeerKey {
6768
generate_key(None)
6869
}
6970

7071
/// It generates a new expiring random key [`PeerKey`].
72+
#[cfg(test)]
7173
#[must_use]
72-
pub fn generate_expiring_key(lifetime: Duration) -> PeerKey {
74+
pub(crate) fn generate_expiring_key(lifetime: Duration) -> PeerKey {
7375
generate_key(Some(lifetime))
7476
}
7577

packages/tracker-core/src/authentication/key/repository/in_memory.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,22 @@ pub struct InMemoryKeyRepository {
99

1010
impl InMemoryKeyRepository {
1111
/// It adds a new authentication key.
12-
pub async fn insert(&self, auth_key: &PeerKey) {
12+
pub(crate) async fn insert(&self, auth_key: &PeerKey) {
1313
self.keys.write().await.insert(auth_key.key.clone(), auth_key.clone());
1414
}
1515

1616
/// It removes an authentication key.
17-
pub async fn remove(&self, key: &Key) {
17+
pub(crate) async fn remove(&self, key: &Key) {
1818
self.keys.write().await.remove(key);
1919
}
2020

21-
pub async fn get(&self, key: &Key) -> Option<PeerKey> {
21+
pub(crate) async fn get(&self, key: &Key) -> Option<PeerKey> {
2222
self.keys.read().await.get(key).cloned()
2323
}
2424

2525
/// It clears all the authentication keys.
26-
pub async fn clear(&self) {
26+
#[allow(dead_code)]
27+
pub(crate) async fn clear(&self) {
2728
let mut keys = self.keys.write().await;
2829
keys.clear();
2930
}

packages/tracker-core/src/authentication/key/repository/persisted.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl DatabaseKeyRepository {
2121
/// # Errors
2222
///
2323
/// Will return a `databases::error::Error` if unable to add the `auth_key` to the database.
24-
pub fn add(&self, peer_key: &PeerKey) -> Result<(), databases::error::Error> {
24+
pub(crate) fn add(&self, peer_key: &PeerKey) -> Result<(), databases::error::Error> {
2525
self.database.add_key_to_keys(peer_key)?;
2626
Ok(())
2727
}
@@ -31,7 +31,7 @@ impl DatabaseKeyRepository {
3131
/// # Errors
3232
///
3333
/// Will return a `database::Error` if unable to remove the `key` from the database.
34-
pub fn remove(&self, key: &Key) -> Result<(), databases::error::Error> {
34+
pub(crate) fn remove(&self, key: &Key) -> Result<(), databases::error::Error> {
3535
self.database.remove_key_from_keys(key)?;
3636
Ok(())
3737
}
@@ -41,7 +41,7 @@ impl DatabaseKeyRepository {
4141
/// # Errors
4242
///
4343
/// Will return a `database::Error` if unable to load the keys from the database.
44-
pub fn load_keys(&self) -> Result<Vec<PeerKey>, databases::error::Error> {
44+
pub(crate) fn load_keys(&self) -> Result<Vec<PeerKey>, databases::error::Error> {
4545
let keys = self.database.load_keys()?;
4646
Ok(keys)
4747
}

packages/tracker-core/src/core_tests.rs

-215
This file was deleted.

0 commit comments

Comments
 (0)