bin/ircd: fixing ping-pong reply which fixes occasional re-connection (#66)

This commit is contained in:
dasman
2022-02-18 03:58:29 -05:00
committed by GitHub
parent f6d80e36f8
commit 7da841e9e7
10 changed files with 24 additions and 19 deletions

View File

@@ -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)?;

View File

@@ -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<Executor<'_>>, 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<Executor<'_>>, 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<Executor<'_>>) -> 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());

View File

@@ -227,7 +227,7 @@ async fn render<B: Backend>(
match k.unwrap() {
Key::Char('q') => {
terminal.clear()?;
return Ok(());
return Ok(())
}
Key::Char('j') => {
view.id_list.next();

View File

@@ -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(())
}
}

View File

@@ -212,4 +212,4 @@ mod tests {
assert_eq!(two_pow_k * inv_two_pow_k, pallas::Base::one());
}
}
}

View File

@@ -140,4 +140,4 @@ mod tests {
assert_eq!(note.value, note2.value);
assert_eq!(note.token_id, note2.token_id);
}
}
}

View File

@@ -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(())
}
}
}

View File

@@ -79,4 +79,4 @@ mod tests {
let public = PublicKey::from_secret(secret);
assert!(public.verify(&message[..], &signature));
}
}
}

View File

@@ -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(())
}
}
}

View File

@@ -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(())
}
}
}