Skip to content

Commit 5840476

Browse files
committed
[addrman] Make m_asmap private
Add a GetAsmap() getter function that returns a reference to const.
1 parent f9002cb commit 5840476

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

src/addrman.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ double CAddrInfo::GetChance(int64_t nNow) const
7878
}
7979

8080
CAddrMan::CAddrMan(std::vector<bool> asmap, bool deterministic, int32_t consistency_check_ratio)
81-
: m_asmap{std::move(asmap)}
82-
, insecure_rand{deterministic}
81+
: insecure_rand{deterministic}
8382
, nKey{deterministic ? uint256{1} : insecure_rand.rand256()}
8483
, m_consistency_check_ratio{consistency_check_ratio}
84+
, m_asmap{std::move(asmap)}
8585
{
8686
for (auto& bucket : vvNew) {
8787
for (auto& entry : bucket) {

src/addrman.h

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -181,22 +181,6 @@ static const int64_t ADDRMAN_TEST_WINDOW = 40*60; // 40 minutes
181181
class CAddrMan
182182
{
183183
public:
184-
// Compressed IP->ASN mapping, loaded from a file when a node starts.
185-
// Should be always empty if no file was provided.
186-
// This mapping is then used for bucketing nodes in Addrman.
187-
//
188-
// If asmap is provided, nodes will be bucketed by
189-
// AS they belong to, in order to make impossible for a node
190-
// to connect to several nodes hosted in a single AS.
191-
// This is done in response to Erebus attack, but also to generally
192-
// diversify the connections every node creates,
193-
// especially useful when a large fraction of nodes
194-
// operate under a couple of cloud providers.
195-
//
196-
// If a new asmap was provided, the existing records
197-
// would be re-bucketed accordingly.
198-
const std::vector<bool> m_asmap;
199-
200184
// Read asmap from provided binary file
201185
static std::vector<bool> DecodeAsmap(fs::path path);
202186

@@ -593,6 +577,8 @@ class CAddrMan
593577
Check();
594578
}
595579

580+
const std::vector<bool>& GetAsmap() const { return m_asmap; }
581+
596582
private:
597583
//! A mutex to protect the inner data structures.
598584
mutable Mutex cs;
@@ -660,6 +646,22 @@ class CAddrMan
660646
/** Perform consistency checks every m_consistency_check_ratio operations (if non-zero). */
661647
const int32_t m_consistency_check_ratio;
662648

649+
// Compressed IP->ASN mapping, loaded from a file when a node starts.
650+
// Should be always empty if no file was provided.
651+
// This mapping is then used for bucketing nodes in Addrman.
652+
//
653+
// If asmap is provided, nodes will be bucketed by
654+
// AS they belong to, in order to make impossible for a node
655+
// to connect to several nodes hosted in a single AS.
656+
// This is done in response to Erebus attack, but also to generally
657+
// diversify the connections every node creates,
658+
// especially useful when a large fraction of nodes
659+
// operate under a couple of cloud providers.
660+
//
661+
// If a new asmap was provided, the existing records
662+
// would be re-bucketed accordingly.
663+
const std::vector<bool> m_asmap;
664+
663665
//! Find an entry.
664666
CAddrInfo* Find(const CNetAddr& addr, int *pnId = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs);
665667

src/net.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
19361936
case ConnectionType::BLOCK_RELAY:
19371937
case ConnectionType::ADDR_FETCH:
19381938
case ConnectionType::FEELER:
1939-
setConnected.insert(pnode->addr.GetGroup(addrman.m_asmap));
1939+
setConnected.insert(pnode->addr.GetGroup(addrman.GetAsmap()));
19401940
} // no default case, so the compiler can warn about missing cases
19411941
}
19421942
}
@@ -2010,7 +2010,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
20102010
m_anchors.pop_back();
20112011
if (!addr.IsValid() || IsLocal(addr) || !IsReachable(addr) ||
20122012
!HasAllDesirableServiceFlags(addr.nServices) ||
2013-
setConnected.count(addr.GetGroup(addrman.m_asmap))) continue;
2013+
setConnected.count(addr.GetGroup(addrman.GetAsmap()))) continue;
20142014
addrConnect = addr;
20152015
LogPrint(BCLog::NET, "Trying to make an anchor connection to %s\n", addrConnect.ToString());
20162016
break;
@@ -2050,7 +2050,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
20502050
}
20512051

20522052
// Require outbound connections, other than feelers, to be to distinct network groups
2053-
if (!fFeeler && setConnected.count(addr.GetGroup(addrman.m_asmap))) {
2053+
if (!fFeeler && setConnected.count(addr.GetGroup(addrman.GetAsmap()))) {
20542054
break;
20552055
}
20562056

@@ -2819,7 +2819,7 @@ void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats) const
28192819
vstats.reserve(vNodes.size());
28202820
for (CNode* pnode : vNodes) {
28212821
vstats.emplace_back();
2822-
pnode->CopyStats(vstats.back(), addrman.m_asmap);
2822+
pnode->CopyStats(vstats.back(), addrman.GetAsmap());
28232823
}
28242824
}
28252825

@@ -3082,7 +3082,7 @@ CSipHasher CConnman::GetDeterministicRandomizer(uint64_t id) const
30823082

30833083
uint64_t CConnman::CalculateKeyedNetGroup(const CAddress& ad) const
30843084
{
3085-
std::vector<unsigned char> vchNetGroup(ad.GetGroup(addrman.m_asmap));
3085+
std::vector<unsigned char> vchNetGroup(ad.GetGroup(addrman.GetAsmap()));
30863086

30873087
return GetDeterministicRandomizer(RANDOMIZER_ID_NETGROUP).Write(vchNetGroup.data(), vchNetGroup.size()).Finalize();
30883088
}

0 commit comments

Comments
 (0)