mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-23 23:27:21 +01:00
GetLocal() type-safety, naming, const, and formatting cleanups
Co-authored-by: Jon Atack <jon@atack.com>
This commit is contained in:
parent
fb4265747c
commit
df488563b2
1 changed files with 7 additions and 10 deletions
17
src/net.cpp
17
src/net.cpp
|
@ -148,30 +148,27 @@ uint16_t GetListenPort()
|
||||||
// find 'best' local address for a particular peer
|
// find 'best' local address for a particular peer
|
||||||
[[nodiscard]] static bool GetLocal(CService& addr, const CNode& peer)
|
[[nodiscard]] static bool GetLocal(CService& addr, const CNode& peer)
|
||||||
{
|
{
|
||||||
if (!fListen)
|
if (!fListen) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
int nBestScore = -1;
|
int nBestScore = -1;
|
||||||
int nBestReachability = -1;
|
int nBestReachability = -1;
|
||||||
{
|
{
|
||||||
LOCK(g_maplocalhost_mutex);
|
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
|
// For privacy reasons, don't advertise our privacy-network address
|
||||||
// to other networks and don't advertise our other-network address
|
// to other networks and don't advertise our other-network address
|
||||||
// to privacy networks.
|
// to privacy networks.
|
||||||
const Network our_net{entry.first.GetNetwork()};
|
const Network our_net{local_addr.GetNetwork()};
|
||||||
const Network peers_net{peer.ConnectedThroughNetwork()};
|
const Network peers_net{peer.ConnectedThroughNetwork()};
|
||||||
if (our_net != peers_net &&
|
if (our_net != peers_net &&
|
||||||
(our_net == NET_ONION || our_net == NET_I2P ||
|
(our_net == NET_ONION || our_net == NET_I2P ||
|
||||||
peers_net == NET_ONION || peers_net == NET_I2P)) {
|
peers_net == NET_ONION || peers_net == NET_I2P)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
int nScore = entry.second.nScore;
|
const int nScore{local_service_info.nScore};
|
||||||
int nReachability = entry.first.GetReachabilityFrom(peer.addr);
|
const int nReachability{local_addr.GetReachabilityFrom(peer.addr)};
|
||||||
if (nReachability > nBestReachability || (nReachability == nBestReachability && nScore > nBestScore))
|
if (nReachability > nBestReachability || (nReachability == nBestReachability && nScore > nBestScore)) {
|
||||||
{
|
addr = CService{local_addr, local_service_info.nPort};
|
||||||
addr = CService(entry.first, entry.second.nPort);
|
|
||||||
nBestReachability = nReachability;
|
nBestReachability = nReachability;
|
||||||
nBestScore = nScore;
|
nBestScore = nScore;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue