Skip to content

Commit cb8935b

Browse files
committed
feat!: [#591] use full socket addr in net config instead of only the port
Old: ```toml [net] port = 3001 ``` New: ```toml [net] bind_address = "0.0.0.0:3001" ```
1 parent 52f3d9c commit cb8935b

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

src/app.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ pub async fn run(configuration: Configuration, api_version: &Version) -> Running
5757
let importer_torrent_info_update_interval = settings.tracker_statistics_importer.torrent_info_update_interval;
5858
let importer_port = settings.tracker_statistics_importer.port;
5959
// From [net] config
60-
let net_ip = settings.net.bind_address.ip().to_string();
61-
let net_port = settings.net.bind_address.port();
60+
let config_bind_address = settings.net.bind_address;
6261
let opt_net_tsl = settings.net.tsl.clone();
6362

6463
// IMPORTANT: drop settings before starting server to avoid read locks that
@@ -181,7 +180,7 @@ pub async fn run(configuration: Configuration, api_version: &Version) -> Running
181180
);
182181

183182
// Start API server
184-
let running_api = web::api::start(app_data, &net_ip, net_port, opt_net_tsl, api_version).await;
183+
let running_api = web::api::start(app_data, config_bind_address, opt_net_tsl, api_version).await;
185184

186185
// Full running application
187186
Running {

src/web/api/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ pub struct Running {
3838
#[must_use]
3939
pub async fn start(
4040
app_data: Arc<AppData>,
41-
net_ip: &str,
42-
net_port: u16,
41+
config_bind_address: SocketAddr,
4342
opt_tsl: Option<Tsl>,
4443
implementation: &Version,
4544
) -> api::Running {
4645
match implementation {
47-
Version::V1 => server::start(app_data, net_ip, net_port, opt_tsl).await,
46+
Version::V1 => server::start(app_data, config_bind_address, opt_tsl).await,
4847
}
4948
}

src/web/api/server/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ pub type DynError = Arc<dyn std::error::Error + Send + Sync>;
2828
/// # Panics
2929
///
3030
/// Panics if the API server can't be started.
31-
pub async fn start(app_data: Arc<AppData>, net_ip: &str, net_port: u16, opt_tsl: Option<Tsl>) -> Running {
32-
let config_socket_addr: SocketAddr = format!("{net_ip}:{net_port}")
33-
.parse()
34-
.expect("API server socket address to be valid.");
35-
31+
pub async fn start(app_data: Arc<AppData>, config_bind_address: SocketAddr, opt_tsl: Option<Tsl>) -> Running {
3632
let opt_rust_tls_config = make_rust_tls(&opt_tsl)
3733
.await
3834
.map(|tls| tls.expect("it should have a valid net tls configuration"));
@@ -42,9 +38,9 @@ pub async fn start(app_data: Arc<AppData>, net_ip: &str, net_port: u16, opt_tsl:
4238

4339
// Run the API server
4440
let join_handle = tokio::spawn(async move {
45-
info!("Starting API server with net config: {} ...", config_socket_addr);
41+
info!("Starting API server with net config: {} ...", config_bind_address);
4642

47-
start_server(config_socket_addr, app_data.clone(), tx_start, rx_halt, opt_rust_tls_config).await;
43+
start_server(config_bind_address, app_data.clone(), tx_start, rx_halt, opt_rust_tls_config).await;
4844

4945
info!("API server stopped");
5046

0 commit comments

Comments
 (0)