From 7da841e9e7dc91bdad768bb133b8ef99070f2648 Mon Sep 17 00:00:00 2001 From: dasman <75807342+Dastan-glitch@users.noreply.github.com> Date: Fri, 18 Feb 2022 03:58:29 -0500 Subject: [PATCH] bin/ircd: fixing ping-pong reply which fixes occasional re-connection (#66) --- bin/ircd/src/irc_server.rs | 7 ++++++- bin/ircd/src/main.rs | 12 ++++++------ bin/map/src/main.rs | 2 +- example/tree.rs | 4 ++-- src/crypto/constants/sinsemilla.rs | 2 +- src/crypto/note.rs | 2 +- src/crypto/proof.rs | 4 ++-- src/crypto/schnorr.rs | 2 +- src/node/wallet/cashierdb.rs | 4 ++-- src/node/wallet/walletdb.rs | 4 ++-- 10 files changed, 24 insertions(+), 19 deletions(-) diff --git a/bin/ircd/src/irc_server.rs b/bin/ircd/src/irc_server.rs index 6c8da535b..aa022f737 100644 --- a/bin/ircd/src/irc_server.rs +++ b/bin/ircd/src/irc_server.rs @@ -84,7 +84,12 @@ impl IrcServerConnection { //self.write_stream.write_all(b":f00!f00@127.0.0.1 PRIVMSG #dev :y0\n").await?; } "PING" => { - self.reply("PONG").await?; + let line_clone = line.clone(); + let split_line: Vec<&str> = line_clone.split_whitespace().collect(); + if split_line.len() > 1 && split_line[0] == "PING" { + let pong = format!("PONG {}\n", split_line[1]); + self.reply(&pong).await?; + } } "PRIVMSG" => { let channel = tokens.next().ok_or(Error::MalformedPacket)?; diff --git a/bin/ircd/src/main.rs b/bin/ircd/src/main.rs index 03440204c..e86b0524b 100644 --- a/bin/ircd/src/main.rs +++ b/bin/ircd/src/main.rs @@ -82,7 +82,7 @@ async fn process_user_input( ) -> Result<()> { if line.is_empty() { warn!("Received empty line from {}. Closing connection.", peer_addr); - return Err(Error::ChannelStopped); + return Err(Error::ChannelStopped) } assert!(&line[(line.len() - 1)..] == "\n"); // Remove the \n character @@ -92,7 +92,7 @@ async fn process_user_input( if let Err(err) = connection.update(line, p2p.clone()).await { warn!("Connection error: {} for {}", err, peer_addr); - return Err(Error::ChannelStopped); + return Err(Error::ChannelStopped) } Ok(()) @@ -103,14 +103,14 @@ async fn start(executor: Arc>, options: ProgramOptions) -> Result<( Ok(listener) => listener, Err(err) => { error!("Bind listener failed: {}", err); - return Err(Error::OperationFailed); + return Err(Error::OperationFailed) } }; let local_addr = match listener.get_ref().local_addr() { Ok(addr) => addr, Err(err) => { error!("Failed to get local address: {}", err); - return Err(Error::OperationFailed); + return Err(Error::OperationFailed) } }; info!("Listening on {}", local_addr); @@ -177,7 +177,7 @@ async fn start(executor: Arc>, options: ProgramOptions) -> Result<( Ok((s, a)) => (s, a), Err(err) => { error!("Error listening for connections: {}", err); - return Err(Error::ServiceStopped); + return Err(Error::ServiceStopped) } }; info!("Accepted client: {}", peer_addr); @@ -196,7 +196,7 @@ struct JsonRpcInterface {} impl RequestHandler for JsonRpcInterface { async fn handle_request(&self, req: JsonRequest, _executor: Arc>) -> JsonResult { if req.params.as_array().is_none() { - return JsonResult::Err(jsonerr(InvalidParams, None, req.id)); + return JsonResult::Err(jsonerr(InvalidParams, None, req.id)) } debug!(target: "RPC", "--> {}", serde_json::to_string(&req).unwrap()); diff --git a/bin/map/src/main.rs b/bin/map/src/main.rs index 418d9368f..224fb41d6 100644 --- a/bin/map/src/main.rs +++ b/bin/map/src/main.rs @@ -227,7 +227,7 @@ async fn render( match k.unwrap() { Key::Char('q') => { terminal.clear()?; - return Ok(()); + return Ok(()) } Key::Char('j') => { view.id_list.next(); diff --git a/example/tree.rs b/example/tree.rs index 60e53d99a..a7770338b 100644 --- a/example/tree.rs +++ b/example/tree.rs @@ -1,7 +1,7 @@ +use group::ff::Field; use incrementalmerkletree::{bridgetree::BridgeTree, Frontier, Tree}; use pasta_curves::pallas; use rand::rngs::OsRng; -use group::ff::Field; use darkfi::{crypto::merkle_node::MerkleNode, Result}; @@ -24,4 +24,4 @@ fn main() -> Result<()> { assert_eq!(root1, root2); Ok(()) -} \ No newline at end of file +} diff --git a/src/crypto/constants/sinsemilla.rs b/src/crypto/constants/sinsemilla.rs index 5c5b8469f..ab0cc31bf 100644 --- a/src/crypto/constants/sinsemilla.rs +++ b/src/crypto/constants/sinsemilla.rs @@ -212,4 +212,4 @@ mod tests { assert_eq!(two_pow_k * inv_two_pow_k, pallas::Base::one()); } -} \ No newline at end of file +} diff --git a/src/crypto/note.rs b/src/crypto/note.rs index 817ff73b3..b9fe99eec 100644 --- a/src/crypto/note.rs +++ b/src/crypto/note.rs @@ -140,4 +140,4 @@ mod tests { assert_eq!(note.value, note2.value); assert_eq!(note.token_id, note2.token_id); } -} \ No newline at end of file +} diff --git a/src/crypto/proof.rs b/src/crypto/proof.rs index e67dcb961..74db16a94 100644 --- a/src/crypto/proof.rs +++ b/src/crypto/proof.rs @@ -112,8 +112,8 @@ mod tests { crypto::{keypair::PublicKey, mint_proof::create_mint_proof}, zk::circuit::MintContract, }; - use rand::rngs::OsRng; use group::ff::Field; + use rand::rngs::OsRng; #[test] fn test_proof_serialization() -> Result<()> { @@ -144,4 +144,4 @@ mod tests { Ok(()) } -} \ No newline at end of file +} diff --git a/src/crypto/schnorr.rs b/src/crypto/schnorr.rs index 994b43017..cf74c2185 100644 --- a/src/crypto/schnorr.rs +++ b/src/crypto/schnorr.rs @@ -79,4 +79,4 @@ mod tests { let public = PublicKey::from_secret(secret); assert!(public.verify(&message[..], &signature)); } -} \ No newline at end of file +} diff --git a/src/node/wallet/cashierdb.rs b/src/node/wallet/cashierdb.rs index 29d0c3e9f..25d4b8bb0 100644 --- a/src/node/wallet/cashierdb.rs +++ b/src/node/wallet/cashierdb.rs @@ -480,8 +480,8 @@ impl CashierDb { mod tests { use super::*; use crate::util::serial::serialize; - use rand::rngs::OsRng; use group::ff::Field; + use rand::rngs::OsRng; const WPASS: &str = "darkfi"; @@ -573,4 +573,4 @@ mod tests { Ok(()) } -} \ No newline at end of file +} diff --git a/src/node/wallet/walletdb.rs b/src/node/wallet/walletdb.rs index 1fa6738f5..9d03d7d8d 100644 --- a/src/node/wallet/walletdb.rs +++ b/src/node/wallet/walletdb.rs @@ -381,10 +381,10 @@ mod tests { merkle_node::MerkleNode, types::{DrkCoinBlind, DrkSerial, DrkValueBlind}, }; + use group::ff::Field; use incrementalmerkletree::{Frontier, Tree}; use pasta_curves::pallas; use rand::rngs::OsRng; - use group::ff::Field; const WPASS: &str = "darkfi"; @@ -500,4 +500,4 @@ mod tests { Ok(()) } -} \ No newline at end of file +}