From 43ef8b6e87048f7f28ddb4c2b97d7bf4fe853b90 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Mon, 5 Aug 2024 17:07:56 +0200 Subject: [PATCH] ref(iroh-net): Don't write the match as fully exhaustive (#2585) ## Description This makes it a bit earier to read. It's harder to figure out if thre are changes to the ConnectionType though, but let's assume that doesn't happen too often. ## Breaking Changes None ## Notes & open questions I'm open to other ways of structuring this code. Not entirely sure what the best shape would be. ## Change checklist - [x] Self-review. - [x] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [x] Tests if relevant. - [x] All breaking changes documented. --- iroh-net/src/magicsock/node_map/node_state.rs | 45 +++++++------------ 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/iroh-net/src/magicsock/node_map/node_state.rs b/iroh-net/src/magicsock/node_map/node_state.rs index 7a69b57117..375fb706d7 100644 --- a/iroh-net/src/magicsock/node_map/node_state.rs +++ b/iroh-net/src/magicsock/node_map/node_state.rs @@ -303,46 +303,31 @@ impl NodeState { // Update some metrics match (prev_typ, typ) { - (ConnectionType::Direct(_), ConnectionType::Direct(_)) => (), - (ConnectionType::Direct(_), ConnectionType::Relay(_)) => { - inc!(MagicsockMetrics, num_direct_conns_removed); - inc!(MagicsockMetrics, num_relay_conns_added); - } - (ConnectionType::Direct(_), ConnectionType::Mixed(_, _)) => { - inc!(MagicsockMetrics, num_direct_conns_removed); - inc!(MagicsockMetrics, num_relay_conns_added); - } - (ConnectionType::Direct(_), ConnectionType::None) => { - inc!(MagicsockMetrics, num_direct_conns_removed) - } - (ConnectionType::Relay(_), ConnectionType::Direct(_)) => { - inc!(MagicsockMetrics, num_direct_conns_added); - inc!(MagicsockMetrics, num_relay_conns_removed); - } - (ConnectionType::Relay(_), ConnectionType::Relay(_)) => (), - (ConnectionType::Relay(_), ConnectionType::Mixed(_, _)) => (), - (ConnectionType::Relay(_), ConnectionType::None) => { - inc!(MagicsockMetrics, num_relay_conns_removed) - } - (ConnectionType::Mixed(_, _), ConnectionType::Direct(_)) => { + (ConnectionType::Relay(_), ConnectionType::Direct(_)) + | (ConnectionType::Mixed(_, _), ConnectionType::Direct(_)) => { inc!(MagicsockMetrics, num_direct_conns_added); inc!(MagicsockMetrics, num_relay_conns_removed); } - (ConnectionType::Mixed(_, _), ConnectionType::Relay(_)) => (), - (ConnectionType::Mixed(_, _), ConnectionType::Mixed(_, _)) => (), - (ConnectionType::Mixed(_, _), ConnectionType::None) => { - inc!(MagicsockMetrics, num_relay_conns_removed) + (ConnectionType::Direct(_), ConnectionType::Relay(_)) + | (ConnectionType::Direct(_), ConnectionType::Mixed(_, _)) => { + inc!(MagicsockMetrics, num_direct_conns_removed); + inc!(MagicsockMetrics, num_relay_conns_added); } (ConnectionType::None, ConnectionType::Direct(_)) => { inc!(MagicsockMetrics, num_direct_conns_added) } - (ConnectionType::None, ConnectionType::Relay(_)) => { - inc!(MagicsockMetrics, num_relay_conns_added) + (ConnectionType::Direct(_), ConnectionType::None) => { + inc!(MagicsockMetrics, num_direct_conns_removed) } - (ConnectionType::None, ConnectionType::Mixed(_, _)) => { + (ConnectionType::None, ConnectionType::Relay(_)) + | (ConnectionType::None, ConnectionType::Mixed(_, _)) => { inc!(MagicsockMetrics, num_relay_conns_added) } - (ConnectionType::None, ConnectionType::None) => (), + (ConnectionType::Relay(_), ConnectionType::None) + | (ConnectionType::Mixed(_, _), ConnectionType::None) => { + inc!(MagicsockMetrics, num_relay_conns_removed) + } + _ => (), } } (best_addr, relay_url)