diff --git a/src/config.rs b/src/config.rs index 072c709..6d9deff 100644 --- a/src/config.rs +++ b/src/config.rs @@ -65,7 +65,7 @@ impl Config { gen_ssl(&key, &cert)? }; - let config = Self { + let mut config = Self { multicast_addr: SocketAddrV4::new(MULTICAST_IP, DEFAULT_PORT), download_dir, local_ip_addr: Some(local_ip_addr), @@ -80,7 +80,7 @@ impl Config { }, }; - let config = if !config_file.exists() { + let mut config = if !config_file.exists() { log::info!("creating config file at {config_file:?}"); std::fs::write(&config_file, toml::to_string(&config)?)?; config @@ -92,6 +92,12 @@ impl Config { .map_err(Box::new)? // boxed because the error size from figment is large }; + if config.local_ip_addr.is_none() { + config.local_ip_addr = Some(local_ip_addr); + } + + log::info!("using config: {config:?}"); + Ok(config) } diff --git a/src/http_server.rs b/src/http_server.rs index 2468e7e..0e4b2cb 100644 --- a/src/http_server.rs +++ b/src/http_server.rs @@ -35,12 +35,9 @@ impl JocalService { // TODO: make addr config let addr = SocketAddr::from(([0, 0, 0, 0], self.config.device.port)); let (key, cert) = self.config.ssl(); - let listener = TcpListener::bind(&addr).await?; let ssl_config = rustls_server_config(key, cert); - // let acceptor = TlsAcceptor::from(ssl_config); - // let stop = Arc::new(Mutex::new(stop_rx)); /*