@@ -2,20 +2,10 @@ use std::net::SocketAddr;
2
2
use std:: sync:: Arc ;
3
3
4
4
use bittorrent_primitives:: info_hash:: InfoHash ;
5
- use bittorrent_tracker_core:: announce_handler:: AnnounceHandler ;
6
- use bittorrent_tracker_core:: databases:: setup:: initialize_database;
7
- use bittorrent_tracker_core:: databases:: Database ;
8
- use bittorrent_tracker_core:: scrape_handler:: ScrapeHandler ;
9
- use bittorrent_tracker_core:: torrent:: repository:: in_memory:: InMemoryTorrentRepository ;
10
- use bittorrent_tracker_core:: torrent:: repository:: persisted:: DatabasePersistentTorrentRepository ;
11
- use bittorrent_tracker_core:: whitelist:: authorization:: WhitelistAuthorization ;
12
- use bittorrent_tracker_core:: whitelist:: repository:: in_memory:: InMemoryWhitelist ;
5
+ use bittorrent_tracker_core:: container:: TrackerCoreContainer ;
13
6
use bittorrent_udp_tracker_core:: container:: UdpTrackerCoreContainer ;
14
- use bittorrent_udp_tracker_core:: services:: banning:: BanService ;
15
- use bittorrent_udp_tracker_core:: { statistics, MAX_CONNECTION_ID_ERRORS_PER_IP } ;
16
- use tokio:: sync:: RwLock ;
17
7
use torrust_server_lib:: registar:: Registar ;
18
- use torrust_tracker_configuration:: { Configuration , Core , UdpTracker , DEFAULT_TIMEOUT } ;
8
+ use torrust_tracker_configuration:: { Configuration , DEFAULT_TIMEOUT } ;
19
9
use torrust_tracker_lib:: bootstrap:: app:: initialize_global_services;
20
10
use torrust_tracker_lib:: servers:: udp:: server:: spawner:: Spawner ;
21
11
use torrust_tracker_lib:: servers:: udp:: server:: states:: { Running , Stopped } ;
@@ -26,12 +16,7 @@ pub struct Environment<S>
26
16
where
27
17
S : std:: fmt:: Debug + std:: fmt:: Display ,
28
18
{
29
- pub udp_tracker_container : Arc < UdpTrackerCoreContainer > ,
30
-
31
- pub database : Arc < Box < dyn Database > > ,
32
- pub in_memory_torrent_repository : Arc < InMemoryTorrentRepository > ,
33
- pub udp_stats_repository : Arc < statistics:: repository:: Repository > ,
34
-
19
+ pub container : Arc < EnvContainer > ,
35
20
pub registar : Registar ,
36
21
pub server : Server < S > ,
37
22
}
43
28
/// Add a torrent to the tracker
44
29
#[ allow( dead_code) ]
45
30
pub fn add_torrent ( & self , info_hash : & InfoHash , peer : & peer:: Peer ) {
46
- let ( ) = self . in_memory_torrent_repository . upsert_peer ( info_hash, peer) ;
31
+ let ( ) = self
32
+ . container
33
+ . tracker_core_container
34
+ . in_memory_torrent_repository
35
+ . upsert_peer ( info_hash, peer) ;
47
36
}
48
37
}
49
38
@@ -52,51 +41,33 @@ impl Environment<Stopped> {
52
41
pub fn new ( configuration : & Arc < Configuration > ) -> Self {
53
42
initialize_global_services ( configuration) ;
54
43
55
- let env_container = EnvContainer :: initialize ( configuration) ;
44
+ let container = Arc :: new ( EnvContainer :: initialize ( configuration) ) ;
56
45
57
- let bind_to = env_container . udp_tracker_config . bind_address ;
46
+ let bind_to = container . udp_tracker_core_container . udp_tracker_config . bind_address ;
58
47
59
48
let server = Server :: new ( Spawner :: new ( bind_to) ) ;
60
49
61
- let udp_tracker_container = Arc :: new ( UdpTrackerCoreContainer {
62
- core_config : env_container. core_config . clone ( ) ,
63
- announce_handler : env_container. udp_tracker_core_container . announce_handler . clone ( ) ,
64
- scrape_handler : env_container. udp_tracker_core_container . scrape_handler . clone ( ) ,
65
- whitelist_authorization : env_container. udp_tracker_core_container . whitelist_authorization . clone ( ) ,
66
-
67
- udp_tracker_config : env_container. udp_tracker_config . clone ( ) ,
68
- udp_stats_event_sender : env_container. udp_tracker_core_container . udp_stats_event_sender . clone ( ) ,
69
- udp_stats_repository : env_container. udp_tracker_core_container . udp_stats_repository . clone ( ) ,
70
- ban_service : env_container. udp_tracker_core_container . ban_service . clone ( ) ,
71
- } ) ;
72
-
73
50
Self {
74
- udp_tracker_container,
75
-
76
- database : env_container. database . clone ( ) ,
77
- in_memory_torrent_repository : env_container. in_memory_torrent_repository . clone ( ) ,
78
- udp_stats_repository : env_container. udp_stats_repository . clone ( ) ,
79
-
51
+ container,
80
52
registar : Registar :: default ( ) ,
81
53
server,
82
54
}
83
55
}
84
56
85
57
#[ allow( dead_code) ]
86
58
pub async fn start ( self ) -> Environment < Running > {
87
- let cookie_lifetime = self . udp_tracker_container . udp_tracker_config . cookie_lifetime ;
59
+ let cookie_lifetime = self . container . udp_tracker_core_container . udp_tracker_config . cookie_lifetime ;
88
60
89
61
Environment {
90
- udp_tracker_container : self . udp_tracker_container . clone ( ) ,
91
-
92
- database : self . database . clone ( ) ,
93
- in_memory_torrent_repository : self . in_memory_torrent_repository . clone ( ) ,
94
- udp_stats_repository : self . udp_stats_repository . clone ( ) ,
95
-
62
+ container : self . container . clone ( ) ,
96
63
registar : self . registar . clone ( ) ,
97
64
server : self
98
65
. server
99
- . start ( self . udp_tracker_container , self . registar . give_form ( ) , cookie_lifetime)
66
+ . start (
67
+ self . container . udp_tracker_core_container . clone ( ) ,
68
+ self . registar . give_form ( ) ,
69
+ cookie_lifetime,
70
+ )
100
71
. await
101
72
. unwrap ( ) ,
102
73
}
@@ -117,12 +88,7 @@ impl Environment<Running> {
117
88
. expect ( "it should stop the environment within the timeout" ) ;
118
89
119
90
Environment {
120
- udp_tracker_container : self . udp_tracker_container ,
121
-
122
- database : self . database ,
123
- in_memory_torrent_repository : self . in_memory_torrent_repository ,
124
- udp_stats_repository : self . udp_stats_repository ,
125
-
91
+ container : self . container ,
126
92
registar : Registar :: default ( ) ,
127
93
server : stopped. expect ( "it stop the udp tracker service" ) ,
128
94
}
@@ -134,13 +100,8 @@ impl Environment<Running> {
134
100
}
135
101
136
102
pub struct EnvContainer {
137
- pub core_config : Arc < Core > ,
138
- pub udp_tracker_config : Arc < UdpTracker > ,
103
+ pub tracker_core_container : Arc < TrackerCoreContainer > ,
139
104
pub udp_tracker_core_container : Arc < UdpTrackerCoreContainer > ,
140
-
141
- pub database : Arc < Box < dyn Database > > ,
142
- pub in_memory_torrent_repository : Arc < InMemoryTorrentRepository > ,
143
- pub udp_stats_repository : Arc < bittorrent_udp_tracker_core:: statistics:: repository:: Repository > ,
144
105
}
145
106
146
107
impl EnvContainer {
@@ -149,48 +110,12 @@ impl EnvContainer {
149
110
let udp_tracker_configurations = configuration. udp_trackers . clone ( ) . expect ( "missing UDP tracker configuration" ) ;
150
111
let udp_tracker_config = Arc :: new ( udp_tracker_configurations[ 0 ] . clone ( ) ) ;
151
112
152
- // UDP stats
153
- let ( udp_stats_event_sender, udp_stats_repository) =
154
- bittorrent_udp_tracker_core:: statistics:: setup:: factory ( configuration. core . tracker_usage_statistics ) ;
155
- let udp_stats_event_sender = Arc :: new ( udp_stats_event_sender) ;
156
- let udp_stats_repository = Arc :: new ( udp_stats_repository) ;
157
-
158
- let ban_service = Arc :: new ( RwLock :: new ( BanService :: new ( MAX_CONNECTION_ID_ERRORS_PER_IP ) ) ) ;
159
- let database = initialize_database ( & configuration. core ) ;
160
- let in_memory_whitelist = Arc :: new ( InMemoryWhitelist :: default ( ) ) ;
161
- let whitelist_authorization = Arc :: new ( WhitelistAuthorization :: new ( & configuration. core , & in_memory_whitelist. clone ( ) ) ) ;
162
- let in_memory_torrent_repository = Arc :: new ( InMemoryTorrentRepository :: default ( ) ) ;
163
- let db_torrent_repository = Arc :: new ( DatabasePersistentTorrentRepository :: new ( & database) ) ;
164
-
165
- let announce_handler = Arc :: new ( AnnounceHandler :: new (
166
- & configuration. core ,
167
- & whitelist_authorization,
168
- & in_memory_torrent_repository,
169
- & db_torrent_repository,
170
- ) ) ;
171
-
172
- let scrape_handler = Arc :: new ( ScrapeHandler :: new ( & whitelist_authorization, & in_memory_torrent_repository) ) ;
173
-
174
- let udp_tracker_container = Arc :: new ( UdpTrackerCoreContainer {
175
- core_config : core_config. clone ( ) ,
176
- announce_handler : announce_handler. clone ( ) ,
177
- scrape_handler : scrape_handler. clone ( ) ,
178
- whitelist_authorization : whitelist_authorization. clone ( ) ,
179
-
180
- udp_tracker_config : udp_tracker_config. clone ( ) ,
181
- udp_stats_event_sender : udp_stats_event_sender. clone ( ) ,
182
- udp_stats_repository : udp_stats_repository. clone ( ) ,
183
- ban_service : ban_service. clone ( ) ,
184
- } ) ;
113
+ let tracker_core_container = Arc :: new ( TrackerCoreContainer :: initialize ( & core_config) ) ;
114
+ let udp_tracker_core_container = UdpTrackerCoreContainer :: initialize_from ( & tracker_core_container, & udp_tracker_config) ;
185
115
186
116
Self {
187
- core_config,
188
- udp_tracker_config,
189
- udp_tracker_core_container : udp_tracker_container,
190
-
191
- database,
192
- in_memory_torrent_repository,
193
- udp_stats_repository,
117
+ tracker_core_container,
118
+ udp_tracker_core_container,
194
119
}
195
120
}
196
121
}
0 commit comments