[addrman] Make m_asmap private
Add a GetAsmap() getter function that returns a reference to const.
This commit is contained in:
1 parent
f9002cb5db
commit
5840476714
3 files changed
+25
-23
No files matched your search
+2
-2
@@ -78,10 +78,10 @@ double CAddrInfo::GetChance(int64_t nNow) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
CAddrMan::CAddrMan(std::vector<bool> asmap, bool deterministic, int32_t consistency_check_ratio)
|
CAddrMan::CAddrMan(std::vector<bool> asmap, bool deterministic, int32_t consistency_check_ratio)
|
||||||
: m_asmap{std::move(asmap)}
|
: insecure_rand{deterministic}
|
||||||
, insecure_rand{deterministic}
|
|
||||||
, nKey{deterministic ? uint256{1} : insecure_rand.rand256()}
|
, nKey{deterministic ? uint256{1} : insecure_rand.rand256()}
|
||||||
, m_consistency_check_ratio{consistency_check_ratio}
|
, m_consistency_check_ratio{consistency_check_ratio}
|
||||||
|
, m_asmap{std::move(asmap)}
|
||||||
{
|
{
|
||||||
for (auto& bucket : vvNew) {
|
for (auto& bucket : vvNew) {
|
||||||
for (auto& entry : bucket) {
|
for (auto& entry : bucket) {
|
||||||
|
|||||||
+18
-16
@@ -181,22 +181,6 @@ static const int64_t ADDRMAN_TEST_WINDOW = 40*60; // 40 minutes
|
|||||||
class CAddrMan
|
class CAddrMan
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Compressed IP->ASN mapping, loaded from a file when a node starts.
|
|
||||||
// Should be always empty if no file was provided.
|
|
||||||
// This mapping is then used for bucketing nodes in Addrman.
|
|
||||||
//
|
|
||||||
// If asmap is provided, nodes will be bucketed by
|
|
||||||
// AS they belong to, in order to make impossible for a node
|
|
||||||
// to connect to several nodes hosted in a single AS.
|
|
||||||
// This is done in response to Erebus attack, but also to generally
|
|
||||||
// diversify the connections every node creates,
|
|
||||||
// especially useful when a large fraction of nodes
|
|
||||||
// operate under a couple of cloud providers.
|
|
||||||
//
|
|
||||||
// If a new asmap was provided, the existing records
|
|
||||||
// would be re-bucketed accordingly.
|
|
||||||
const std::vector<bool> m_asmap;
|
|
||||||
|
|
||||||
// Read asmap from provided binary file
|
// Read asmap from provided binary file
|
||||||
static std::vector<bool> DecodeAsmap(fs::path path);
|
static std::vector<bool> DecodeAsmap(fs::path path);
|
||||||
|
|
||||||
@@ -593,6 +577,8 @@ public:
|
|||||||
Check();
|
Check();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::vector<bool>& GetAsmap() const { return m_asmap; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! A mutex to protect the inner data structures.
|
//! A mutex to protect the inner data structures.
|
||||||
mutable Mutex cs;
|
mutable Mutex cs;
|
||||||
@@ -660,6 +646,22 @@ private:
|
|||||||
/** Perform consistency checks every m_consistency_check_ratio operations (if non-zero). */
|
/** Perform consistency checks every m_consistency_check_ratio operations (if non-zero). */
|
||||||
const int32_t m_consistency_check_ratio;
|
const int32_t m_consistency_check_ratio;
|
||||||
|
|
||||||
|
// Compressed IP->ASN mapping, loaded from a file when a node starts.
|
||||||
|
// Should be always empty if no file was provided.
|
||||||
|
// This mapping is then used for bucketing nodes in Addrman.
|
||||||
|
//
|
||||||
|
// If asmap is provided, nodes will be bucketed by
|
||||||
|
// AS they belong to, in order to make impossible for a node
|
||||||
|
// to connect to several nodes hosted in a single AS.
|
||||||
|
// This is done in response to Erebus attack, but also to generally
|
||||||
|
// diversify the connections every node creates,
|
||||||
|
// especially useful when a large fraction of nodes
|
||||||
|
// operate under a couple of cloud providers.
|
||||||
|
//
|
||||||
|
// If a new asmap was provided, the existing records
|
||||||
|
// would be re-bucketed accordingly.
|
||||||
|
const std::vector<bool> m_asmap;
|
||||||
|
|
||||||
//! Find an entry.
|
//! Find an entry.
|
||||||
CAddrInfo* Find(const CNetAddr& addr, int *pnId = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
CAddrInfo* Find(const CNetAddr& addr, int *pnId = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs);
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -1936,7 +1936,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
|||||||
case ConnectionType::BLOCK_RELAY:
|
case ConnectionType::BLOCK_RELAY:
|
||||||
case ConnectionType::ADDR_FETCH:
|
case ConnectionType::ADDR_FETCH:
|
||||||
case ConnectionType::FEELER:
|
case ConnectionType::FEELER:
|
||||||
setConnected.insert(pnode->addr.GetGroup(addrman.m_asmap));
|
setConnected.insert(pnode->addr.GetGroup(addrman.GetAsmap()));
|
||||||
} // no default case, so the compiler can warn about missing cases
|
} // no default case, so the compiler can warn about missing cases
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2010,7 +2010,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
|||||||
m_anchors.pop_back();
|
m_anchors.pop_back();
|
||||||
if (!addr.IsValid() || IsLocal(addr) || !IsReachable(addr) ||
|
if (!addr.IsValid() || IsLocal(addr) || !IsReachable(addr) ||
|
||||||
!HasAllDesirableServiceFlags(addr.nServices) ||
|
!HasAllDesirableServiceFlags(addr.nServices) ||
|
||||||
setConnected.count(addr.GetGroup(addrman.m_asmap))) continue;
|
setConnected.count(addr.GetGroup(addrman.GetAsmap()))) continue;
|
||||||
addrConnect = addr;
|
addrConnect = addr;
|
||||||
LogPrint(BCLog::NET, "Trying to make an anchor connection to %s\n", addrConnect.ToString());
|
LogPrint(BCLog::NET, "Trying to make an anchor connection to %s\n", addrConnect.ToString());
|
||||||
break;
|
break;
|
||||||
@@ -2050,7 +2050,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Require outbound connections, other than feelers, to be to distinct network groups
|
// Require outbound connections, other than feelers, to be to distinct network groups
|
||||||
if (!fFeeler && setConnected.count(addr.GetGroup(addrman.m_asmap))) {
|
if (!fFeeler && setConnected.count(addr.GetGroup(addrman.GetAsmap()))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2819,7 +2819,7 @@ void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats) const
|
|||||||
vstats.reserve(vNodes.size());
|
vstats.reserve(vNodes.size());
|
||||||
for (CNode* pnode : vNodes) {
|
for (CNode* pnode : vNodes) {
|
||||||
vstats.emplace_back();
|
vstats.emplace_back();
|
||||||
pnode->CopyStats(vstats.back(), addrman.m_asmap);
|
pnode->CopyStats(vstats.back(), addrman.GetAsmap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3082,7 +3082,7 @@ CSipHasher CConnman::GetDeterministicRandomizer(uint64_t id) const
|
|||||||
|
|
||||||
uint64_t CConnman::CalculateKeyedNetGroup(const CAddress& ad) const
|
uint64_t CConnman::CalculateKeyedNetGroup(const CAddress& ad) const
|
||||||
{
|
{
|
||||||
std::vector<unsigned char> vchNetGroup(ad.GetGroup(addrman.m_asmap));
|
std::vector<unsigned char> vchNetGroup(ad.GetGroup(addrman.GetAsmap()));
|
||||||
|
|
||||||
return GetDeterministicRandomizer(RANDOMIZER_ID_NETGROUP).Write(vchNetGroup.data(), vchNetGroup.size()).Finalize();
|
return GetDeterministicRandomizer(RANDOMIZER_ID_NETGROUP).Write(vchNetGroup.data(), vchNetGroup.size()).Finalize();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user