|
|
@ -41,7 +41,7 @@ static constexpr size_t ADDRMAN_SET_TRIED_COLLISION_SIZE{10};
|
|
|
|
/** The maximum time we'll spend trying to resolve a tried table collision, in seconds */
|
|
|
|
/** The maximum time we'll spend trying to resolve a tried table collision, in seconds */
|
|
|
|
static constexpr int64_t ADDRMAN_TEST_WINDOW{40*60}; // 40 minutes
|
|
|
|
static constexpr int64_t ADDRMAN_TEST_WINDOW{40*60}; // 40 minutes
|
|
|
|
|
|
|
|
|
|
|
|
int AddrInfo::GetTriedBucket(const uint256& nKey, const std::vector<bool> &asmap) const
|
|
|
|
int AddrInfo::GetTriedBucket(const uint256& nKey, const std::vector<bool>& asmap) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetKey()).GetCheapHash();
|
|
|
|
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetKey()).GetCheapHash();
|
|
|
|
uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup(asmap) << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP)).GetCheapHash();
|
|
|
|
uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup(asmap) << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP)).GetCheapHash();
|
|
|
@ -51,7 +51,7 @@ int AddrInfo::GetTriedBucket(const uint256& nKey, const std::vector<bool> &asmap
|
|
|
|
return tried_bucket;
|
|
|
|
return tried_bucket;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int AddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src, const std::vector<bool> &asmap) const
|
|
|
|
int AddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src, const std::vector<bool>& asmap) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::vector<unsigned char> vchSourceGroupKey = src.GetGroup(asmap);
|
|
|
|
std::vector<unsigned char> vchSourceGroupKey = src.GetGroup(asmap);
|
|
|
|
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup(asmap) << vchSourceGroupKey).GetCheapHash();
|
|
|
|
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup(asmap) << vchSourceGroupKey).GetCheapHash();
|
|
|
@ -62,7 +62,7 @@ int AddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src, const std::
|
|
|
|
return new_bucket;
|
|
|
|
return new_bucket;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int AddrInfo::GetBucketPosition(const uint256 &nKey, bool fNew, int nBucket) const
|
|
|
|
int AddrInfo::GetBucketPosition(const uint256& nKey, bool fNew, int nBucket) const
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << (fNew ? uint8_t{'N'} : uint8_t{'K'}) << nBucket << GetKey()).GetCheapHash();
|
|
|
|
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << (fNew ? uint8_t{'N'} : uint8_t{'K'}) << nBucket << GetKey()).GetCheapHash();
|
|
|
|
return hash1 % ADDRMAN_BUCKET_SIZE;
|
|
|
|
return hash1 % ADDRMAN_BUCKET_SIZE;
|
|
|
@ -190,7 +190,7 @@ void AddrManImpl::Serialize(Stream& s_) const
|
|
|
|
int nIds = 0;
|
|
|
|
int nIds = 0;
|
|
|
|
for (const auto& entry : mapInfo) {
|
|
|
|
for (const auto& entry : mapInfo) {
|
|
|
|
mapUnkIds[entry.first] = nIds;
|
|
|
|
mapUnkIds[entry.first] = nIds;
|
|
|
|
const AddrInfo &info = entry.second;
|
|
|
|
const AddrInfo& info = entry.second;
|
|
|
|
if (info.nRefCount) {
|
|
|
|
if (info.nRefCount) {
|
|
|
|
assert(nIds != nNew); // this means nNew was wrong, oh ow
|
|
|
|
assert(nIds != nNew); // this means nNew was wrong, oh ow
|
|
|
|
s << info;
|
|
|
|
s << info;
|
|
|
@ -199,7 +199,7 @@ void AddrManImpl::Serialize(Stream& s_) const
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nIds = 0;
|
|
|
|
nIds = 0;
|
|
|
|
for (const auto& entry : mapInfo) {
|
|
|
|
for (const auto& entry : mapInfo) {
|
|
|
|
const AddrInfo &info = entry.second;
|
|
|
|
const AddrInfo& info = entry.second;
|
|
|
|
if (info.fInTried) {
|
|
|
|
if (info.fInTried) {
|
|
|
|
assert(nIds != nTried); // this means nTried was wrong, oh ow
|
|
|
|
assert(nIds != nTried); // this means nTried was wrong, oh ow
|
|
|
|
s << info;
|
|
|
|
s << info;
|
|
|
@ -283,7 +283,7 @@ void AddrManImpl::Unserialize(Stream& s_)
|
|
|
|
|
|
|
|
|
|
|
|
// Deserialize entries from the new table.
|
|
|
|
// Deserialize entries from the new table.
|
|
|
|
for (int n = 0; n < nNew; n++) {
|
|
|
|
for (int n = 0; n < nNew; n++) {
|
|
|
|
AddrInfo &info = mapInfo[n];
|
|
|
|
AddrInfo& info = mapInfo[n];
|
|
|
|
s >> info;
|
|
|
|
s >> info;
|
|
|
|
mapAddr[info] = n;
|
|
|
|
mapAddr[info] = n;
|
|
|
|
info.nRandomPos = vRandom.size();
|
|
|
|
info.nRandomPos = vRandom.size();
|
|
|
@ -1024,7 +1024,7 @@ size_t AddrManImpl::size() const
|
|
|
|
return vRandom.size();
|
|
|
|
return vRandom.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool AddrManImpl::Add(const std::vector<CAddress> &vAddr, const CNetAddr& source, int64_t nTimePenalty)
|
|
|
|
bool AddrManImpl::Add(const std::vector<CAddress>& vAddr, const CNetAddr& source, int64_t nTimePenalty)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
LOCK(cs);
|
|
|
|
int nAdd = 0;
|
|
|
|
int nAdd = 0;
|
|
|
@ -1038,7 +1038,7 @@ bool AddrManImpl::Add(const std::vector<CAddress> &vAddr, const CNetAddr& source
|
|
|
|
return nAdd > 0;
|
|
|
|
return nAdd > 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AddrManImpl::Good(const CService &addr, int64_t nTime)
|
|
|
|
void AddrManImpl::Good(const CService& addr, int64_t nTime)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
LOCK(cs);
|
|
|
|
Check();
|
|
|
|
Check();
|
|
|
@ -1046,7 +1046,7 @@ void AddrManImpl::Good(const CService &addr, int64_t nTime)
|
|
|
|
Check();
|
|
|
|
Check();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AddrManImpl::Attempt(const CService &addr, bool fCountFailure, int64_t nTime)
|
|
|
|
void AddrManImpl::Attempt(const CService& addr, bool fCountFailure, int64_t nTime)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
LOCK(cs);
|
|
|
|
Check();
|
|
|
|
Check();
|
|
|
@ -1089,7 +1089,7 @@ std::vector<CAddress> AddrManImpl::GetAddr(size_t max_addresses, size_t max_pct,
|
|
|
|
return addresses;
|
|
|
|
return addresses;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AddrManImpl::Connected(const CService &addr, int64_t nTime)
|
|
|
|
void AddrManImpl::Connected(const CService& addr, int64_t nTime)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
LOCK(cs);
|
|
|
|
Check();
|
|
|
|
Check();
|
|
|
@ -1097,7 +1097,7 @@ void AddrManImpl::Connected(const CService &addr, int64_t nTime)
|
|
|
|
Check();
|
|
|
|
Check();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AddrManImpl::SetServices(const CService &addr, ServiceFlags nServices)
|
|
|
|
void AddrManImpl::SetServices(const CService& addr, ServiceFlags nServices)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
|
|
|
LOCK(cs);
|
|
|
|
Check();
|
|
|
|
Check();
|
|
|
@ -1141,17 +1141,17 @@ size_t AddrMan::size() const
|
|
|
|
return m_impl->size();
|
|
|
|
return m_impl->size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool AddrMan::Add(const std::vector<CAddress> &vAddr, const CNetAddr& source, int64_t nTimePenalty)
|
|
|
|
bool AddrMan::Add(const std::vector<CAddress>& vAddr, const CNetAddr& source, int64_t nTimePenalty)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return m_impl->Add(vAddr, source, nTimePenalty);
|
|
|
|
return m_impl->Add(vAddr, source, nTimePenalty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AddrMan::Good(const CService &addr, int64_t nTime)
|
|
|
|
void AddrMan::Good(const CService& addr, int64_t nTime)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_impl->Good(addr, nTime);
|
|
|
|
m_impl->Good(addr, nTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AddrMan::Attempt(const CService &addr, bool fCountFailure, int64_t nTime)
|
|
|
|
void AddrMan::Attempt(const CService& addr, bool fCountFailure, int64_t nTime)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_impl->Attempt(addr, fCountFailure, nTime);
|
|
|
|
m_impl->Attempt(addr, fCountFailure, nTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1176,12 +1176,12 @@ std::vector<CAddress> AddrMan::GetAddr(size_t max_addresses, size_t max_pct, std
|
|
|
|
return m_impl->GetAddr(max_addresses, max_pct, network);
|
|
|
|
return m_impl->GetAddr(max_addresses, max_pct, network);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AddrMan::Connected(const CService &addr, int64_t nTime)
|
|
|
|
void AddrMan::Connected(const CService& addr, int64_t nTime)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_impl->Connected(addr, nTime);
|
|
|
|
m_impl->Connected(addr, nTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AddrMan::SetServices(const CService &addr, ServiceFlags nServices)
|
|
|
|
void AddrMan::SetServices(const CService& addr, ServiceFlags nServices)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_impl->SetServices(addr, nServices);
|
|
|
|
m_impl->SetServices(addr, nServices);
|
|
|
|
}
|
|
|
|
}
|
|
|
|