diff --git a/CHANGELOG.md b/CHANGELOG.md index 49eae5b..d66ef93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,12 @@ Format inspiré de Keep a Changelog et versionnage SemVer. ## [Unreleased] ### Ajouts +- **Configuration externalisée avancée** : Ajout des variables d'environnement `WS_BIND_URL`, `HEALTH_PORT`, `HEALTH_BIND_ADDRESS` - **Configuration externalisée** : Ajout de la variable d'environnement `SDK_RELAY_WS_URL` pour les tests - **Tests améliorés** : Remplacement de `localhost` par `0.0.0.0` dans les tests WebSocket pour compatibilité Docker - **Documentation** : Ajout de `docs/CONFIGURATION.md` avec guide des variables d'environnement - **Flexibilité** : Configuration plus flexible pour les environnements Docker et conteneurs +- **Correction majeure** : Résolution du problème de binding sur 127.0.0.1 au lieu de 0.0.0.0 - Documentation: README modernisé, `docs/ANALYSE.md` et `docs/VALIDATION.md` vérifiés - Open source: LICENSE (MIT), CONTRIBUTING, Code of Conduct - Tests: script `tests/health_check.sh`, test WS conservé diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index 440f766..f064ad0 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -7,6 +7,9 @@ Le service `sdk_relay` peut être configuré via les variables d'environnement s ### Variables principales - **`SDK_RELAY_WS_URL`** : URL WebSocket pour les tests (défaut: `ws://0.0.0.0:8090`) +- **`WS_BIND_URL`** : URL de binding WebSocket (override de la configuration, défaut: valeur de `ws_url`) +- **`HEALTH_PORT`** : Port du serveur de santé (défaut: `8091`) +- **`HEALTH_BIND_ADDRESS`** : Adresse de binding du serveur de santé (défaut: `0.0.0.0`) - **`RUST_LOG`** : Niveau de logging (défaut: `INFO`) ### Configuration via fichier @@ -31,11 +34,13 @@ sp_address="tsp1qqgmwp9n5p9ujhq2j6cfqe4jpkyu70jh9rgj0pwt3ndezk2mrlvw6jqew8fhsule ## Changements récents -### v0.1.2 - Configuration externalisée +### v0.1.3 - Configuration externalisée avancée +- **Ajout** : Variables d'environnement `WS_BIND_URL`, `HEALTH_PORT`, `HEALTH_BIND_ADDRESS` - **Ajout** : Support de la variable d'environnement `SDK_RELAY_WS_URL` pour les tests - **Modification** : Remplacement de `localhost` par `0.0.0.0` dans les tests WebSocket - **Amélioration** : Configuration plus flexible pour les environnements Docker +- **Correction** : Résolution du problème de binding sur 127.0.0.1 au lieu de 0.0.0.0 ### Tests @@ -45,7 +50,9 @@ Les tests WebSocket utilisent maintenant `ws://0.0.0.0:8090` au lieu de `ws://lo ```yaml environment: - - SDK_RELAY_WS_URL=ws://0.0.0.0:8090 + - WS_BIND_URL=0.0.0.0:8090 + - HEALTH_PORT=8091 + - HEALTH_BIND_ADDRESS=0.0.0.0 - RUST_LOG=INFO volumes: - ./relay/sdk_relay.conf:/home/bitcoin/.conf:ro diff --git a/src/main.rs b/src/main.rs index d1fb5f2..1f92638 100644 --- a/src/main.rs +++ b/src/main.rs @@ -424,7 +424,9 @@ async fn handle_health_endpoint(mut stream: TcpStream) { } async fn start_health_server(port: u16) { - let listener = match TcpListener::bind(format!("0.0.0.0:{}", port)).await { + // Use configurable bind address for health server + let bind_address = std::env::var("HEALTH_BIND_ADDRESS").unwrap_or_else(|_| "0.0.0.0".to_string()); + let listener = match TcpListener::bind(format!("{}:{}", bind_address, port)).await { Ok(listener) => listener, Err(e) => { log::error!("Failed to bind health server on port {}: {}", port, e); @@ -666,22 +668,26 @@ async fn main() -> Result<()> { const MAX_RETRIES: u32 = 5; const RETRY_DELAY_MS: u64 = 1000; + // Allow environment variable override of ws_url + let ws_bind_url = std::env::var("WS_BIND_URL").unwrap_or_else(|_| config.ws_url.clone()); + log::info!("Using WebSocket bind URL: {}", ws_bind_url); + while listener.is_none() && retry_count < MAX_RETRIES { - let try_socket = TcpListener::bind(config.ws_url.clone()).await; + let try_socket = TcpListener::bind(ws_bind_url.clone()).await; match try_socket { Ok(socket) => { - log::info!("Successfully bound to {}", config.ws_url); + log::info!("Successfully bound to {}", ws_bind_url); listener = Some(socket); } Err(e) => { retry_count += 1; - log::warn!("Failed to bind to {} (attempt {}/{}): {}", config.ws_url, retry_count, MAX_RETRIES, e); + log::warn!("Failed to bind to {} (attempt {}/{}): {}", ws_bind_url, retry_count, MAX_RETRIES, e); if retry_count < MAX_RETRIES { log::info!("Retrying in {}ms...", RETRY_DELAY_MS); tokio::time::sleep(tokio::time::Duration::from_millis(RETRY_DELAY_MS)).await; } else { - log::error!("Failed to bind to {} after {} attempts: {}", config.ws_url, MAX_RETRIES, e); - return Err(anyhow::anyhow!("Failed to bind to {} after {} attempts: {}", config.ws_url, MAX_RETRIES, e)); + log::error!("Failed to bind to {} after {} attempts: {}", ws_bind_url, MAX_RETRIES, e); + return Err(anyhow::anyhow!("Failed to bind to {} after {} attempts: {}", ws_bind_url, MAX_RETRIES, e)); } } } @@ -691,8 +697,12 @@ async fn main() -> Result<()> { tokio::spawn(MessageCache::clean_up()); - // Start health server on port 8091 - tokio::spawn(start_health_server(8091)); + // Start health server on configurable port + let health_port = std::env::var("HEALTH_PORT") + .ok() + .and_then(|p| p.parse::().ok()) + .unwrap_or(8091); + tokio::spawn(start_health_server(health_port)); // Let's spawn the handling of each connection in a separate task. while let Ok((stream, addr)) = listener.accept().await {