Skip to content

Commit a4e5f4d

Browse files
Merge #6255: backport: merge bitcoin#24531, #25500, #25814, #25962, #26888, #27264, #27257, #27324, #27374, #27467, #27411, partial bitcoin#25472 (networking backports: part 8)
c38544a merge bitcoin#27411: Restrict self-advertisements with privacy networks to avoid fingerprinting (Kittywhiskers Van Gogh) 8b43345 merge bitcoin#27467: skip netgroup diversity follow-up (Kittywhiskers Van Gogh) a584c21 merge bitcoin#27374: skip netgroup diversity of new connections for tor/i2p/cjdns (Kittywhiskers Van Gogh) 7c95868 merge bitcoin#27324: bitcoin#27257 follow-ups (Kittywhiskers Van Gogh) 72fef41 merge bitcoin#27257: End friendship of CNode, CConnman and ConnmanTestMsg (Kittywhiskers Van Gogh) 31c9803 merge bitcoin#27264: Improve diversification of new connections (Kittywhiskers Van Gogh) 63c579a merge bitcoin#26888: simplify the call to vProcessMsg.splice() (Kittywhiskers Van Gogh) b05fece merge bitcoin#25962: Add CNodeOptions and increase constness (Kittywhiskers Van Gogh) 2e4e584 merge bitcoin#25814: simplify GetLocalAddress() (Kittywhiskers Van Gogh) f09d632 partial bitcoin#25472: Increase MS Visual Studio minimum version (Kittywhiskers Van Gogh) aba1b26 merge bitcoin#25500: Move inbound eviction logic to its own translation unit (Kittywhiskers Van Gogh) d57bcbe merge bitcoin#24531: Use designated initializers (Kittywhiskers Van Gogh) Pull request description: ## Additional Information * Dependent on dashpay/dash#6254 * When backporting [bitcoin#27411](bitcoin/bitcoin#27411), the `CNetAddr*` variant of `GetLocal()` was not removed (upstream it was replaced by the `CNode&` variant with additional checks that rely on fields in `CNode`) as `CActiveMasternodeManager` relies on `GetLocal()` to detect a valid external address. * While it can also rely on other nodes to determine that, removing code that tests against a well-known public address would increase the number of reported failures esp. if the checks are run _before_ the node has a chance to connect to any peers. ## Breaking Changes None observed. ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas **(note: N/A)** - [x] I have added or updated relevant unit/integration/functional/e2e tests - [x] I have made corresponding changes to the documentation **(note: N/A)** - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: UdjinM6: utACK c38544a PastaPastaPasta: utACK c38544a Tree-SHA512: 1d02bc33c8d62c392960d4dd044edf3de08515a5e8c8794d95cd95e9654da91b20e7290436cf9c79b0ea8dbd42b27dcc61c8eb17e573902574d7b281b8874584
2 parents c4dd8a7 + c38544a commit a4e5f4d

22 files changed

Lines changed: 803 additions & 503 deletions

src/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,9 @@ BITCOIN_CORE_H = \
271271
node/blockstorage.h \
272272
node/coin.h \
273273
node/coinstats.h \
274+
node/connection_types.h \
274275
node/context.h \
276+
node/eviction.h \
275277
node/psbt.h \
276278
node/transaction.h \
277279
node/ui_interface.h \
@@ -498,7 +500,9 @@ libbitcoin_server_a_SOURCES = \
498500
node/blockstorage.cpp \
499501
node/coin.cpp \
500502
node/coinstats.cpp \
503+
node/connection_types.cpp \
501504
node/context.cpp \
505+
node/eviction.cpp \
502506
node/interfaces.cpp \
503507
node/psbt.cpp \
504508
node/transaction.cpp \

src/masternode/node.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,42 @@
1515
#include <validation.h>
1616
#include <warnings.h>
1717

18+
namespace {
19+
bool GetLocal(CService& addr, const CNetAddr* paddrPeer)
20+
{
21+
if (!fListen)
22+
return false;
23+
24+
int nBestScore = -1;
25+
{
26+
LOCK(g_maplocalhost_mutex);
27+
int nBestReachability = -1;
28+
for (const auto& entry : mapLocalHost)
29+
{
30+
// For privacy reasons, don't advertise our privacy-network address
31+
// to other networks and don't advertise our other-network address
32+
// to privacy networks.
33+
const Network our_net{entry.first.GetNetwork()};
34+
const Network peers_net{paddrPeer->GetNetwork()};
35+
if (our_net != peers_net &&
36+
(our_net == NET_ONION || our_net == NET_I2P ||
37+
peers_net == NET_ONION || peers_net == NET_I2P)) {
38+
continue;
39+
}
40+
int nScore = entry.second.nScore;
41+
int nReachability = entry.first.GetReachabilityFrom(*paddrPeer);
42+
if (nReachability > nBestReachability || (nReachability == nBestReachability && nScore > nBestScore))
43+
{
44+
addr = CService(entry.first, entry.second.nPort);
45+
nBestReachability = nReachability;
46+
nBestScore = nScore;
47+
}
48+
}
49+
}
50+
return nBestScore >= 0;
51+
}
52+
} // anonymous namespace
53+
1854
CActiveMasternodeManager::CActiveMasternodeManager(const CBLSSecretKey& sk, CConnman& connman, const std::unique_ptr<CDeterministicMNManager>& dmnman) :
1955
m_info(sk, sk.GetPublicKey()),
2056
m_connman{connman},
@@ -204,8 +240,7 @@ bool CActiveMasternodeManager::GetLocalAddress(CService& addrRet)
204240
auto service = m_info.service;
205241
m_connman.ForEachNodeContinueIf(CConnman::AllNodes, [&](CNode* pnode) {
206242
empty = false;
207-
if (pnode->addr.IsIPv4())
208-
fFoundLocal = GetLocal(service, &pnode->addr) && IsValidNetAddr(service);
243+
if (pnode->addr.IsIPv4()) fFoundLocal = GetLocal(service, *pnode) && IsValidNetAddr(service);
209244
return !fFoundLocal;
210245
});
211246
// nothing and no live connections, can't do anything for now

0 commit comments

Comments
 (0)