From d7097d4e9a969fbf3f2b129ccfcdf03e91ddde5d Mon Sep 17 00:00:00 2001 From: a-moreira Date: Thu, 14 Dec 2023 20:59:56 -0300 Subject: [PATCH] use info and error macros --- .../src/electrum_protocol.rs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/floresta-electrum/src/electrum_protocol.rs b/crates/floresta-electrum/src/electrum_protocol.rs index 736f1b53..5a3f6ff0 100644 --- a/crates/floresta-electrum/src/electrum_protocol.rs +++ b/crates/floresta-electrum/src/electrum_protocol.rs @@ -22,7 +22,7 @@ use bitcoin::{ }; use bitcoin::{Transaction, TxOut}; -use log::{info, log, trace, Level}; +use log::{error, info, trace}; use serde_json::{json, Value}; use std::collections::{HashMap, HashSet}; use std::sync::Arc; @@ -341,7 +341,7 @@ impl ElectrumServer { ); json_rpc_res!(request, res) } - // TODO: Return clients? + "server.peers.subscribe" => json_rpc_res!(request, []), "server.ping" => json_rpc_res!(request, null), "server.version" => json_rpc_res!( @@ -419,10 +419,7 @@ impl ElectrumServer { if let Ok(req) = serde_json::from_str::(msg.as_str()) { let client = self.clients.get(&client); if client.is_none() { - log!( - Level::Error, - "Client sent a message but is not listed as client" - ); + error!("Client sent a message but is not listed as client"); return Ok(()); } let client = client.unwrap().to_owned(); @@ -474,15 +471,15 @@ impl ElectrumServer { .write(serde_json::to_string(¬ify).unwrap().as_bytes()) .await { - log!(Level::Error, "{err}"); + error!("{err}"); } } } } } -/// Each client gets one reading loop -async fn client_loop( +/// Each client gets one loop to deal with their requests +async fn client_broker_loop( client: Arc, message_transmitter: Sender, ) -> Result<(), std::io::Error> { @@ -496,7 +493,7 @@ async fn client_loop( .expect("Main loop is broken"); } - log!(Level::Info, "Lost a client"); + info!("Lost client with ID: {}", client.client_id); message_transmitter .send(Message::Disconnect(client.client_id)) @@ -514,7 +511,10 @@ pub async fn client_accept_loop(listener: Arc, message_transmitter: info!("New client connection"); let stream = Arc::new(stream); let client = Arc::new(Client::new(id_count, stream)); - async_std::task::spawn(client_loop(client.clone(), message_transmitter.clone())); + async_std::task::spawn(client_broker_loop( + client.clone(), + message_transmitter.clone(), + )); message_transmitter .send(Message::NewClient((client.client_id, client)))