From 6f4c6d17a9b8e71b35f62f57e6eb2aab851dbf22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojte=CC=8Cch=20Parka=CC=81n?= Date: Fri, 1 Nov 2024 10:55:38 +0100 Subject: [PATCH] formatting and remove unnecesary let --- node/src/neighborhood/gossip_acceptor.rs | 32 ++++++++++++++++++------ node/src/neighborhood/mod.rs | 5 ++-- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/node/src/neighborhood/gossip_acceptor.rs b/node/src/neighborhood/gossip_acceptor.rs index f8a6e200e..e47661037 100644 --- a/node/src/neighborhood/gossip_acceptor.rs +++ b/node/src/neighborhood/gossip_acceptor.rs @@ -165,7 +165,13 @@ impl GossipHandler for DebutHandler { source_node_addr, ); } - if let Ok(result) = self.try_accept_debut(cryptde, database, &source_agr, gossip_source, neighborhood_metadata.exit_tools_opt) { + if let Ok(result) = self.try_accept_debut( + cryptde, + database, + &source_agr, + gossip_source, + neighborhood_metadata.exit_tools_opt, + ) { return result; } debug!(self.logger, "Seeking neighbor for Pass"); @@ -276,7 +282,7 @@ impl DebutHandler { let mut debuting_node = NodeRecord::from(debuting_agr); match exit_tools_opt { Some(exit_tools) => exit_tools.assign_nodes_country_undesirability(&mut debuting_node), - None => () + None => (), } // TODO 468 make debuting_node mut and add country_undesirability to its metadata @@ -693,7 +699,12 @@ impl GossipHandler for IntroductionHandler { .expect("IP Address not found for the Node Addr.") .ip_addr(); // TODO 468 pass the NeighborhoodMetadata into update_database - match self.update_database(database, cryptde, introducer, neighborhood_metadata.exit_tools_opt) { + match self.update_database( + database, + cryptde, + introducer, + neighborhood_metadata.exit_tools_opt, + ) { Ok(_) => (), Err(e) => { return GossipAcceptanceResult::Ban(format!( @@ -853,7 +864,7 @@ impl IntroductionHandler { database: &mut NeighborhoodDatabase, cryptde: &dyn CryptDE, introducer: AccessibleGossipRecord, - exit_tools_opt: Option + exit_tools_opt: Option, ) -> Result { let introducer_key = introducer.inner.public_key.clone(); match database.node_by_key_mut(&introducer_key) { @@ -881,7 +892,9 @@ impl IntroductionHandler { let mut new_introducer = NodeRecord::from(introducer); //TODO 468 add country undesirability match exit_tools_opt { - Some(exit_tools) => exit_tools.assign_nodes_country_undesirability(&mut new_introducer), + Some(exit_tools) => { + exit_tools.assign_nodes_country_undesirability(&mut new_introducer) + } None => (), } //TODO probably make one function to use on all places @@ -1394,7 +1407,9 @@ mod tests { use crate::neighborhood::gossip_producer::GossipProducer; use crate::neighborhood::gossip_producer::GossipProducerReal; use crate::neighborhood::node_record::NodeRecord; - use crate::neighborhood::{COUNTRY_UNDESIRABILITY_FACTOR, ExitPreference, ExitTools, UNREACHABLE_COUNTRY_PENALTY}; + use crate::neighborhood::{ + ExitPreference, ExitTools, COUNTRY_UNDESIRABILITY_FACTOR, UNREACHABLE_COUNTRY_PENALTY, + }; use crate::sub_lib::cryptde_null::CryptDENull; use crate::sub_lib::neighborhood::{ ConnectionProgressEvent, ConnectionProgressMessage, ExitLocation, @@ -3108,7 +3123,10 @@ Length: 24 (0x18) bytes let reference_node = dest_db.node_by_key_mut(debut_node.public_key()).unwrap(); debut_node.metadata.last_update = reference_node.metadata.last_update; debut_node.resign(); - assert_eq!(reference_node.metadata.country_undesirability, UNREACHABLE_COUNTRY_PENALTY); + assert_eq!( + reference_node.metadata.country_undesirability, + UNREACHABLE_COUNTRY_PENALTY + ); reference_node.metadata.country_undesirability = 0u32; assert_node_records_eq(reference_node, &debut_node, before, after); } diff --git a/node/src/neighborhood/mod.rs b/node/src/neighborhood/mod.rs index 670185fb5..2d44d21af 100644 --- a/node/src/neighborhood/mod.rs +++ b/node/src/neighborhood/mod.rs @@ -1587,7 +1587,7 @@ impl Neighborhood { &mut self, message: &UiSetExitLocationRequest, ) -> Vec { - let exit_location_vec = message + message .to_owned() .exit_locations .into_iter() @@ -1600,8 +1600,7 @@ impl Neighborhood { priority: cc.priority, } }) - .collect(); - exit_location_vec + .collect() } fn handle_gossip_reply(