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: create dependency containers for UDP tracker, HTTP tracker and Tracker API #1217

Closed
Tracked by #1181
josecelano opened this issue Jan 28, 2025 · 1 comment · Fixed by #1218
Closed
Tracked by #1181
Assignees
Labels
- Developer - Torrust Improvement Experience Code Cleanup / Refactoring Tidying and Making Neat

Comments

@josecelano
Copy link
Member

josecelano commented Jan 28, 2025

Parent issue: #1181

After refactoring the core Tracker (it was removed), all services are injected independently where they are needed.

This function signature is very common:

impl Launcher {
    #[allow(clippy::too_many_arguments)]
    #[instrument(skip(
        self,
        announce_handler,
        scrape_handler,
        authentication_service,
        whitelist_authorization,
        stats_event_sender,
        tx_start,
        rx_halt
    ))]
    fn start(
        &self,
        config: Arc<Core>,
        announce_handler: Arc<AnnounceHandler>,
        scrape_handler: Arc<ScrapeHandler>,
        authentication_service: Arc<AuthenticationService>,
        whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
        stats_event_sender: Arc<Option<Box<dyn statistics::event::sender::Sender>>>,
        tx_start: Sender<Started>,
        rx_halt: Receiver<Halted>,
    ) -> BoxFuture<'static, ()> {
    
    // ...

    }
}

Where announce_handler, scrape_handler, authentication_service, whitelist_authorization and stats_event_sender are the services needed by this function.

We could pass the AppContainer I have introduced in this core tracker overhaul:

pub struct AppContainer {
    pub database: Arc<Box<dyn Database>>,
    pub announce_handler: Arc<AnnounceHandler>,
    pub scrape_handler: Arc<ScrapeHandler>,
    pub keys_handler: Arc<KeysHandler>,
    pub authentication_service: Arc<AuthenticationService>,
    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 in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
    pub db_torrent_repository: Arc<DatabasePersistentTorrentRepository>,
    pub torrents_manager: Arc<TorrentsManager>,
}

However the main three application user's services (UDP tracker, HTTP tracker and Tracker API) don't use the same services. My proposal is to create specific containers for those services:

  • UdpTrackerContainer
  • HttpTrackerContainer
  • TrackerApiContainer

cc @da2ce7

@josecelano josecelano added - Developer - Torrust Improvement Experience Code Cleanup / Refactoring Tidying and Making Neat labels Jan 28, 2025
@josecelano josecelano self-assigned this Jan 28, 2025
@josecelano josecelano mentioned this issue Jan 28, 2025
26 tasks
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Jan 28, 2025
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Jan 29, 2025
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Jan 29, 2025
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Jan 29, 2025
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Jan 29, 2025
josecelano added a commit to josecelano/torrust-tracker that referenced this issue Jan 29, 2025
@josecelano
Copy link
Member Author

I considered extracting also a CoreTrackerContainer to avoid this duplications:

struct CoreTrackerServices {
    pub core_config: Arc<Core>,
    pub announce_handler: Arc<AnnounceHandler>,
    pub stats_event_sender: Arc<Option<Box<dyn Sender>>>,
    pub whitelist_authorization: Arc<WhitelistAuthorization>,
    pub authentication_service: Arc<AuthenticationService>,
}
    
struct CoreTrackerServices {
    pub core_config: Arc<Core>,
    pub scrape_handler: Arc<ScrapeHandler>,
    pub stats_event_sender: Arc<Option<Box<dyn crate::core::statistics::event::sender::Sender>>>,
    pub authentication_service: Arc<AuthenticationService>,
}

struct CoreTrackerServices {
    pub core_config: Arc<Core>,
    pub announce_handler: Arc<AnnounceHandler>,
    pub stats_event_sender: Arc<Option<Box<dyn Sender>>>,
}
    
struct CoreTrackerServices {
    pub core_config: Arc<Core>,
    pub announce_handler: Arc<AnnounceHandler>,
    pub scrape_handler: Arc<ScrapeHandler>,
    pub in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
    pub stats_event_sender: Arc<Option<Box<dyn Sender>>>,
    pub in_memory_whitelist: Arc<InMemoryWhitelist>,
    pub whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
}

However I didn't do it because there are used only in tests and are not exactly the same. They only use the services they need for a concrete tests.

josecelano added a commit that referenced this issue Jan 29, 2025
…UDP tracker, HTTP tracker and Tracker API

b38e4af chore: add DevSkim ignore DS173237 (Jose Celano)
66b2b56 refactor: [#1217] extract HttpApiContainer (Jose Celano)
a2bf1cd refactor: [#1217] extract HttpTrackerContainer (Jose Celano)
5342a5d refactor: [#1217] extract UdpTrackerContainer (Jose Celano)

Pull request description:

  Overhaul core Tracker: create dependency containers for UDP tracker, HTTP tracker and Tracker API.

  ### Subtasks

  - [x] Extract `UdpTrackerContainer`
  - [x] Extract `HttpTrackerContainer`
  - [x] Extract `HttpApiContainer`

ACKs for top commit:
  josecelano:
    ACK b38e4af

Tree-SHA512: da14cb884920eaf7f7c249dace05596a61ee0532efb77cb4bd5c381e6c5d2b119d86f8f22764080b84c7f165c4fc524dce2eb4e311521728fdb81d172bda6164
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- Developer - Torrust Improvement Experience Code Cleanup / Refactoring Tidying and Making Neat
Projects
None yet
1 participant