From df488563b280c63f5d74d5ac0fcb1a2cad489d55 Mon Sep 17 00:00:00 2001 From: stickies-v Date: Tue, 18 Jul 2023 10:07:41 -0600 Subject: [PATCH] GetLocal() type-safety, naming, const, and formatting cleanups Co-authored-by: Jon Atack --- src/net.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index d76874b2338..83440c2497f 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -148,30 +148,27 @@ uint16_t GetListenPort() // find 'best' local address for a particular peer [[nodiscard]] static bool GetLocal(CService& addr, const CNode& peer) { - if (!fListen) - return false; + if (!fListen) return false; int nBestScore = -1; int nBestReachability = -1; { LOCK(g_maplocalhost_mutex); - for (const auto& entry : mapLocalHost) - { + for (const auto& [local_addr, local_service_info] : mapLocalHost) { // For privacy reasons, don't advertise our privacy-network address // to other networks and don't advertise our other-network address // to privacy networks. - const Network our_net{entry.first.GetNetwork()}; + const Network our_net{local_addr.GetNetwork()}; const Network peers_net{peer.ConnectedThroughNetwork()}; if (our_net != peers_net && (our_net == NET_ONION || our_net == NET_I2P || peers_net == NET_ONION || peers_net == NET_I2P)) { continue; } - int nScore = entry.second.nScore; - int nReachability = entry.first.GetReachabilityFrom(peer.addr); - if (nReachability > nBestReachability || (nReachability == nBestReachability && nScore > nBestScore)) - { - addr = CService(entry.first, entry.second.nPort); + const int nScore{local_service_info.nScore}; + const int nReachability{local_addr.GetReachabilityFrom(peer.addr)}; + if (nReachability > nBestReachability || (nReachability == nBestReachability && nScore > nBestScore)) { + addr = CService{local_addr, local_service_info.nPort}; nBestReachability = nReachability; nBestScore = nScore; }