mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
refactor: make AddrMan::Good return bool
If AddrMan::Good is unable to add an entry to tried (for a number of reasons), return false. This makes it much easier and cleaner to directly test for tried collisions. It also allows anyone calling Good() to handle the case where adding an address to tried is unsuccessful. Update docs to doxygen style.
This commit is contained in:
@@ -614,7 +614,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, int64_
|
||||
return fInsert;
|
||||
}
|
||||
|
||||
void AddrManImpl::Good_(const CService& addr, bool test_before_evict, int64_t nTime)
|
||||
bool AddrManImpl::Good_(const CService& addr, bool test_before_evict, int64_t nTime)
|
||||
{
|
||||
AssertLockHeld(cs);
|
||||
|
||||
@@ -625,8 +625,7 @@ void AddrManImpl::Good_(const CService& addr, bool test_before_evict, int64_t nT
|
||||
AddrInfo* pinfo = Find(addr, &nId);
|
||||
|
||||
// if not found, bail out
|
||||
if (!pinfo)
|
||||
return;
|
||||
if (!pinfo) return false;
|
||||
|
||||
AddrInfo& info = *pinfo;
|
||||
|
||||
@@ -638,13 +637,11 @@ void AddrManImpl::Good_(const CService& addr, bool test_before_evict, int64_t nT
|
||||
// currently-connected peers.
|
||||
|
||||
// if it is already in the tried set, don't do anything else
|
||||
if (info.fInTried)
|
||||
return;
|
||||
if (info.fInTried) return false;
|
||||
|
||||
// if it is not in new, something bad happened
|
||||
if (!Assume(info.nRefCount > 0)) {
|
||||
return;
|
||||
}
|
||||
if (!Assume(info.nRefCount > 0)) return false;
|
||||
|
||||
|
||||
// which tried bucket to move the entry to
|
||||
int tried_bucket = info.GetTriedBucket(nKey, m_asmap);
|
||||
@@ -661,11 +658,13 @@ void AddrManImpl::Good_(const CService& addr, bool test_before_evict, int64_t nT
|
||||
colliding_entry != mapInfo.end() ? colliding_entry->second.ToString() : "",
|
||||
addr.ToString(),
|
||||
m_tried_collisions.size());
|
||||
return false;
|
||||
} else {
|
||||
// move nId to the tried tables
|
||||
MakeTried(info, nId);
|
||||
LogPrint(BCLog::ADDRMAN, "Moved %s mapped to AS%i to tried[%i][%i]\n",
|
||||
addr.ToString(), addr.GetMappedAS(m_asmap), tried_bucket, tried_bucket_pos);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1049,12 +1048,13 @@ bool AddrManImpl::Add(const std::vector<CAddress>& vAddr, const CNetAddr& source
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AddrManImpl::Good(const CService& addr, int64_t nTime)
|
||||
bool AddrManImpl::Good(const CService& addr, int64_t nTime)
|
||||
{
|
||||
LOCK(cs);
|
||||
Check();
|
||||
Good_(addr, /* test_before_evict */ true, nTime);
|
||||
auto ret = Good_(addr, /*test_before_evict=*/true, nTime);
|
||||
Check();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AddrManImpl::Attempt(const CService& addr, bool fCountFailure, int64_t nTime)
|
||||
@@ -1157,9 +1157,9 @@ bool AddrMan::Add(const std::vector<CAddress>& vAddr, const CNetAddr& source, in
|
||||
return m_impl->Add(vAddr, source, nTimePenalty);
|
||||
}
|
||||
|
||||
void AddrMan::Good(const CService& addr, int64_t nTime)
|
||||
bool AddrMan::Good(const CService& addr, int64_t nTime)
|
||||
{
|
||||
m_impl->Good(addr, nTime);
|
||||
return m_impl->Good(addr, nTime);
|
||||
}
|
||||
|
||||
void AddrMan::Attempt(const CService& addr, bool fCountFailure, int64_t nTime)
|
||||
|
||||
Reference in New Issue
Block a user