diff --git a/masq_lib/src/test_utils/ui_connection.rs b/masq_lib/src/test_utils/ui_connection.rs index 547e12880..952d8d928 100644 --- a/masq_lib/src/test_utils/ui_connection.rs +++ b/masq_lib/src/test_utils/ui_connection.rs @@ -99,8 +99,7 @@ impl UiConnection { Err(UiMessageError::PayloadError(message_body)) => { let payload_error = message_body .payload - .err() - .expect("PayloadError message body contained no payload error"); + .expect_err("PayloadError message body contained no payload error"); ReceiveResult::TransactionError(payload_error) } Err(e) => ReceiveResult::MarshalError((incoming_msg, e)), diff --git a/node/src/entry_dns/processing.rs b/node/src/entry_dns/processing.rs index c8c6a4a81..54e9b9610 100644 --- a/node/src/entry_dns/processing.rs +++ b/node/src/entry_dns/processing.rs @@ -5,6 +5,7 @@ use super::packet_facade::ResourceRecord; use masq_lib::logger::Logger; use std::convert::From; use std::convert::TryFrom; +use std::fmt::Write as _; use std::net::SocketAddr; use std::net::{Ipv4Addr, Ipv6Addr}; use std::time::Instant; @@ -124,7 +125,8 @@ fn write_log(from: &RequestRecord, to: &ResponseRecord, addr: &SocketAddr, logge Ok(c) => <&'static str>::from(c), Err(_) => UNKNOWN, }; - query_list += &format!( + let _ = write!( + query_list, "{}/{}/{}", RecordType::from(query.get_query_type()), class_string, diff --git a/node/src/neighborhood/dot_graph.rs b/node/src/neighborhood/dot_graph.rs index d173dae76..345afe077 100644 --- a/node/src/neighborhood/dot_graph.rs +++ b/node/src/neighborhood/dot_graph.rs @@ -2,6 +2,7 @@ use crate::sub_lib::cryptde::PublicKey; use crate::sub_lib::node_addr::NodeAddr; +use std::fmt::Write as _; pub trait DotRenderable { fn render(&self) -> String; @@ -25,17 +26,17 @@ pub struct NodeRenderable { impl DotRenderable for NodeRenderable { fn render(&self) -> String { let mut result = String::new(); - result.push_str(&format!("\"{}\"", self.public_key)); - result.push_str(&self.render_label()); + let _ = write!(result, "\"{}\"", self.public_key); + let _ = write!(result, "{}", &self.render_label()); if !self.is_present { - result.push_str(" [shape=none]") + let _ = write!(result, " [shape=none]"); } else if self.known_target { - result.push_str(" [shape=box]") + let _ = write!(result, " [shape=box]"); } if self.known_source { - result.push_str(" [style=filled]") + let _ = write!(result, " [style=filled]"); } - result.push(';'); + let _ = write!(result, ";"); result } } @@ -77,7 +78,7 @@ pub struct EdgeRenderable { impl DotRenderable for EdgeRenderable { fn render(&self) -> String { let mut result = String::new(); - result.push_str(&format!("\"{}\" -> \"{}\";", self.from, self.to)); + let _ = write!(result, "\"{}\" -> \"{}\";", self.from, self.to); result } } @@ -85,7 +86,7 @@ impl DotRenderable for EdgeRenderable { pub fn render_dot_graph(renderables: Vec>) -> String { let mut result = String::from("digraph db {"); for renderable in renderables { - result.push_str(&format!(" {}", renderable.render())) + let _ = write!(result, " {}", renderable.render()); } result.push_str(" }"); result diff --git a/node/src/neighborhood/gossip.rs b/node/src/neighborhood/gossip.rs index 4542c93a7..f5fbf6523 100644 --- a/node/src/neighborhood/gossip.rs +++ b/node/src/neighborhood/gossip.rs @@ -18,6 +18,7 @@ use std::convert::{TryFrom, TryInto}; use std::fmt::Debug; use std::fmt::Error; use std::fmt::Formatter; +use std::fmt::Write as _; use std::net::{IpAddr, SocketAddr}; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -97,37 +98,53 @@ impl TryFrom<&Value> for GossipNodeRecord { impl GossipNodeRecord { fn to_human_readable(&self) -> String { let mut human_readable = String::new(); - human_readable.push_str("\nGossipNodeRecord {"); + let _ = write!(human_readable, "\nGossipNodeRecord {{"); match NodeRecordInner_0v1::try_from(self) { Ok(nri) => { - human_readable.push_str("\n\tinner: NodeRecordInner_0v1 {"); - human_readable.push_str(&format!("\n\t\tpublic_key: {:?},", &nri.public_key)); - human_readable.push_str(&format!("\n\t\tnode_addr_opt: {:?},", self.node_addr_opt)); - human_readable - .push_str(&format!("\n\t\tearning_wallet: {:?},", nri.earning_wallet)); - human_readable.push_str(&format!("\n\t\trate_pack: {:?},", nri.rate_pack)); - human_readable.push_str(&format!( + let _ = write!(human_readable, "\n\tinner: NodeRecordInner_0v1 {{"); + let _ = write!(human_readable, "\n\t\tpublic_key: {:?},", &nri.public_key); + let _ = write!( + human_readable, + "\n\t\tnode_addr_opt: {:?},", + self.node_addr_opt + ); + let _ = write!( + human_readable, + "\n\t\tearning_wallet: {:?},", + nri.earning_wallet + ); + let _ = write!(human_readable, "\n\t\trate_pack: {:?},", nri.rate_pack); + let _ = write!( + human_readable, "\n\t\tneighbors: {:?},", nri.neighbors .clone() .into_iter() .collect::>() - )); - human_readable.push_str(&format!("\n\t\tversion: {:?},", nri.version)); - human_readable.push_str("\n\t},"); + ); + let _ = write!(human_readable, "\n\t\tversion: {:?},", nri.version); + let _ = write!(human_readable, "\n\t}},"); + } + Err(_e) => { + let _ = write!(human_readable, "\n\tinner: "); } - Err(_e) => human_readable.push_str("\n\tinner: "), }; - human_readable.push_str(&format!("\n\tnode_addr_opt: {:?},", self.node_addr_opt)); - human_readable.push_str(&format!( + let _ = write!( + human_readable, + "\n\tnode_addr_opt: {:?},", + self.node_addr_opt + ); + let _ = write!( + human_readable, "\n\tsigned_data:\n{:?}", self.signed_data.as_slice().hex_dump() - )); - human_readable.push_str(&format!( + ); + let _ = write!( + human_readable, "\n\tsignature:\n{:?}", self.signature.as_slice().hex_dump() - )); - human_readable.push_str("\n}"); + ); + let _ = write!(human_readable, "\n}}"); human_readable } } diff --git a/node/src/neighborhood/mod.rs b/node/src/neighborhood/mod.rs index 0c3070d95..2e5debafd 100644 --- a/node/src/neighborhood/mod.rs +++ b/node/src/neighborhood/mod.rs @@ -7,7 +7,6 @@ pub mod gossip_producer; pub mod neighborhood_database; pub mod node_record; -use std::cmp::Ordering; use std::convert::TryFrom; use std::net::SocketAddr; use std::path::PathBuf; @@ -895,8 +894,13 @@ impl Neighborhood { payload_size: usize, direction: RouteDirection, ) -> Result { - let route_opt = - self.best_route_segment(origin, target_opt, minimum_hop_count, payload_size, direction); + let route_opt = self.best_route_segment( + origin, + target_opt, + minimum_hop_count, + payload_size, + direction, + ); match route_opt { None => { let target_str = match target_opt { @@ -908,39 +912,10 @@ impl Neighborhood { minimum_hop_count, origin, target_component, target_str )) } - Some(route) => { - Ok(RouteSegment::new(route, target_component)) - } + Some(route) => Ok(RouteSegment::new(route, target_component)), } } - fn sort_routes_by_desirable_exit_nodes(&self, node_seqs: &mut [Vec<&PublicKey>]) { - if node_seqs.is_empty() { - panic!("Unable to sort routes by desirable exit nodes: Missing routes."); - } - let get_the_exit_nodes_desirable_flag = |vec: &Vec<&PublicKey>| -> Option { - vec.last() - .map(|pk| - self.neighborhood_database - .node_by_key(pk) - .unwrap_or_else(|| panic!("Unable to sort routes by desirable exit nodes: Missing NodeRecord for public key: [{}]", pk)) - ).map(|node| node.is_desirable()) - }; - - node_seqs.sort_by(|vec1: &Vec<&PublicKey>, vec2: &Vec<&PublicKey>| { - if vec1.is_empty() || vec2.is_empty() { - panic!("Unable to sort routes by desirable exit nodes: Missing route segments.") - } - let is_desirable1 = get_the_exit_nodes_desirable_flag(vec1); - let is_desirable2 = get_the_exit_nodes_desirable_flag(vec2); - match (is_desirable1, is_desirable2) { - (Some(true), Some(false)) => Ordering::Less, - (Some(false), Some(true)) => Ordering::Greater, - _ => Ordering::Equal, - } - }); - } - fn make_expected_services( &self, segment: &RouteSegment, @@ -1022,14 +997,29 @@ impl Neighborhood { } } - fn compute_undesirability (&self, node_record: &NodeRecord, payload_size: usize, link_type: LinkType) -> i64 { + fn compute_undesirability( + &self, + node_record: &NodeRecord, + payload_size: usize, + link_type: LinkType, + ) -> i64 { let (per_byte, per_cores) = match link_type { - LinkType::Relay => (node_record.inner.rate_pack.routing_byte_rate, node_record.inner.rate_pack.routing_service_rate), - LinkType::Exit => (node_record.inner.rate_pack.exit_byte_rate, node_record.inner.rate_pack.exit_service_rate), + LinkType::Relay => ( + node_record.inner.rate_pack.routing_byte_rate, + node_record.inner.rate_pack.routing_service_rate, + ), + LinkType::Exit => ( + node_record.inner.rate_pack.exit_byte_rate, + node_record.inner.rate_pack.exit_service_rate, + ), LinkType::Origin => (0, 0), }; let rate_undesirability = per_cores as i64 + (per_byte as i64 * payload_size as i64); - let desirable_undesirability = if node_record.metadata.desirable {0} else {100_000_000}; + let desirable_undesirability = if node_record.metadata.desirable { + 0 + } else { + 100_000_000 + }; rate_undesirability + desirable_undesirability } @@ -1060,7 +1050,7 @@ impl Neighborhood { // target in hops_remaining or more hops with no cycles, or from the origin hops_remaining hops // out into the MASQ Network. No round trips; if you want a round trip, call this method twice. // If the return value is None, no qualifying route was found. - fn best_route_segment<'a> ( + fn best_route_segment<'a>( &'a self, source: &'a PublicKey, target_opt: Option<&'a PublicKey>, @@ -1069,21 +1059,22 @@ impl Neighborhood { direction: RouteDirection, ) -> Option> { let mut minimum_undesirability = i64::MAX; - self.complete_routes_inner ( + self.complete_routes_inner( vec![source], 0, target_opt, minimum_hops, payload_size, direction, - &mut minimum_undesirability + &mut minimum_undesirability, ) .into_iter() - .filter (|cr| cr.undesirability <= minimum_undesirability) - .map (|cr| cr.nodes) - .nth(0) + .filter(|cr| cr.undesirability <= minimum_undesirability) + .map(|cr| cr.nodes) + .next() } + #[allow(clippy::too_many_arguments)] fn complete_routes_inner<'a>( &'a self, prefix: Vec<&'a PublicKey>, @@ -1138,8 +1129,14 @@ impl Neighborhood { hops_remaining - 1 }; - let new_undesirability = self.compute_new_undesirability(&node_record, - undesirability, target_opt, hops_remaining, payload_size, direction); + let new_undesirability = self.compute_new_undesirability( + node_record, + undesirability, + target_opt, + hops_remaining, + payload_size, + direction, + ); self.complete_routes_inner( new_prefix.clone(), @@ -1148,7 +1145,7 @@ impl Neighborhood { new_hops_remaining, payload_size, direction, - minimum_undesirability + minimum_undesirability, ) }) .collect() @@ -1162,17 +1159,18 @@ impl Neighborhood { target_opt: Option<&PublicKey>, hops_remaining: usize, payload_size: usize, - direction: RouteDirection + direction: RouteDirection, ) -> i64 { let link_type = match (direction, target_opt) { - (RouteDirection::Over, None) if hops_remaining <= 0 => LinkType::Exit, + (RouteDirection::Over, None) if hops_remaining == 0 => LinkType::Exit, (RouteDirection::Over, _) => LinkType::Relay, - (RouteDirection::Back, Some(target)) if &node_record.inner.public_key == target => LinkType::Origin, + (RouteDirection::Back, Some(target)) if &node_record.inner.public_key == target => { + LinkType::Origin + } (RouteDirection::Back, _) => LinkType::Relay, }; - let node_undesirability = self.compute_undesirability(&node_record, payload_size, link_type); - let new_undesirability = undesirability + node_undesirability; - new_undesirability + let node_undesirability = self.compute_undesirability(node_record, payload_size, link_type); + undesirability + node_undesirability } fn handle_gossip_reply( @@ -1336,8 +1334,11 @@ struct ComputedRouteSegment<'a> { } impl<'a> ComputedRouteSegment<'a> { - pub fn new (nodes: Vec<&'a PublicKey>, undesirability: i64) -> Self { - Self {nodes, undesirability} + pub fn new(nodes: Vec<&'a PublicKey>, undesirability: i64) -> Self { + Self { + nodes, + undesirability, + } } } @@ -2234,102 +2235,6 @@ mod tests { assert_eq!(expected_response, result); } - #[test] - fn sort_routes_by_desirable_exit_nodes() { - let mut subject = make_standard_subject(); - - let us = subject.neighborhood_database.root().clone(); - let routing_node = make_node_record(0000, true); - let desirable_node = make_node_record(1111, false); - let mut undesirable_node = make_node_record(2222, false); - undesirable_node.set_desirable(false); - - subject - .neighborhood_database - .add_node(routing_node.clone()) - .unwrap(); - subject - .neighborhood_database - .add_node(undesirable_node.clone()) - .unwrap(); - subject - .neighborhood_database - .add_node(desirable_node.clone()) - .unwrap(); - - let mut node_sequences = Vec::new(); - node_sequences.push(vec![ - us.public_key(), - routing_node.public_key(), - undesirable_node.public_key(), - ]); - node_sequences.push(vec![ - us.public_key(), - routing_node.public_key(), - desirable_node.public_key(), - ]); - - subject.sort_routes_by_desirable_exit_nodes(&mut node_sequences); - - assert_eq!(desirable_node.public_key(), node_sequences[0][2]); - assert_eq!(undesirable_node.public_key(), node_sequences[1][2]); - } - - #[test] - #[should_panic(expected = "Unable to sort routes by desirable exit nodes: Missing routes.")] - fn sort_routes_by_desirable_exit_nodes_panics_with_empty_node_sequences() { - let subject = make_standard_subject(); - - let mut node_sequences: Vec> = Vec::new(); - subject.sort_routes_by_desirable_exit_nodes(&mut node_sequences); - } - - #[test] - #[should_panic( - expected = "Unable to sort routes by desirable exit nodes: Missing route segments." - )] - fn sort_routes_by_desirable_exit_nodes_panics_with_the_first_route_segment_empty() { - let subject = make_standard_subject(); - - let mut node_sequences: Vec> = Vec::new(); - let public_key = &PublicKey::from(&b"1234"[..]); - node_sequences.push(vec![]); - node_sequences.push(vec![public_key]); - - subject.sort_routes_by_desirable_exit_nodes(&mut node_sequences); - } - - #[test] - #[should_panic( - expected = "Unable to sort routes by desirable exit nodes: Missing route segments." - )] - fn sort_routes_by_desirable_exit_nodes_panics_with_the_second_route_segment_empty() { - let subject = make_standard_subject(); - - let mut node_sequences: Vec> = Vec::new(); - let public_key = &PublicKey::from(&b"1234"[..]); - node_sequences.push(vec![public_key]); - node_sequences.push(vec![]); - - subject.sort_routes_by_desirable_exit_nodes(&mut node_sequences); - } - - #[test] - #[should_panic( - expected = "Unable to sort routes by desirable exit nodes: Missing NodeRecord for public key: [MTIzNA]" - )] - fn sort_routes_by_desirable_exit_nodes_panics_when_node_record_is_missing() { - let subject = make_standard_subject(); - - let mut node_sequences: Vec> = Vec::new(); - let public_key = &PublicKey::from(&b"1234"[..]); - node_sequences.push(vec![public_key]); - node_sequences.push(vec![public_key]); - println!("{}", public_key); - - subject.sort_routes_by_desirable_exit_nodes(&mut node_sequences); - } - #[test] fn compose_route_query_response_returns_an_error_when_route_segment_is_empty() { let mut subject = make_standard_subject(); @@ -2426,11 +2331,13 @@ mod tests { ) .unwrap(); - let route_request_1 = route_sub.send(RouteQueryMessage::data_indefinite_route_request(2, 1000)); + let route_request_1 = + route_sub.send(RouteQueryMessage::data_indefinite_route_request(2, 1000)); let _ = set_wallet_sub.try_send(SetConsumingWalletMessage { wallet: expected_new_wallet, }); - let route_request_2 = route_sub.send(RouteQueryMessage::data_indefinite_route_request(2, 2000)); + let route_request_2 = + route_sub.send(RouteQueryMessage::data_indefinite_route_request(2, 2000)); System::current().stop(); system.run(); @@ -2597,37 +2504,44 @@ mod tests { }; let designate_root_node = |db: &mut NeighborhoodDatabase, key| { let root_node_key = db.root().public_key().clone(); - let node = db.node_by_key (key).unwrap().clone(); + let node = db.node_by_key(key).unwrap().clone(); db.root_mut().inner = node.inner.clone(); db.root_mut().metadata = node.metadata.clone(); - db.remove_node (&root_node_key); + db.remove_node(&root_node_key); }; - let (a, b, c, d, e) = make_row (db); - let (f, g, h, i, j) = make_row (db); - let (k, l, m, n, o) = make_row (db); - let (p, q, r, s, t) = make_row (db); - let (u, v, w, x, y) = make_row (db); - join_rows (db, (&a, &b, &c, &d, &e), (&f, &g, &h, &i, &j)); - join_rows (db, (&f, &g, &h, &i, &j), (&k, &l, &m, &n, &o)); - join_rows (db, (&k, &l, &m, &n, &o), (&p, &q, &r, &s, &t)); - join_rows (db, (&p, &q, &r, &s, &t), (&u, &v, &w, &x, &y)); - designate_root_node (db, &l); + let (a, b, c, d, e) = make_row(db); + let (f, g, h, i, j) = make_row(db); + let (k, l, m, n, o) = make_row(db); + let (p, q, r, s, t) = make_row(db); + let (u, v, w, x, y) = make_row(db); + join_rows(db, (&a, &b, &c, &d, &e), (&f, &g, &h, &i, &j)); + join_rows(db, (&f, &g, &h, &i, &j), (&k, &l, &m, &n, &o)); + join_rows(db, (&k, &l, &m, &n, &o), (&p, &q, &r, &s, &t)); + join_rows(db, (&p, &q, &r, &s, &t), (&u, &v, &w, &x, &y)); + designate_root_node(db, &l); let before = Instant::now(); // All the target-designated routes from L to N - let route = subject.best_route_segment(&l, Some (&n), - 3, 10000, RouteDirection::Back).unwrap(); + let route = subject + .best_route_segment(&l, Some(&n), 3, 10000, RouteDirection::Back) + .unwrap(); let after = Instant::now(); let northern_route = vec![&l, &g, &h, &i, &n]; let southern_route = vec![&l, &q, &r, &s, &n]; - assert! ((route == northern_route) || (route == southern_route), + assert!( + (route == northern_route) || (route == southern_route), "Route should have been {:?} or {:?}, but was {:?}", - northern_route, southern_route, route + northern_route, + southern_route, + route ); let interval = after.duration_since(before); - assert! (interval.as_millis() <= 100, "Should have calculated route in <=100ms, but was {}ms", - interval.as_millis()); + assert!( + interval.as_millis() <= 100, + "Should have calculated route in <=100ms, but was {}ms", + interval.as_millis() + ); } /* @@ -2665,12 +2579,12 @@ mod tests { routing_byte_rate: 100, routing_service_rate: 200, exit_byte_rate: 123456, - exit_service_rate: 234567 + exit_service_rate: 234567, }; let result = subject.compute_undesirability(&node_record, 10000, LinkType::Relay); - assert_eq! (result, 200 + (100 * 10000)); + assert_eq!(result, 200 + (100 * 10000)); } #[test] @@ -2682,12 +2596,12 @@ mod tests { routing_byte_rate: 123456, routing_service_rate: 234567, exit_byte_rate: 100, - exit_service_rate: 200 + exit_service_rate: 200, }; let result = subject.compute_undesirability(&node_record, 10000, LinkType::Exit); - assert_eq! (result, 200 + (100 * 10000)); + assert_eq!(result, 200 + (100 * 10000)); } #[test] @@ -2699,12 +2613,12 @@ mod tests { routing_byte_rate: 123456, routing_service_rate: 234567, exit_byte_rate: 345678, - exit_service_rate: 456789 + exit_service_rate: 456789, }; let result = subject.compute_undesirability(&node_record, 10000, LinkType::Origin); - assert_eq! (result, 0); + assert_eq!(result, 0); } #[test] @@ -4269,74 +4183,76 @@ mod tests { } /* - For the next two tests, the database looks like this: - - +---A---+ - | | - O X - | | - +---B---+ - - O is the originating Node, X is the exit Node. Minimum hop count is 2. - Node A offers low per-packet rates and high per-byte rates; Node B offers - low per-byte rates and high per-packet rates. Large packets should prefer - route O -> A -> X -> A -> O; small packets should prefer route - O -> B -> X -> B -> O. - */ + For the next two tests, the database looks like this: + + +---A---+ + | | + O X + | | + +---B---+ + + O is the originating Node, X is the exit Node. Minimum hop count is 2. + Node A offers low per-packet rates and high per-byte rates; Node B offers + low per-byte rates and high per-packet rates. Large packets should prefer + route O -> A -> X -> A -> O; small packets should prefer route + O -> B -> X -> B -> O. + */ #[test] fn handle_route_query_message_prefers_low_service_fees_for_small_packet() { - check_fee_preference (100, true); + check_fee_preference(100, true); } #[test] fn handle_route_query_message_prefers_low_byte_fees_for_large_packet() { - check_fee_preference (100_000, false); + check_fee_preference(100_000, false); } - fn check_fee_preference (payload_size: usize, a_not_b: bool) { + fn check_fee_preference(payload_size: usize, a_not_b: bool) { let mut subject = make_standard_subject(); let db = &mut subject.neighborhood_database; let o = &db.root().public_key().clone(); - let a = &db.add_node (make_node_record(2345, true)).unwrap(); - let b = &db.add_node (make_node_record(3456, true)).unwrap(); - let x = &db.add_node (make_node_record(4567, true)).unwrap(); + let a = &db.add_node(make_node_record(2345, true)).unwrap(); + let b = &db.add_node(make_node_record(3456, true)).unwrap(); + let x = &db.add_node(make_node_record(4567, true)).unwrap(); db.add_arbitrary_full_neighbor(o, a); db.add_arbitrary_full_neighbor(a, x); db.add_arbitrary_full_neighbor(x, b); db.add_arbitrary_full_neighbor(b, o); - db.node_by_key_mut (a).unwrap().inner.rate_pack = RatePack { - routing_byte_rate: 100, // high - routing_service_rate: 1000, // low + db.node_by_key_mut(a).unwrap().inner.rate_pack = RatePack { + routing_byte_rate: 100, // high + routing_service_rate: 1000, // low exit_byte_rate: 0, - exit_service_rate: 0 + exit_service_rate: 0, }; - db.node_by_key_mut (b).unwrap().inner.rate_pack = RatePack { + db.node_by_key_mut(b).unwrap().inner.rate_pack = RatePack { routing_byte_rate: 1, // low routing_service_rate: 100_000, // high exit_byte_rate: 0, - exit_service_rate: 0 + exit_service_rate: 0, }; - let response = subject.handle_route_query_message (RouteQueryMessage { - target_key_opt: Some (x.clone()), - target_component: Component::ProxyClient, - minimum_hop_count: 2, - return_component_opt: Some (Component::ProxyServer), - payload_size - }).unwrap(); + let response = subject + .handle_route_query_message(RouteQueryMessage { + target_key_opt: Some(x.clone()), + target_component: Component::ProxyClient, + minimum_hop_count: 2, + return_component_opt: Some(Component::ProxyServer), + payload_size, + }) + .unwrap(); let (over, back) = match response.expected_services { - ExpectedServices::OneWay(_) => panic! ("Expecting RoundTrip"), + ExpectedServices::OneWay(_) => panic!("Expecting RoundTrip"), ExpectedServices::RoundTrip(o, b, _) => (o[1].clone(), b[1].clone()), }; let extract_key = |es: ExpectedService| match es { ExpectedService::Routing(pk, _, _) => pk, - x => panic! ("Expecting Routing, found {:?}", x), + x => panic!("Expecting Routing, found {:?}", x), }; - let expected_relay_key = if a_not_b {a.clone()} else {b.clone()}; - assert_eq! (extract_key (over), expected_relay_key); - assert_eq! (extract_key (back), expected_relay_key); + let expected_relay_key = if a_not_b { a.clone() } else { b.clone() }; + assert_eq!(extract_key(over), expected_relay_key); + assert_eq!(extract_key(back), expected_relay_key); } #[test] diff --git a/node/src/node_configurator/configurator.rs b/node/src/node_configurator/configurator.rs index a8f0a9176..e315e225f 100644 --- a/node/src/node_configurator/configurator.rs +++ b/node/src/node_configurator/configurator.rs @@ -708,7 +708,7 @@ impl Configurator { ) -> Result { let password: Option = None; //prepared for an upgrade with parameters requiring the password - let _ = match password { + match password { None => { if "gas-price" == &msg.name { Self::set_gas_price(msg.value, persist_config)?; diff --git a/node/src/proxy_server/mod.rs b/node/src/proxy_server/mod.rs index 755af3ac7..0e595b5a2 100644 --- a/node/src/proxy_server/mod.rs +++ b/node/src/proxy_server/mod.rs @@ -509,7 +509,7 @@ impl ProxyServer { route_source .send(RouteQueryMessage::data_indefinite_route_request( minimum_hop_count, - payload.sequenced_packet.data.len() + payload.sequenced_packet.data.len(), )) .then(move |route_result| { match route_result { @@ -1219,7 +1219,10 @@ mod tests { ); let recording = neighborhood_recording_arc.lock().unwrap(); let record = recording.get_record::(0); - assert_eq!(record, &RouteQueryMessage::data_indefinite_route_request(0, 47)); + assert_eq!( + record, + &RouteQueryMessage::data_indefinite_route_request(0, 47) + ); let recording = proxy_server_recording_arc.lock().unwrap(); assert_eq!(recording.len(), 0); } @@ -2096,7 +2099,10 @@ mod tests { assert_eq!(record, &expected_pkg); let recording = neighborhood_recording_arc.lock().unwrap(); let record = recording.get_record::(0); - assert_eq!(record, &RouteQueryMessage::data_indefinite_route_request(3, 47)); + assert_eq!( + record, + &RouteQueryMessage::data_indefinite_route_request(3, 47) + ); } #[test] @@ -2661,7 +2667,10 @@ mod tests { assert_eq!(record, &expected_msg); let recording = neighborhood_recording_arc.lock().unwrap(); let record = recording.get_record::(0); - assert_eq!(record, &RouteQueryMessage::data_indefinite_route_request(3, 47)); + assert_eq!( + record, + &RouteQueryMessage::data_indefinite_route_request(3, 47) + ); TestLogHandler::new() .exists_log_containing("ERROR: ProxyServer: Failed to find route to nowhere.com"); } @@ -2792,7 +2801,10 @@ mod tests { assert_eq!(record, &expected_msg); let recording = neighborhood_recording_arc.lock().unwrap(); let record = recording.get_record::(0); - assert_eq!(record, &RouteQueryMessage::data_indefinite_route_request(3, 47)); + assert_eq!( + record, + &RouteQueryMessage::data_indefinite_route_request(3, 47) + ); TestLogHandler::new() .exists_log_containing("ERROR: ProxyServer: Failed to find route to nowhere.com"); } diff --git a/node/src/sub_lib/neighborhood.rs b/node/src/sub_lib/neighborhood.rs index bc4dc7df2..0a7a999cd 100644 --- a/node/src/sub_lib/neighborhood.rs +++ b/node/src/sub_lib/neighborhood.rs @@ -245,7 +245,7 @@ fn first_dividing(descriptor: &str) -> Result<(&str, &str), String> { CENTRAL_DELIMITER, DescriptorParsingError::CentralDelimiterProbablyMissing(descriptor), )?; - let _ = approx_position_assertion(descriptor, &halves)?; + approx_position_assertion(descriptor, &halves)?; Ok((halves[0], halves[1])) } @@ -438,7 +438,10 @@ impl Message for RouteQueryMessage { } impl RouteQueryMessage { - pub fn data_indefinite_route_request(minimum_hop_count: usize, payload_size: usize) -> RouteQueryMessage { + pub fn data_indefinite_route_request( + minimum_hop_count: usize, + payload_size: usize, + ) -> RouteQueryMessage { RouteQueryMessage { target_key_opt: None, target_component: Component::ProxyClient, diff --git a/node/src/sub_lib/versioned_data.rs b/node/src/sub_lib/versioned_data.rs index cae03784e..c0ef2c6ed 100644 --- a/node/src/sub_lib/versioned_data.rs +++ b/node/src/sub_lib/versioned_data.rs @@ -341,7 +341,7 @@ impl Migrations { #[macro_export] macro_rules! dv { ($j:expr, $n:expr) => { - crate::sub_lib::versioned_data::DataVersion::new($j, $n) + $crate::sub_lib::versioned_data::DataVersion::new($j, $n) }; } @@ -370,16 +370,16 @@ macro_rules! migrate_item { ($fv:expr, $ft:ty, $tv:expr, $tt:ty, $mt:ident, $b:block) => { #[allow(non_camel_case_types)] struct $mt {} - impl crate::sub_lib::versioned_data::MigrationStep for $mt { + impl $crate::sub_lib::versioned_data::MigrationStep for $mt { fn migrate( &self, data: Vec, - ) -> Result, crate::sub_lib::versioned_data::StepError> { + ) -> Result, $crate::sub_lib::versioned_data::StepError> { let in_item = match serde_cbor::de::from_slice::<$ft>(&data) { Ok(item) => item, Err(_) => { return Err( - crate::sub_lib::versioned_data::StepError::DeserializationError( + $crate::sub_lib::versioned_data::StepError::DeserializationError( $fv, $tv, "Fibble".to_string(), @@ -387,7 +387,7 @@ macro_rules! migrate_item { ) } }; - let result: Result<$tt, crate::sub_lib::versioned_data::StepError> = $b(in_item); + let result: Result<$tt, $crate::sub_lib::versioned_data::StepError> = $b(in_item); match result { Ok(out_item) => { Ok(serde_cbor::ser::to_vec(&out_item).expect("Serialization failed")) @@ -395,7 +395,7 @@ macro_rules! migrate_item { Err(e) => Err(e), } } - fn dup(&self) -> Box { + fn dup(&self) -> Box { Box::new($mt {}) } } @@ -425,16 +425,16 @@ macro_rules! migrate_value { #[allow(non_camel_case_types)] #[allow(clippy::upper_case_acronyms)] struct $mt {} - impl crate::sub_lib::versioned_data::MigrationStep for $mt { + impl $crate::sub_lib::versioned_data::MigrationStep for $mt { fn migrate( &self, data: Vec, - ) -> Result, crate::sub_lib::versioned_data::StepError> { + ) -> Result, $crate::sub_lib::versioned_data::StepError> { let value: serde_cbor::Value = match serde_cbor::de::from_slice(&data) { Ok(v) => v, Err(_) => { return Err( - crate::sub_lib::versioned_data::StepError::DeserializationError( + $crate::sub_lib::versioned_data::StepError::DeserializationError( FUTURE_VERSION, $tv, "Wampum".to_string(), @@ -442,7 +442,7 @@ macro_rules! migrate_value { ) } }; - let result: Result<$tt, crate::sub_lib::versioned_data::StepError> = $b(value); + let result: Result<$tt, $crate::sub_lib::versioned_data::StepError> = $b(value); match result { Ok(out_item) => { Ok(serde_cbor::ser::to_vec(&out_item).expect("Serialization failed")) @@ -450,7 +450,7 @@ macro_rules! migrate_value { Err(e) => Err(e), } } - fn dup(&self) -> Box { + fn dup(&self) -> Box { Box::new($mt {}) } }