@@ -7,13 +7,16 @@ use bittorrent_tracker_core::container::TrackerCoreContainer;
7
7
use bittorrent_udp_tracker_core:: container:: UdpTrackerCoreContainer ;
8
8
use futures:: executor:: block_on;
9
9
use torrust_axum_server:: tsl:: make_rust_tls;
10
- use torrust_axum_tracker_api_server:: server:: { ApiServer , Launcher , Running , Stopped } ;
11
10
use torrust_server_lib:: registar:: Registar ;
12
11
use torrust_tracker_api_client:: connection_info:: { ConnectionInfo , Origin } ;
13
12
use torrust_tracker_api_core:: container:: TrackerHttpApiCoreContainer ;
14
13
use torrust_tracker_configuration:: { logging, Configuration } ;
15
14
use torrust_tracker_primitives:: peer;
16
15
16
+ use crate :: server:: { ApiServer , Launcher , Running , Stopped } ;
17
+
18
+ pub type Started = Environment < Running > ;
19
+
17
20
pub struct Environment < S >
18
21
where
19
22
S : std:: fmt:: Debug + std:: fmt:: Display ,
38
41
}
39
42
40
43
impl Environment < Stopped > {
44
+ /// # Panics
45
+ ///
46
+ /// Will panic if it cannot make the TSL configuration from the provided
47
+ /// configuration.
48
+ #[ must_use]
41
49
pub fn new ( configuration : & Arc < Configuration > ) -> Self {
42
50
initialize_global_services ( configuration) ;
43
51
@@ -59,6 +67,9 @@ impl Environment<Stopped> {
59
67
}
60
68
}
61
69
70
+ /// # Panics
71
+ ///
72
+ /// Will panic if the server cannot be started.
62
73
pub async fn start ( self ) -> Environment < Running > {
63
74
let access_tokens = Arc :: new (
64
75
self . container
@@ -89,6 +100,9 @@ impl Environment<Running> {
89
100
Environment :: < Stopped > :: new ( configuration) . start ( ) . await
90
101
}
91
102
103
+ /// # Panics
104
+ ///
105
+ /// Will panic if the server cannot be stopped.
92
106
pub async fn stop ( self ) -> Environment < Stopped > {
93
107
Environment {
94
108
container : self . container ,
@@ -97,6 +111,11 @@ impl Environment<Running> {
97
111
}
98
112
}
99
113
114
+ /// # Panics
115
+ ///
116
+ /// Will panic if it cannot build the origin for the connection info from the
117
+ /// server local socket address.
118
+ #[ must_use]
100
119
pub fn get_connection_info ( & self ) -> ConnectionInfo {
101
120
let origin = Origin :: new ( & format ! ( "http://{}/" , self . server. state. local_addr) ) . unwrap ( ) ; // DevSkim: ignore DS137138
102
121
@@ -112,6 +131,7 @@ impl Environment<Running> {
112
131
}
113
132
}
114
133
134
+ #[ must_use]
115
135
pub fn bind_address ( & self ) -> SocketAddr {
116
136
self . server . state . local_addr
117
137
}
@@ -123,6 +143,14 @@ pub struct EnvContainer {
123
143
}
124
144
125
145
impl EnvContainer {
146
+ /// # Panics
147
+ ///
148
+ /// Will panic if:
149
+ ///
150
+ /// - The configuration does not contain a HTTP tracker configuration.
151
+ /// - The configuration does not contain a UDP tracker configuration.
152
+ /// - The configuration does not contain a HTTP API configuration.
153
+ #[ must_use]
126
154
pub fn initialize ( configuration : & Configuration ) -> Self {
127
155
let core_config = Arc :: new ( configuration. core . clone ( ) ) ;
128
156
0 commit comments