Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 30 additions & 0 deletions packages/primitives/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,33 @@ impl ScrapeData {
self.files.insert(*info_hash, SwarmMetadata::zeroed());
}
}

#[cfg(test)]
mod tests {

use bittorrent_primitives::info_hash::InfoHash;

use crate::core::ScrapeData;

/// # Panics
///
/// Will panic if the string representation of the info hash is not a valid info hash.
#[must_use]
pub fn sample_info_hash() -> InfoHash {
"3b245504cf5f11bbdbe1201cea6a6bf45aee1bc0" // DevSkim: ignore DS173237
.parse::<InfoHash>()
.expect("String should be a valid info hash")
}

#[test]
fn it_should_be_able_to_build_a_zeroed_scrape_data_for_a_list_of_info_hashes() {
// Zeroed scrape data is used when the authentication for the scrape request fails.

let sample_info_hash = sample_info_hash();

let mut expected_scrape_data = ScrapeData::empty();
expected_scrape_data.add_file_with_zeroed_metadata(&sample_info_hash);

assert_eq!(ScrapeData::zeroed(&vec![sample_info_hash]), expected_scrape_data);
}
}
4 changes: 2 additions & 2 deletions src/app_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ pub fn initialize_tracker_dependencies(
) -> (
Arc<Box<dyn Database>>,
Arc<InMemoryWhitelist>,
Arc<whitelist::authorization::Authorization>,
Arc<whitelist::authorization::WhitelistAuthorization>,
Arc<AuthenticationService>,
Arc<InMemoryTorrentRepository>,
Arc<DatabasePersistentTorrentRepository>,
Arc<TorrentsManager>,
) {
let database = initialize_database(config);
let in_memory_whitelist = Arc::new(InMemoryWhitelist::default());
let whitelist_authorization = Arc::new(whitelist::authorization::Authorization::new(
let whitelist_authorization = Arc::new(whitelist::authorization::WhitelistAuthorization::new(
&config.core,
&in_memory_whitelist.clone(),
));
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn initialize_app_container(configuration: &Configuration) -> AppContainer {
let ban_service = Arc::new(RwLock::new(BanService::new(MAX_CONNECTION_ID_ERRORS_PER_IP)));
let database = initialize_database(configuration);
let in_memory_whitelist = Arc::new(InMemoryWhitelist::default());
let whitelist_authorization = Arc::new(whitelist::authorization::Authorization::new(
let whitelist_authorization = Arc::new(whitelist::authorization::WhitelistAuthorization::new(
&configuration.core,
&in_memory_whitelist.clone(),
));
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/jobs/http_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub async fn start_job(
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
authentication_service: Arc<AuthenticationService>,
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
stats_event_sender: Arc<Option<Box<dyn Sender>>>,
form: ServiceRegistrationForm,
version: Version,
Expand Down Expand Up @@ -99,7 +99,7 @@ async fn start_v1(
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
authentication_service: Arc<AuthenticationService>,
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
stats_event_sender: Arc<Option<Box<dyn statistics::event::sender::Sender>>>,
form: ServiceRegistrationForm,
) -> JoinHandle<()> {
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/jobs/tracker_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::core::authentication::handler::KeysHandler;
use crate::core::statistics::event::sender::Sender;
use crate::core::statistics::repository::Repository;
use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository;
use crate::core::whitelist::manager::WhiteListManager;
use crate::core::whitelist::manager::WhitelistManager;
use crate::servers::apis::server::{ApiServer, Launcher};
use crate::servers::apis::Version;
use crate::servers::registar::ServiceRegistrationForm;
Expand Down Expand Up @@ -74,7 +74,7 @@ pub async fn start_job(
config: &HttpApi,
in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
keys_handler: Arc<KeysHandler>,
whitelist_manager: Arc<WhiteListManager>,
whitelist_manager: Arc<WhitelistManager>,
ban_service: Arc<RwLock<BanService>>,
stats_event_sender: Arc<Option<Box<dyn Sender>>>,
stats_repository: Arc<Repository>,
Expand Down Expand Up @@ -126,7 +126,7 @@ async fn start_v1(
tls: Option<RustlsConfig>,
in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
keys_handler: Arc<KeysHandler>,
whitelist_manager: Arc<WhiteListManager>,
whitelist_manager: Arc<WhitelistManager>,
ban_service: Arc<RwLock<BanService>>,
stats_event_sender: Arc<Option<Box<dyn Sender>>>,
stats_repository: Arc<Repository>,
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/jobs/udp_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub async fn start_job(
config: &UdpTracker,
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
stats_event_sender: Arc<Option<Box<dyn Sender>>>,
ban_service: Arc<RwLock<BanService>>,
form: ServiceRegistrationForm,
Expand Down
6 changes: 3 additions & 3 deletions src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::core::torrent::manager::TorrentsManager;
use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository;
use crate::core::torrent::repository::persisted::DatabasePersistentTorrentRepository;
use crate::core::whitelist;
use crate::core::whitelist::manager::WhiteListManager;
use crate::core::whitelist::manager::WhitelistManager;
use crate::servers::udp::server::banning::BanService;

pub struct AppContainer {
Expand All @@ -22,11 +22,11 @@ pub struct AppContainer {
pub scrape_handler: Arc<ScrapeHandler>,
pub keys_handler: Arc<KeysHandler>,
pub authentication_service: Arc<AuthenticationService>,
pub whitelist_authorization: Arc<whitelist::authorization::Authorization>,
pub whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
pub ban_service: Arc<RwLock<BanService>>,
pub stats_event_sender: Arc<Option<Box<dyn Sender>>>,
pub stats_repository: Arc<Repository>,
pub whitelist_manager: Arc<WhiteListManager>,
pub whitelist_manager: Arc<WhitelistManager>,
pub in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
pub db_torrent_repository: Arc<DatabasePersistentTorrentRepository>,
pub torrents_manager: Arc<TorrentsManager>,
Expand Down
Loading