1
+ use std:: net:: { IpAddr , Ipv4Addr , SocketAddr } ;
2
+
1
3
use serde:: { Deserialize , Serialize } ;
2
4
use url:: Url ;
3
5
@@ -11,13 +13,16 @@ use crate::config::Tsl;
11
13
/// via port 443, which is a very common setup.
12
14
#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq ) ]
13
15
pub struct Network {
14
- /// The port to listen on. Default to `3001`.
15
- #[ serde( default = "Network::default_port" ) ]
16
- pub port : u16 ,
17
16
/// The base URL for the API. For example: `http://localhost`.
18
17
/// If not set, the base URL will be inferred from the request.
19
18
#[ serde( default = "Network::default_base_url" ) ]
20
19
pub base_url : Option < Url > ,
20
+ /// The address the tracker will bind to.
21
+ /// The format is `ip:port`, for example `0.0.0.0:6969`. If you want to
22
+ /// listen to all interfaces, use `0.0.0.0`. If you want the operating
23
+ /// system to choose a random port, use port `0`.
24
+ #[ serde( default = "Network::default_bind_address" ) ]
25
+ pub bind_address : SocketAddr ,
21
26
/// TSL configuration.
22
27
#[ serde( default = "Network::default_tsl" ) ]
23
28
pub tsl : Option < Tsl > ,
@@ -26,14 +31,22 @@ pub struct Network {
26
31
impl Default for Network {
27
32
fn default ( ) -> Self {
28
33
Self {
29
- port : Self :: default_port ( ) ,
34
+ bind_address : Self :: default_bind_address ( ) ,
30
35
base_url : Self :: default_base_url ( ) ,
31
36
tsl : Self :: default_tsl ( ) ,
32
37
}
33
38
}
34
39
}
35
40
36
41
impl Network {
42
+ fn default_bind_address ( ) -> SocketAddr {
43
+ SocketAddr :: new ( Self :: default_ip ( ) , Self :: default_port ( ) )
44
+ }
45
+
46
+ fn default_ip ( ) -> IpAddr {
47
+ IpAddr :: V4 ( Ipv4Addr :: new ( 0 , 0 , 0 , 0 ) )
48
+ }
49
+
37
50
fn default_port ( ) -> u16 {
38
51
3001
39
52
}
0 commit comments