mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-27 15:01:18 +02:00
Add AssertLockHeld to CAddrMan private functions
This commit is contained in:
@@ -79,6 +79,8 @@ double CAddrInfo::GetChance(int64_t nNow) const
|
|||||||
|
|
||||||
CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId)
|
CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId)
|
||||||
{
|
{
|
||||||
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
const auto it = mapAddr.find(addr);
|
const auto it = mapAddr.find(addr);
|
||||||
if (it == mapAddr.end())
|
if (it == mapAddr.end())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -92,6 +94,8 @@ CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId)
|
|||||||
|
|
||||||
CAddrInfo* CAddrMan::Create(const CAddress& addr, const CNetAddr& addrSource, int* pnId)
|
CAddrInfo* CAddrMan::Create(const CAddress& addr, const CNetAddr& addrSource, int* pnId)
|
||||||
{
|
{
|
||||||
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
int nId = nIdCount++;
|
int nId = nIdCount++;
|
||||||
mapInfo[nId] = CAddrInfo(addr, addrSource);
|
mapInfo[nId] = CAddrInfo(addr, addrSource);
|
||||||
mapAddr[addr] = nId;
|
mapAddr[addr] = nId;
|
||||||
@@ -104,6 +108,8 @@ CAddrInfo* CAddrMan::Create(const CAddress& addr, const CNetAddr& addrSource, in
|
|||||||
|
|
||||||
void CAddrMan::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2)
|
void CAddrMan::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2)
|
||||||
{
|
{
|
||||||
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
if (nRndPos1 == nRndPos2)
|
if (nRndPos1 == nRndPos2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -124,6 +130,8 @@ void CAddrMan::SwapRandom(unsigned int nRndPos1, unsigned int nRndPos2)
|
|||||||
|
|
||||||
void CAddrMan::Delete(int nId)
|
void CAddrMan::Delete(int nId)
|
||||||
{
|
{
|
||||||
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
assert(mapInfo.count(nId) != 0);
|
assert(mapInfo.count(nId) != 0);
|
||||||
CAddrInfo& info = mapInfo[nId];
|
CAddrInfo& info = mapInfo[nId];
|
||||||
assert(!info.fInTried);
|
assert(!info.fInTried);
|
||||||
@@ -138,6 +146,8 @@ void CAddrMan::Delete(int nId)
|
|||||||
|
|
||||||
void CAddrMan::ClearNew(int nUBucket, int nUBucketPos)
|
void CAddrMan::ClearNew(int nUBucket, int nUBucketPos)
|
||||||
{
|
{
|
||||||
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
// if there is an entry in the specified bucket, delete it.
|
// if there is an entry in the specified bucket, delete it.
|
||||||
if (vvNew[nUBucket][nUBucketPos] != -1) {
|
if (vvNew[nUBucket][nUBucketPos] != -1) {
|
||||||
int nIdDelete = vvNew[nUBucket][nUBucketPos];
|
int nIdDelete = vvNew[nUBucket][nUBucketPos];
|
||||||
@@ -153,6 +163,8 @@ void CAddrMan::ClearNew(int nUBucket, int nUBucketPos)
|
|||||||
|
|
||||||
void CAddrMan::MakeTried(CAddrInfo& info, int nId)
|
void CAddrMan::MakeTried(CAddrInfo& info, int nId)
|
||||||
{
|
{
|
||||||
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
// remove the entry from all new buckets
|
// remove the entry from all new buckets
|
||||||
for (int bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; bucket++) {
|
for (int bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; bucket++) {
|
||||||
int pos = info.GetBucketPosition(nKey, true, bucket);
|
int pos = info.GetBucketPosition(nKey, true, bucket);
|
||||||
@@ -201,6 +213,8 @@ void CAddrMan::MakeTried(CAddrInfo& info, int nId)
|
|||||||
|
|
||||||
void CAddrMan::Good_(const CService& addr, bool test_before_evict, int64_t nTime)
|
void CAddrMan::Good_(const CService& addr, bool test_before_evict, int64_t nTime)
|
||||||
{
|
{
|
||||||
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
int nId;
|
int nId;
|
||||||
|
|
||||||
nLastGood = nTime;
|
nLastGood = nTime;
|
||||||
@@ -267,6 +281,8 @@ void CAddrMan::Good_(const CService& addr, bool test_before_evict, int64_t nTime
|
|||||||
|
|
||||||
bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimePenalty)
|
bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimePenalty)
|
||||||
{
|
{
|
||||||
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
if (!addr.IsRoutable())
|
if (!addr.IsRoutable())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -340,6 +356,8 @@ bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimeP
|
|||||||
|
|
||||||
void CAddrMan::Attempt_(const CService& addr, bool fCountFailure, int64_t nTime)
|
void CAddrMan::Attempt_(const CService& addr, bool fCountFailure, int64_t nTime)
|
||||||
{
|
{
|
||||||
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
CAddrInfo* pinfo = Find(addr);
|
CAddrInfo* pinfo = Find(addr);
|
||||||
|
|
||||||
// if not found, bail out
|
// if not found, bail out
|
||||||
@@ -362,6 +380,8 @@ void CAddrMan::Attempt_(const CService& addr, bool fCountFailure, int64_t nTime)
|
|||||||
|
|
||||||
CAddrInfo CAddrMan::Select_(bool newOnly)
|
CAddrInfo CAddrMan::Select_(bool newOnly)
|
||||||
{
|
{
|
||||||
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
if (vRandom.empty())
|
if (vRandom.empty())
|
||||||
return CAddrInfo();
|
return CAddrInfo();
|
||||||
|
|
||||||
@@ -410,6 +430,8 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
|
|||||||
#ifdef DEBUG_ADDRMAN
|
#ifdef DEBUG_ADDRMAN
|
||||||
int CAddrMan::Check_()
|
int CAddrMan::Check_()
|
||||||
{
|
{
|
||||||
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
std::unordered_set<int> setTried;
|
std::unordered_set<int> setTried;
|
||||||
std::unordered_map<int, int> mapNew;
|
std::unordered_map<int, int> mapNew;
|
||||||
|
|
||||||
@@ -487,6 +509,8 @@ int CAddrMan::Check_()
|
|||||||
|
|
||||||
void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network)
|
void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size_t max_pct, std::optional<Network> network)
|
||||||
{
|
{
|
||||||
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
size_t nNodes = vRandom.size();
|
size_t nNodes = vRandom.size();
|
||||||
if (max_pct != 0) {
|
if (max_pct != 0) {
|
||||||
nNodes = max_pct * nNodes / 100;
|
nNodes = max_pct * nNodes / 100;
|
||||||
@@ -519,6 +543,8 @@ void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr, size_t max_addresses, size
|
|||||||
|
|
||||||
void CAddrMan::Connected_(const CService& addr, int64_t nTime)
|
void CAddrMan::Connected_(const CService& addr, int64_t nTime)
|
||||||
{
|
{
|
||||||
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
CAddrInfo* pinfo = Find(addr);
|
CAddrInfo* pinfo = Find(addr);
|
||||||
|
|
||||||
// if not found, bail out
|
// if not found, bail out
|
||||||
@@ -539,6 +565,8 @@ void CAddrMan::Connected_(const CService& addr, int64_t nTime)
|
|||||||
|
|
||||||
void CAddrMan::SetServices_(const CService& addr, ServiceFlags nServices)
|
void CAddrMan::SetServices_(const CService& addr, ServiceFlags nServices)
|
||||||
{
|
{
|
||||||
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
CAddrInfo* pinfo = Find(addr);
|
CAddrInfo* pinfo = Find(addr);
|
||||||
|
|
||||||
// if not found, bail out
|
// if not found, bail out
|
||||||
@@ -557,6 +585,8 @@ void CAddrMan::SetServices_(const CService& addr, ServiceFlags nServices)
|
|||||||
|
|
||||||
void CAddrMan::ResolveCollisions_()
|
void CAddrMan::ResolveCollisions_()
|
||||||
{
|
{
|
||||||
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
for (std::set<int>::iterator it = m_tried_collisions.begin(); it != m_tried_collisions.end();) {
|
for (std::set<int>::iterator it = m_tried_collisions.begin(); it != m_tried_collisions.end();) {
|
||||||
int id_new = *it;
|
int id_new = *it;
|
||||||
|
|
||||||
@@ -616,6 +646,8 @@ void CAddrMan::ResolveCollisions_()
|
|||||||
|
|
||||||
CAddrInfo CAddrMan::SelectTriedCollision_()
|
CAddrInfo CAddrMan::SelectTriedCollision_()
|
||||||
{
|
{
|
||||||
|
AssertLockHeld(cs);
|
||||||
|
|
||||||
if (m_tried_collisions.size() == 0) return CAddrInfo();
|
if (m_tried_collisions.size() == 0) return CAddrInfo();
|
||||||
|
|
||||||
std::set<int>::iterator it = m_tried_collisions.begin();
|
std::set<int>::iterator it = m_tried_collisions.begin();
|
||||||
|
Reference in New Issue
Block a user