@@ -33,11 +33,11 @@ use bittorrent_udp_tracker_core::MAX_CONNECTION_ID_ERRORS_PER_IP;
33
33
use tokio:: sync:: RwLock ;
34
34
use torrust_tracker_clock:: static_time;
35
35
use torrust_tracker_configuration:: validator:: Validator ;
36
- use torrust_tracker_configuration:: { logging, Configuration , Logging } ;
36
+ use torrust_tracker_configuration:: { logging, Configuration , Core , HttpApi , Logging , UdpTracker } ;
37
37
use tracing:: instrument;
38
38
39
39
use super :: config:: initialize_configuration;
40
- use crate :: container:: AppContainer ;
40
+ use crate :: container:: { AppContainer , HttpApiContainer , UdpTrackerContainer } ;
41
41
42
42
/// It loads the configuration from the environment and builds app container.
43
43
///
@@ -155,6 +155,79 @@ pub fn initialize_app_container(configuration: &Configuration) -> AppContainer {
155
155
}
156
156
}
157
157
158
+ #[ must_use]
159
+ pub fn initialize_http_api_container ( core_config : & Arc < Core > , http_api_config : & Arc < HttpApi > ) -> Arc < HttpApiContainer > {
160
+ // HTTP stats
161
+ let ( _http_stats_event_sender, http_stats_repository) =
162
+ bittorrent_http_tracker_core:: statistics:: setup:: factory ( core_config. tracker_usage_statistics ) ;
163
+ let http_stats_repository = Arc :: new ( http_stats_repository) ;
164
+
165
+ // UDP stats
166
+ let ( _udp_stats_event_sender, udp_stats_repository) =
167
+ bittorrent_udp_tracker_core:: statistics:: setup:: factory ( core_config. tracker_usage_statistics ) ;
168
+ let udp_stats_repository = Arc :: new ( udp_stats_repository) ;
169
+
170
+ let ban_service = Arc :: new ( RwLock :: new ( BanService :: new ( MAX_CONNECTION_ID_ERRORS_PER_IP ) ) ) ;
171
+ let database = initialize_database ( core_config) ;
172
+ let in_memory_whitelist = Arc :: new ( InMemoryWhitelist :: default ( ) ) ;
173
+ let whitelist_manager = initialize_whitelist_manager ( database. clone ( ) , in_memory_whitelist. clone ( ) ) ;
174
+ let db_key_repository = Arc :: new ( DatabaseKeyRepository :: new ( & database) ) ;
175
+ let in_memory_key_repository = Arc :: new ( InMemoryKeyRepository :: default ( ) ) ;
176
+ let keys_handler = Arc :: new ( KeysHandler :: new (
177
+ & db_key_repository. clone ( ) ,
178
+ & in_memory_key_repository. clone ( ) ,
179
+ ) ) ;
180
+ let in_memory_torrent_repository = Arc :: new ( InMemoryTorrentRepository :: default ( ) ) ;
181
+
182
+ Arc :: new ( HttpApiContainer {
183
+ http_api_config : http_api_config. clone ( ) ,
184
+ core_config : core_config. clone ( ) ,
185
+ in_memory_torrent_repository : in_memory_torrent_repository. clone ( ) ,
186
+ keys_handler : keys_handler. clone ( ) ,
187
+ whitelist_manager : whitelist_manager. clone ( ) ,
188
+ ban_service : ban_service. clone ( ) ,
189
+ http_stats_repository : http_stats_repository. clone ( ) ,
190
+ udp_stats_repository : udp_stats_repository. clone ( ) ,
191
+ } )
192
+ }
193
+
194
+ #[ must_use]
195
+ pub fn initialize_udt_tracker_container (
196
+ core_config : & Arc < Core > ,
197
+ udp_tracker_config : & Arc < UdpTracker > ,
198
+ ) -> Arc < UdpTrackerContainer > {
199
+ // UDP stats
200
+ let ( udp_stats_event_sender, _udp_stats_repository) =
201
+ bittorrent_udp_tracker_core:: statistics:: setup:: factory ( core_config. tracker_usage_statistics ) ;
202
+ let udp_stats_event_sender = Arc :: new ( udp_stats_event_sender) ;
203
+
204
+ let ban_service = Arc :: new ( RwLock :: new ( BanService :: new ( MAX_CONNECTION_ID_ERRORS_PER_IP ) ) ) ;
205
+ let database = initialize_database ( core_config) ;
206
+ let in_memory_whitelist = Arc :: new ( InMemoryWhitelist :: default ( ) ) ;
207
+ let whitelist_authorization = Arc :: new ( WhitelistAuthorization :: new ( core_config, & in_memory_whitelist. clone ( ) ) ) ;
208
+ let in_memory_torrent_repository = Arc :: new ( InMemoryTorrentRepository :: default ( ) ) ;
209
+ let db_torrent_repository = Arc :: new ( DatabasePersistentTorrentRepository :: new ( & database) ) ;
210
+
211
+ let announce_handler = Arc :: new ( AnnounceHandler :: new (
212
+ core_config,
213
+ & whitelist_authorization,
214
+ & in_memory_torrent_repository,
215
+ & db_torrent_repository,
216
+ ) ) ;
217
+
218
+ let scrape_handler = Arc :: new ( ScrapeHandler :: new ( & whitelist_authorization, & in_memory_torrent_repository) ) ;
219
+
220
+ Arc :: new ( UdpTrackerContainer {
221
+ udp_tracker_config : udp_tracker_config. clone ( ) ,
222
+ core_config : core_config. clone ( ) ,
223
+ announce_handler : announce_handler. clone ( ) ,
224
+ scrape_handler : scrape_handler. clone ( ) ,
225
+ whitelist_authorization : whitelist_authorization. clone ( ) ,
226
+ udp_stats_event_sender : udp_stats_event_sender. clone ( ) ,
227
+ ban_service : ban_service. clone ( ) ,
228
+ } )
229
+ }
230
+
158
231
/// It initializes the application static values.
159
232
///
160
233
/// These values are accessible throughout the entire application:
0 commit comments