2
2
use std:: env;
3
3
use std:: net:: { IpAddr , Ipv4Addr , Ipv6Addr , SocketAddr } ;
4
4
5
- use torrust_tracker_configuration:: { Configuration , LogLevel } ;
5
+ use torrust_tracker_configuration:: { Configuration , HttpApi , HttpTracker , LogLevel , UdpTracker } ;
6
6
use torrust_tracker_primitives:: TrackerMode ;
7
7
8
8
use crate :: random;
@@ -33,22 +33,27 @@ pub fn ephemeral() -> Configuration {
33
33
34
34
// Ephemeral socket address for API
35
35
let api_port = 0u16 ;
36
- config. http_api . enabled = true ;
37
- config. http_api . bind_address = SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 127 , 0 , 0 , 1 ) ) , api_port) ;
36
+ config. http_api = Some ( HttpApi {
37
+ bind_address : SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 127 , 0 , 0 , 1 ) ) , api_port) ,
38
+ ..Default :: default ( )
39
+ } ) ;
38
40
39
41
// Ephemeral socket address for Health Check API
40
42
let health_check_api_port = 0u16 ;
41
43
config. health_check_api . bind_address = SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 127 , 0 , 0 , 1 ) ) , health_check_api_port) ;
42
44
43
45
// Ephemeral socket address for UDP tracker
44
46
let udp_port = 0u16 ;
45
- config. udp_trackers [ 0 ] . enabled = true ;
46
- config. udp_trackers [ 0 ] . bind_address = SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 127 , 0 , 0 , 1 ) ) , udp_port) ;
47
+ config. udp_trackers = Some ( vec ! [ UdpTracker {
48
+ bind_address: SocketAddr :: new( IpAddr :: V4 ( Ipv4Addr :: new( 127 , 0 , 0 , 1 ) ) , udp_port) ,
49
+ } ] ) ;
47
50
48
51
// Ephemeral socket address for HTTP tracker
49
52
let http_port = 0u16 ;
50
- config. http_trackers [ 0 ] . enabled = true ;
51
- config. http_trackers [ 0 ] . bind_address = SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 127 , 0 , 0 , 1 ) ) , http_port) ;
53
+ config. http_trackers = Some ( vec ! [ HttpTracker {
54
+ bind_address: SocketAddr :: new( IpAddr :: V4 ( Ipv4Addr :: new( 127 , 0 , 0 , 1 ) ) , http_port) ,
55
+ tsl_config: None ,
56
+ } ] ) ;
52
57
53
58
// Ephemeral sqlite database
54
59
let temp_directory = env:: temp_dir ( ) ;
@@ -137,9 +142,17 @@ pub fn ephemeral_ipv6() -> Configuration {
137
142
138
143
let ipv6 = SocketAddr :: new ( IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) ) , 0 ) ;
139
144
140
- cfg. http_api . bind_address . clone_from ( & ipv6) ;
141
- cfg. http_trackers [ 0 ] . bind_address . clone_from ( & ipv6) ;
142
- cfg. udp_trackers [ 0 ] . bind_address = ipv6;
145
+ if let Some ( ref mut http_api) = cfg. http_api {
146
+ http_api. bind_address . clone_from ( & ipv6) ;
147
+ } ;
148
+
149
+ if let Some ( ref mut http_trackers) = cfg. http_trackers {
150
+ http_trackers[ 0 ] . bind_address . clone_from ( & ipv6) ;
151
+ }
152
+
153
+ if let Some ( ref mut udp_trackers) = cfg. udp_trackers {
154
+ udp_trackers[ 0 ] . bind_address . clone_from ( & ipv6) ;
155
+ }
143
156
144
157
cfg
145
158
}
@@ -149,9 +162,9 @@ pub fn ephemeral_ipv6() -> Configuration {
149
162
pub fn ephemeral_with_no_services ( ) -> Configuration {
150
163
let mut cfg = ephemeral ( ) ;
151
164
152
- cfg. http_api . enabled = false ;
153
- cfg. http_trackers [ 0 ] . enabled = false ;
154
- cfg. udp_trackers [ 0 ] . enabled = false ;
165
+ cfg. http_api = None ;
166
+ cfg. http_trackers = None ;
167
+ cfg. udp_trackers = None ;
155
168
156
169
cfg
157
170
}
0 commit comments