@@ -21,42 +21,44 @@ pub enum Error {
2121}
2222
2323pub struct AppContainer {
24+ // Configuration
2425 pub http_api_config : Arc < Option < HttpApi > > ,
2526
27+ // Core
2628 pub tracker_core_container : Arc < TrackerCoreContainer > ,
29+
30+ // HTTP
2731 pub http_tracker_core_services : Arc < HttpTrackerCoreServices > ,
28- pub udp_tracker_core_services : Arc < UdpTrackerCoreServices > ,
32+ pub http_tracker_instance_containers : Arc < HashMap < SocketAddr , Arc < HttpTrackerCoreContainer > > > ,
2933
30- // UDP Tracker Server Container
34+ // UDP
35+ pub udp_tracker_core_services : Arc < UdpTrackerCoreServices > ,
3136 pub udp_tracker_server_container : Arc < UdpTrackerServerContainer > ,
32-
33- // Tracker Instance Containers
34- pub http_tracker_containers : Arc < HashMap < SocketAddr , Arc < HttpTrackerCoreContainer > > > ,
35- pub udp_tracker_containers : Arc < HashMap < SocketAddr , Arc < UdpTrackerCoreContainer > > > ,
37+ pub udp_tracker_instance_containers : Arc < HashMap < SocketAddr , Arc < UdpTrackerCoreContainer > > > ,
3638}
3739
3840impl AppContainer {
3941 #[ instrument( skip( ) ) ]
4042 pub fn initialize ( configuration : & Configuration ) -> AppContainer {
43+ // Configuration
44+
4145 let core_config = Arc :: new ( configuration. core . clone ( ) ) ;
4246
4347 let http_api_config = Arc :: new ( configuration. http_api . clone ( ) ) ;
4448
45- let tracker_core_container = Arc :: new ( TrackerCoreContainer :: initialize ( & core_config ) ) ;
49+ // Core
4650
47- let http_tracker_core_services = HttpTrackerCoreServices :: initialize_from ( & tracker_core_container) ;
48-
49- let udp_tracker_core_services = UdpTrackerCoreServices :: initialize_from ( & tracker_core_container) ;
51+ let tracker_core_container = Arc :: new ( TrackerCoreContainer :: initialize ( & core_config) ) ;
5052
51- let udp_tracker_server_container = UdpTrackerServerContainer :: initialize ( & core_config ) ;
53+ // HTTP
5254
53- // Tracker Instance Containers
55+ let http_tracker_core_services = HttpTrackerCoreServices :: initialize_from ( & tracker_core_container ) ;
5456
55- let mut http_tracker_containers = HashMap :: new ( ) ;
57+ let mut http_tracker_instance_containers = HashMap :: new ( ) ;
5658
5759 if let Some ( http_trackers) = & configuration. http_trackers {
5860 for http_tracker_config in http_trackers {
59- http_tracker_containers . insert (
61+ http_tracker_instance_containers . insert (
6062 http_tracker_config. bind_address ,
6163 HttpTrackerCoreContainer :: initialize_from_services (
6264 & tracker_core_container,
@@ -67,13 +69,19 @@ impl AppContainer {
6769 }
6870 }
6971
70- let http_tracker_containers = Arc :: new ( http_tracker_containers) ;
72+ let http_tracker_instance_containers = Arc :: new ( http_tracker_instance_containers) ;
73+
74+ // UDP
75+
76+ let udp_tracker_core_services = UdpTrackerCoreServices :: initialize_from ( & tracker_core_container) ;
77+
78+ let udp_tracker_server_container = UdpTrackerServerContainer :: initialize ( & core_config) ;
7179
72- let mut udp_tracker_containers = HashMap :: new ( ) ;
80+ let mut udp_tracker_instance_containers = HashMap :: new ( ) ;
7381
7482 if let Some ( udp_trackers) = & configuration. udp_trackers {
7583 for udp_tracker_config in udp_trackers {
76- udp_tracker_containers . insert (
84+ udp_tracker_instance_containers . insert (
7785 udp_tracker_config. bind_address ,
7886 UdpTrackerCoreContainer :: initialize_from_services (
7987 & tracker_core_container,
@@ -84,21 +92,23 @@ impl AppContainer {
8492 }
8593 }
8694
87- let udp_tracker_containers = Arc :: new ( udp_tracker_containers ) ;
95+ let udp_tracker_instance_containers = Arc :: new ( udp_tracker_instance_containers ) ;
8896
8997 AppContainer {
98+ // Configuration
9099 http_api_config,
91100
101+ // Core
92102 tracker_core_container,
103+
104+ // HTTP
93105 http_tracker_core_services,
94- udp_tracker_core_services ,
106+ http_tracker_instance_containers ,
95107
96- // UDP Tracker Server Container
108+ // UDP
109+ udp_tracker_core_services,
97110 udp_tracker_server_container,
98-
99- // Tracker Instance Containers
100- http_tracker_containers,
101- udp_tracker_containers,
111+ udp_tracker_instance_containers,
102112 }
103113 }
104114
@@ -112,7 +122,7 @@ impl AppContainer {
112122 /// Return an error if there is no HTTP tracker server instance bound to the
113123 /// socket address.
114124 pub fn http_tracker_container ( & self , bind_address : SocketAddr ) -> Result < Arc < HttpTrackerCoreContainer > , Error > {
115- match self . http_tracker_containers . get ( & bind_address) {
125+ match self . http_tracker_instance_containers . get ( & bind_address) {
116126 Some ( http_tracker_container) => Ok ( http_tracker_container. clone ( ) ) ,
117127 None => Err ( Error :: MissingHttpTrackerCoreContainer { bind_address } ) ,
118128 }
@@ -123,7 +133,7 @@ impl AppContainer {
123133 /// Return an error if there is no UDP tracker server instance bound to the
124134 /// socket address.
125135 pub fn udp_tracker_container ( & self , bind_address : SocketAddr ) -> Result < Arc < UdpTrackerCoreContainer > , Error > {
126- match self . udp_tracker_containers . get ( & bind_address) {
136+ match self . udp_tracker_instance_containers . get ( & bind_address) {
127137 Some ( udp_tracker_container) => Ok ( udp_tracker_container. clone ( ) ) ,
128138 None => Err ( Error :: MissingUdpTrackerCoreContainer { bind_address } ) ,
129139 }
0 commit comments