From d67e1641494c925a1bcf37f2beedf8fdd03d6b8c Mon Sep 17 00:00:00 2001 From: qima Date: Mon, 7 Oct 2024 23:37:19 +0800 Subject: [PATCH 1/2] feat(auditor): restart webservice on client request --- sn_auditor/src/main.rs | 82 +++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 33 deletions(-) diff --git a/sn_auditor/src/main.rs b/sn_auditor/src/main.rs index 2faf8551e1..5da0fea62e 100644 --- a/sn_auditor/src/main.rs +++ b/sn_auditor/src/main.rs @@ -262,43 +262,59 @@ async fn initialize_background_spend_dag_collection( } async fn start_server(dag: SpendDagDb) -> Result<()> { - let server = Server::http("0.0.0.0:4242").expect("Failed to start server"); - info!("Starting dag-query server listening on port 4242..."); - for request in server.incoming_requests() { - info!( - "Received request! method: {:?}, url: {:?}", - request.method(), - request.url(), - ); - - // Dispatch the request to the appropriate handler - let response = match request.url() { - "/" => routes::spend_dag_svg(&dag), - s if s.starts_with("/spend/") => routes::spend(&dag, &request).await, - s if s.starts_with("/add-participant/") => { - routes::add_participant(&dag, &request).await - } - "/beta-rewards" => routes::beta_rewards(&dag).await, - _ => routes::not_found(), - }; + loop { + let server = Server::http("0.0.0.0:4242").expect("Failed to start server"); + info!("Starting dag-query server listening on port 4242..."); + for request in server.incoming_requests() { + info!( + "Received request! method: {:?}, url: {:?}", + request.method(), + request.url(), + ); - // Send a response to the client - match response { - Ok(res) => { - let _ = request - .respond(res) - .map_err(|err| eprintln!("Failed to send response: {err}")); - } - Err(e) => { - eprint!("Sending error to client: {e}"); - let res = Response::from_string(format!("Error: {e}")).with_status_code(500); - let _ = request - .respond(res) - .map_err(|err| eprintln!("Failed to send error response: {err}")); + // Dispatch the request to the appropriate handler + let response = match request.url() { + "/" => routes::spend_dag_svg(&dag), + s if s.starts_with("/spend/") => routes::spend(&dag, &request).await, + s if s.starts_with("/add-participant/") => { + routes::add_participant(&dag, &request).await + } + "/beta-rewards" => routes::beta_rewards(&dag).await, + "/restart" => { + info!("Restart auditor web service as to client's request"); + break; + } + "/terminate" => { + info!("Terminate auditor web service as to client's request"); + return Ok(()); + } + _ => routes::not_found(), + }; + + // Send a response to the client + match response { + Ok(res) => { + info!("Sending response to client"); + let _ = request.respond(res).map_err(|err| { + warn!("Failed to send response: {err}"); + eprintln!("Failed to send response: {err}") + }); + } + Err(e) => { + eprint!("Sending error to client: {e}"); + let res = Response::from_string(format!("Error: {e}")).with_status_code(500); + let _ = request.respond(res).map_err(|err| { + warn!("Failed to send error response: {err}"); + eprintln!("Failed to send error response: {err}") + }); + } } } + // Reaching this point indicates a restarting of auditor web service + // Sleep for a while to allowing OS cleanup and settlement. + drop(server); + std::thread::sleep(std::time::Duration::from_secs(10)); } - Ok(()) } // get the data dir path for auditor From 979e03c945c76ecc1c61e32fb5f9c0404b916d0d Mon Sep 17 00:00:00 2001 From: Chris O'Neil Date: Mon, 7 Oct 2024 19:23:15 +0100 Subject: [PATCH 2/2] chore(release): stable release 2024.10.2.2 ================== Crate Versions ================== autonomi: 0.1.2 sn_auditor: 0.3.4 sn_build_info: 0.1.15 sn_cli: 0.95.3 sn_client: 0.110.3 sn_faucet: 0.5.3 sn_logging: 0.2.36 sn_metrics: 0.1.16 nat-detection: 0.2.7 sn_networking: 0.18.4 sn_node: 0.111.4 node-launchpad: 0.3.19 sn_node_manager: 0.10.6 sn_node_rpc_client: 0.6.31 sn_peers_acquisition: 0.5.3 sn_protocol: 0.17.11 sn_registers: 0.3.21 sn_service_management: 0.3.14 sn_transfers: 0.19.3 test_utils: 0.4.7 token_supplies: 0.1.54 =================== Binary Versions =================== faucet: 0.5.3 nat-detection: 0.2.7 node-launchpad: 0.3.19 safe: 0.95.3 safenode: 0.111.4 safenode-manager: 0.10.6 safenode_rpc_client: 0.6.31 safenodemand: 0.10.6 sn_auditor: 0.3.4 --- CHANGELOG.md | 14 ++++++++++++-- Cargo.lock | 2 +- sn_auditor/Cargo.toml | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e05fa21fa9..9da0b70553 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #### Changed +- The auditor's webservice has new endpoints that allow it to be restarted or terminated + +## 2024-10-07 + +### Network + +#### Changed + - Increase chunk size to 4MB with node size remaining at 32GB - Bootstrap peer parsing in CI was changed to accommodate new log format in libp2p @@ -20,7 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #### Added -- The `add` command has new `--max-log-files` and `--max-archived-log-files` arguments to support capping node log output +- The `add` command has new `--max-log-files` and `--max-archived-log-files` arguments to support + capping node log output #### Fixed @@ -30,7 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Increased logging related to app configuration. This could help solving issues on launchpad start up. +- Increased logging related to app configuration. This could help solving issues on launchpad start + up. ## 2024-10-03 diff --git a/Cargo.lock b/Cargo.lock index 5418bdcc30..aa9771fd8b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7002,7 +7002,7 @@ dependencies = [ [[package]] name = "sn_auditor" -version = "0.3.3" +version = "0.3.4" dependencies = [ "blsttc", "clap", diff --git a/sn_auditor/Cargo.toml b/sn_auditor/Cargo.toml index b38eeee122..6251404483 100644 --- a/sn_auditor/Cargo.toml +++ b/sn_auditor/Cargo.toml @@ -2,7 +2,7 @@ authors = ["MaidSafe Developers "] description = "Safe Network Auditor" name = "sn_auditor" -version = "0.3.3" +version = "0.3.4" edition = "2021" homepage = "https://maidsafe.net" repository = "https://github.com/maidsafe/safe_network"