55 std::vector<unsigned char> vchSourceGroupKey = netgroupman.
GetGroup(src);
56 uint64_t hash1 = (
HashWriter{} << nKey << netgroupman.
GetGroup(*
this) << vchSourceGroupKey).GetCheapHash();
63 uint64_t hash1 = (
HashWriter{} << nKey << (fNew ? uint8_t{
'N'} : uint8_t{
'K'}) << bucket <<
GetKey()).GetCheapHash();
73 if (
nTime > now + 10min) {
102 fChance *= pow(0.66, std::min(
nAttempts, 8));
108 : insecure_rand{deterministic}
109 , nKey{deterministic ?
uint256{1} : insecure_rand.rand256()}
110 , m_consistency_check_ratio{consistency_check_ratio}
111 , m_netgroupman{netgroupman}
113 for (
auto& bucket : vvNew) {
114 for (
auto& entry : bucket) {
118 for (
auto& bucket : vvTried) {
119 for (
auto& entry : bucket) {
130 template <
typename Stream>
180 static constexpr uint8_t lowest_compatible = Format::V4_MULTIPORT;
189 std::unordered_map<int, int> mapUnkIds;
191 for (
const auto& entry : mapInfo) {
192 mapUnkIds[entry.first] = nIds;
193 const AddrInfo& info = entry.second;
201 for (
const auto& entry : mapInfo) {
202 const AddrInfo& info = entry.second;
212 if (vvNew[bucket][i] != -1)
217 if (vvNew[bucket][i] != -1) {
218 int nIndex = mapUnkIds[vvNew[bucket][i]];
228 template <
typename Stream>
236 s_ >> Using<CustomUintFormatter<1>>(
format);
245 "Corrupted addrman database: The compat value (%u) " 246 "is lower than the expected minimum value %u.",
252 "Unsupported format of addrman database: %u. It is compatible with formats >=%u, " 253 "but the maximum supported by this version of %s is %u.",
262 if (
format >= Format::V1_DETERMINISTIC) {
263 nUBuckets ^= (1 << 30);
267 throw std::ios_base::failure(
268 strprintf(
"Corrupt AddrMan serialization: nNew=%d, should be in [0, %d]",
274 throw std::ios_base::failure(
275 strprintf(
"Corrupt AddrMan serialization: nTried=%d, should be in [0, %d]",
281 for (
int n = 0; n < nNew; n++) {
286 vRandom.push_back(n);
287 m_network_counts[info.GetNetwork()].n_new++;
293 for (
int n = 0; n < nTried; n++) {
297 int nKBucketPos = info.GetBucketPosition(
nKey,
false, nKBucket);
299 && vvTried[nKBucket][nKBucketPos] == -1) {
300 info.nRandomPos = vRandom.size();
301 info.fInTried =
true;
302 vRandom.push_back(nIdCount);
303 mapInfo[nIdCount] = info;
304 mapAddr[info] = nIdCount;
305 vvTried[nKBucket][nKBucketPos] = nIdCount;
307 m_network_counts[info.GetNetwork()].n_tried++;
317 std::vector<std::pair<int, int>> bucket_entries;
319 for (
int bucket = 0; bucket < nUBuckets; ++bucket) {
322 for (
int n = 0; n < num_entries; ++n) {
325 if (entry_index >= 0 && entry_index < nNew) {
326 bucket_entries.emplace_back(bucket, entry_index);
335 uint256 serialized_asmap_checksum;
336 if (
format >= Format::V2_ASMAP) {
337 s >> serialized_asmap_checksum;
340 serialized_asmap_checksum == supplied_asmap_checksum};
342 if (!restore_bucketing) {
346 for (
auto bucket_entry : bucket_entries) {
347 int bucket{bucket_entry.first};
348 const int entry_index{bucket_entry.second};
349 AddrInfo& info = mapInfo[entry_index];
360 if (restore_bucketing && vvNew[bucket][bucket_position] == -1) {
362 vvNew[bucket][bucket_position] = entry_index;
369 if (vvNew[bucket][bucket_position] == -1) {
370 vvNew[bucket][bucket_position] = entry_index;
378 for (
auto it = mapInfo.cbegin(); it != mapInfo.cend(); ) {
379 if (it->second.fInTried ==
false && it->second.nRefCount == 0) {
380 const auto itCopy = it++;
387 if (nLost + nLostUnk > 0) {
388 LogPrint(
BCLog::ADDRMAN,
"addrman lost %i new and %i tried addresses due to collisions or invalid addresses\n", nLostUnk, nLost);
392 if (check_code != 0) {
394 "Corrupt data. Consistency check failed with code %s",
403 const auto it = mapAddr.find(addr);
404 if (it == mapAddr.end())
407 *pnId = (*it).second;
408 const auto it2 = mapInfo.find((*it).second);
409 if (it2 != mapInfo.end())
410 return &(*it2).second;
418 int nId = nIdCount++;
419 mapInfo[nId] =
AddrInfo(addr, addrSource);
421 mapInfo[nId].nRandomPos = vRandom.size();
422 vRandom.push_back(nId);
427 return &mapInfo[nId];
434 if (nRndPos1 == nRndPos2)
437 assert(nRndPos1 < vRandom.size() && nRndPos2 < vRandom.size());
439 int nId1 = vRandom[nRndPos1];
440 int nId2 = vRandom[nRndPos2];
442 const auto it_1{mapInfo.find(nId1)};
443 const auto it_2{mapInfo.find(nId2)};
444 assert(it_1 != mapInfo.end());
445 assert(it_2 != mapInfo.end());
447 it_1->second.nRandomPos = nRndPos2;
448 it_2->second.nRandomPos = nRndPos1;
450 vRandom[nRndPos1] = nId2;
451 vRandom[nRndPos2] = nId1;
458 assert(mapInfo.count(nId) != 0);
461 assert(info.nRefCount == 0);
463 SwapRandom(info.nRandomPos, vRandom.size() - 1);
464 m_network_counts[info.GetNetwork()].n_new--;
476 if (vvNew[nUBucket][nUBucketPos] != -1) {
477 int nIdDelete = vvNew[nUBucket][nUBucketPos];
478 AddrInfo& infoDelete = mapInfo[nIdDelete];
481 vvNew[nUBucket][nUBucketPos] = -1;
498 if (vvNew[bucket][pos] == nId) {
499 vvNew[bucket][pos] = -1;
514 if (vvTried[nKBucket][nKBucketPos] != -1) {
516 int nIdEvict = vvTried[nKBucket][nKBucketPos];
517 assert(mapInfo.count(nIdEvict) == 1);
518 AddrInfo& infoOld = mapInfo[nIdEvict];
522 vvTried[nKBucket][nKBucketPos] = -1;
524 m_network_counts[infoOld.GetNetwork()].n_tried--;
528 int nUBucketPos = infoOld.GetBucketPosition(
nKey,
true, nUBucket);
530 assert(vvNew[nUBucket][nUBucketPos] == -1);
533 infoOld.nRefCount = 1;
534 vvNew[nUBucket][nUBucketPos] = nIdEvict;
536 m_network_counts[infoOld.GetNetwork()].n_new++;
538 infoOld.ToStringAddrPort(), nKBucket, nKBucketPos, nUBucket, nUBucketPos);
540 assert(vvTried[nKBucket][nKBucketPos] == -1);
542 vvTried[nKBucket][nKBucketPos] = nId;
545 m_network_counts[info.
GetNetwork()].n_tried++;
566 const auto update_interval{currently_online ? 1h : 24h};
567 if (pinfo->
nTime < addr.
nTime - update_interval - time_penalty) {
589 for (
int n = 0; n < pinfo->
nRefCount; n++)
591 if (nFactor > 1 && (insecure_rand.randrange(nFactor) != 0))
600 bool fInsert = vvNew[nUBucket][nUBucketPos] == -1;
601 if (vvNew[nUBucket][nUBucketPos] != nId) {
603 AddrInfo& infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];
612 vvNew[nUBucket][nUBucketPos] = nId;
635 if (!pinfo)
return false;
658 if (test_before_evict && (vvTried[tried_bucket][tried_bucket_pos] != -1)) {
663 auto colliding_entry = mapInfo.find(vvTried[tried_bucket][tried_bucket_pos]);
665 colliding_entry != mapInfo.end() ? colliding_entry->second.ToStringAddrPort() :
"",
681 for (std::vector<CAddress>::const_iterator it = vAddr.begin(); it != vAddr.end(); it++) {
685 LogPrint(
BCLog::ADDRMAN,
"Added %i addresses (of %i) from %s: %i tried, %i new\n", added, vAddr.size(),
source.ToStringAddr(), nTried, nNew);
714 if (vRandom.empty())
return {};
716 size_t new_count = nNew;
717 size_t tried_count = nTried;
719 if (network.has_value()) {
720 auto it = m_network_counts.find(*network);
721 if (it == m_network_counts.end())
return {};
723 auto counts = it->second;
724 new_count = counts.n_new;
725 tried_count = counts.n_tried;
728 if (new_only && new_count == 0)
return {};
729 if (new_count + tried_count == 0)
return {};
734 if (new_only || tried_count == 0) {
735 search_tried =
false;
736 }
else if (new_count == 0) {
739 search_tried = insecure_rand.randbool();
745 double chance_factor = 1.0;
748 int bucket = insecure_rand.randrange(bucket_count);
753 int i, position, node_id;
756 node_id =
GetEntry(search_tried, bucket, position);
758 if (network.has_value()) {
759 const auto it{mapInfo.find(node_id)};
760 if (
Assume(it != mapInfo.end()) && it->second.GetNetwork() == *network)
break;
771 const auto it_found{mapInfo.find(node_id)};
772 assert(it_found != mapInfo.end());
773 const AddrInfo& info{it_found->second};
776 if (insecure_rand.randbits(30) < chance_factor * info.GetChance() * (1 << 30)) {
777 LogPrint(
BCLog::ADDRMAN,
"Selected %s from %s\n", info.ToStringAddrPort(), search_tried ?
"tried" :
"new");
778 return {info, info.m_last_try};
782 chance_factor *= 1.2;
792 return vvTried[bucket][position];
796 return vvNew[bucket][position];
803 std::vector<CAddress>
AddrManImpl::GetAddr_(
size_t max_addresses,
size_t max_pct, std::optional<Network> network)
const 807 size_t nNodes = vRandom.size();
809 nNodes = max_pct * nNodes / 100;
811 if (max_addresses != 0) {
812 nNodes = std::min(nNodes, max_addresses);
816 const auto now{Now<NodeSeconds>()};
817 std::vector<CAddress> addresses;
818 for (
unsigned int n = 0; n < vRandom.size(); n++) {
819 if (addresses.size() >= nNodes)
822 int nRndPos = insecure_rand.randrange(vRandom.size() - n) + n;
824 const auto it{mapInfo.find(vRandom[n])};
825 assert(it != mapInfo.end());
830 if (network != std::nullopt && ai.GetNetClass() != network)
continue;
833 if (ai.IsTerrible(now))
continue;
835 addresses.push_back(ai);
846 std::vector<std::pair<AddrInfo, AddressPosition>> infos;
847 for (
int bucket = 0; bucket < bucket_count; ++bucket) {
849 int id =
GetEntry(from_tried, bucket, position);
857 infos.emplace_back(info, location);
878 const auto update_interval{20min};
879 if (time - info.
nTime > update_interval) {
907 bool erase_collision =
false;
910 if (mapInfo.count(id_new) != 1) {
911 erase_collision =
true;
913 AddrInfo& info_new = mapInfo[id_new];
919 erase_collision =
true;
920 }
else if (vvTried[tried_bucket][tried_bucket_pos] != -1) {
923 int id_old = vvTried[tried_bucket][tried_bucket_pos];
924 AddrInfo& info_old = mapInfo[id_old];
926 const auto current_time{Now<NodeSeconds>()};
930 erase_collision =
true;
934 if (current_time - info_old.
m_last_try > 60s) {
938 Good_(info_new,
false, current_time);
939 erase_collision =
true;
946 Good_(info_new,
false, current_time);
947 erase_collision =
true;
950 Good_(info_new,
false, Now<NodeSeconds>());
951 erase_collision =
true;
955 if (erase_collision) {
976 if (mapInfo.count(id_new) != 1) {
981 const AddrInfo& newInfo = mapInfo[id_new];
987 const AddrInfo& info_old = mapInfo[vvTried[tried_bucket][tried_bucket_pos]];
997 if (!addr_info)
return std::nullopt;
1018 if (!net.has_value()) {
1019 if (in_new.has_value()) {
1020 return *in_new ? nNew : nTried;
1022 return vRandom.size();
1025 if (
auto it = m_network_counts.find(*net); it != m_network_counts.end()) {
1026 auto net_count = it->second;
1027 if (in_new.has_value()) {
1028 return *in_new ? net_count.n_new : net_count.n_tried;
1030 return net_count.n_new + net_count.n_tried;
1046 LogPrintf(
"ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i\n", err);
1058 std::unordered_set<int> setTried;
1059 std::unordered_map<int, int> mapNew;
1060 std::unordered_map<Network, NewTriedCount> local_counts;
1062 if (vRandom.size() != (size_t)(nTried + nNew))
1065 for (
const auto& entry : mapInfo) {
1066 int n = entry.first;
1067 const AddrInfo& info = entry.second;
1069 if (!TicksSinceEpoch<std::chrono::seconds>(info.
m_last_success)) {
1084 const auto it{mapAddr.find(info)};
1085 if (it == mapAddr.end() || it->second != n) {
1098 if (setTried.size() != (size_t)nTried)
1100 if (mapNew.size() != (size_t)nNew)
1105 if (vvTried[n][i] != -1) {
1106 if (!setTried.count(vvTried[n][i]))
1108 const auto it{mapInfo.find(vvTried[n][i])};
1109 if (it == mapInfo.end() || it->second.GetTriedBucket(nKey, m_netgroupman) != n) {
1112 if (it->second.GetBucketPosition(nKey,
false, n) != i) {
1115 setTried.erase(vvTried[n][i]);
1122 if (vvNew[n][i] != -1) {
1123 if (!mapNew.count(vvNew[n][i]))
1125 const auto it{mapInfo.find(vvNew[n][i])};
1126 if (it == mapInfo.end() || it->second.GetBucketPosition(nKey,
true, n) != i) {
1129 if (--mapNew[vvNew[n][i]] == 0)
1130 mapNew.erase(vvNew[n][i]);
1135 if (setTried.size())
1144 if (m_network_counts.size() < local_counts.size()) {
1147 for (
const auto& [net,
count] : m_network_counts) {
1148 if (local_counts[net].n_new !=
count.n_new || local_counts[net].n_tried !=
count.n_tried) {
1178 auto ret =
Good_(addr,
true, time);
1187 Attempt_(addr, fCountFailure, time);
1212 auto addrRet =
Select_(new_only, network);
1217 std::vector<CAddress>
AddrManImpl::GetAddr(
size_t max_addresses,
size_t max_pct, std::optional<Network> network)
const 1221 auto addresses =
GetAddr_(max_addresses, max_pct, network);
1261 : m_impl(
std::make_unique<
AddrManImpl>(netgroupman, deterministic, consistency_check_ratio)) {}
1265 template <
typename Stream>
1268 m_impl->Serialize<Stream>(s_);
1271 template <
typename Stream>
1274 m_impl->Unserialize<Stream>(s_);
1285 size_t AddrMan::Size(std::optional<Network> net, std::optional<bool> in_new)
const 1287 return m_impl->Size(net, in_new);
1297 return m_impl->Good(addr, time);
1302 m_impl->Attempt(addr, fCountFailure, time);
1307 m_impl->ResolveCollisions();
1312 return m_impl->SelectTriedCollision();
1315 std::pair<CAddress, NodeSeconds>
AddrMan::Select(
bool new_only, std::optional<Network> network)
const 1317 return m_impl->Select(new_only, network);
1320 std::vector<CAddress>
AddrMan::GetAddr(
size_t max_addresses,
size_t max_pct, std::optional<Network> network)
const 1322 return m_impl->GetAddr(max_addresses, max_pct, network);
1327 return m_impl->GetEntries(use_tried);
1332 m_impl->Connected(addr, time);
1337 m_impl->SetServices(addr, nServices);
1342 return m_impl->FindAddressEntry(addr);
Wrapper that overrides the GetParams() function of a stream (and hides GetVersion/GetType).
const std::unique_ptr< AddrManImpl > m_impl
void Connected(const CService &addr, NodeSeconds time) EXCLUSIVE_LOCKS_REQUIRED(!cs)
std::vector< unsigned char > GetGroup(const CNetAddr &address) const
Get the canonical identifier of the network group for address.
size_t Size(std::optional< Network > net=std::nullopt, std::optional< bool > in_new=std::nullopt) const
Return size information about addrman.
static constexpr uint8_t INCOMPATIBILITY_BASE
The initial value of a field that is incremented every time an incompatible format change is made (su...
void Connected_(const CService &addr, NodeSeconds time) EXCLUSIVE_LOCKS_REQUIRED(cs)
ServiceFlags
nServices flags
const NetGroupManager & m_netgroupman
Reference to the netgroup manager.
#define LogPrint(category,...)
uint256 GetAsmapChecksum() const
Get a checksum identifying the asmap being used.
bool Good_(const CService &addr, bool test_before_evict, NodeSeconds time) EXCLUSIVE_LOCKS_REQUIRED(cs)
void Unserialize(Stream &s_)
static constexpr int ADDRMAN_BUCKET_SIZE
void SwapRandom(unsigned int nRandomPos1, unsigned int nRandomPos2) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Swap two elements in vRandom.
std::pair< CAddress, NodeSeconds > Select(bool new_only, std::optional< Network > network) const EXCLUSIVE_LOCKS_REQUIRED(!cs)
int GetEntry(bool use_tried, size_t bucket, size_t position) const EXCLUSIVE_LOCKS_REQUIRED(cs)
Helper to generalize looking up an addrman entry from either table.
std::optional< AddressPosition > FindAddressEntry(const CAddress &addr)
Test-only function Find the address record in AddrMan and return information about its position...
std::vector< std::pair< AddrInfo, AddressPosition > > GetEntries_(bool from_tried) const EXCLUSIVE_LOCKS_REQUIRED(cs)
static constexpr int ADDRMAN_TRIED_BUCKET_COUNT
std::vector< CAddress > GetAddr(size_t max_addresses, size_t max_pct, std::optional< Network > network) const EXCLUSIVE_LOCKS_REQUIRED(!cs)
void Attempt_(const CService &addr, bool fCountFailure, NodeSeconds time) EXCLUSIVE_LOCKS_REQUIRED(cs)
static constexpr int32_t ADDRMAN_MAX_FAILURES
How many successive failures are allowed ...
bool Add_(const std::vector< CAddress > &vAddr, const CNetAddr &source, std::chrono::seconds time_penalty) EXCLUSIVE_LOCKS_REQUIRED(cs)
size_t Size_(std::optional< Network > net, std::optional< bool > in_new) const EXCLUSIVE_LOCKS_REQUIRED(cs)
static constexpr SerParams V1_DISK
std::pair< CAddress, NodeSeconds > Select_(bool new_only, std::optional< Network > network) const EXCLUSIVE_LOCKS_REQUIRED(cs)
int nRandomPos
position in vRandom
int CheckAddrman() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Perform consistency check, regardless of m_consistency_check_ratio.
size_t Size(std::optional< Network > net, std::optional< bool > in_new) const EXCLUSIVE_LOCKS_REQUIRED(!cs)
static constexpr size_t ADDRMAN_SET_TRIED_COLLISION_SIZE
The maximum number of tried addr collisions to store.
int GetBucketPosition(const uint256 &nKey, bool fNew, int bucket) const
Calculate in which position of a bucket to store this entry.
Non-refcounted RAII wrapper for FILE*.
enum Network GetNetwork() const
void ResolveCollisions()
See if any to-be-evicted tried table entries have been tested and if so resolve the collisions...
std::string ToStringAddrPort() const
uint256 nKey
secret key to randomize bucket select with
std::pair< CAddress, NodeSeconds > SelectTriedCollision_() EXCLUSIVE_LOCKS_REQUIRED(cs)
void ResolveCollisions() EXCLUSIVE_LOCKS_REQUIRED(!cs)
static constexpr int32_t ADDRMAN_RETRIES
After how many failed attempts we give up on a new node.
std::chrono::time_point< NodeClock, std::chrono::seconds > NodeSeconds
static constexpr SerParams V2_DISK
int nAttempts
connection attempts since last successful attempt
void ResolveCollisions_() EXCLUSIVE_LOCKS_REQUIRED(cs)
std::pair< CAddress, NodeSeconds > SelectTriedCollision() EXCLUSIVE_LOCKS_REQUIRED(!cs)
NodeSeconds m_last_try
last try whatsoever by us (memory only)
bool Add(const std::vector< CAddress > &vAddr, const CNetAddr &source, std::chrono::seconds time_penalty=0s)
Attempt to add one or more addresses to addrman's new table.
std::vector< CAddress > GetAddr_(size_t max_addresses, size_t max_pct, std::optional< Network > network) const EXCLUSIVE_LOCKS_REQUIRED(cs)
int nRefCount
reference count in new sets (memory only)
static constexpr auto ADDRMAN_MIN_FAIL
...
Double ended buffer combining vector and stream-like interfaces.
void Attempt(const CService &addr, bool fCountFailure, NodeSeconds time) EXCLUSIVE_LOCKS_REQUIRED(!cs)
A combination of a network address (CNetAddr) and a (TCP) port.
A writer stream (for serialization) that computes a 256-bit hash.
Extended statistics about a CAddress.
void Attempt(const CService &addr, bool fCountFailure, NodeSeconds time=Now< NodeSeconds >())
Mark an entry as connection attempted to.
NodeSeconds m_last_count_attempt
last counted attempt (memory only)
A CService with information about it as peer.
void Connected(const CService &addr, NodeSeconds time=Now< NodeSeconds >())
We have successfully connected to this peer.
std::vector< unsigned char > GetKey() const
void Serialize(Stream &s_) const EXCLUSIVE_LOCKS_REQUIRED(!cs)
uint32_t GetMappedAS(const CNetAddr &address) const
Get the autonomous system on the BGP path to address.
bool Add(const std::vector< CAddress > &vAddr, const CNetAddr &source, std::chrono::seconds time_penalty) EXCLUSIVE_LOCKS_REQUIRED(!cs)
NodeSeconds nTime
Always included in serialization. The behavior is unspecified if the value is not representable as ui...
int GetNewBucket(const uint256 &nKey, const CNetAddr &src, const NetGroupManager &netgroupman) const
Calculate in which "new" bucket this entry belongs, given a certain source.
void Serialize(Stream &s_) const
void ClearNew(int nUBucket, int nUBucketPos) EXCLUSIVE_LOCKS_REQUIRED(cs)
Clear a position in a "new" table. This is the only place where entries are actually deleted...
std::vector< CAddress > GetAddr(size_t max_addresses, size_t max_pct, std::optional< Network > network) const
Return all or many randomly selected addresses, optionally by network.
void Check() const EXCLUSIVE_LOCKS_REQUIRED(cs)
Consistency check, taking into account m_consistency_check_ratio.
#define Assume(val)
Assume is the identity function.
static constexpr Format FILE_FORMAT
The maximum format this software knows it can unserialize.
Format
Serialization versions.
std::pair< CAddress, NodeSeconds > Select(bool new_only=false, std::optional< Network > network=std::nullopt) const
Choose an address to connect to.
bool IsTerrible(NodeSeconds now=Now< NodeSeconds >()) const
Determine whether the statistics about this entry are bad enough so that it can just be deleted...
void Unserialize(Stream &s_) EXCLUSIVE_LOCKS_REQUIRED(!cs)
static time_point now() noexcept
Return current system time or mocked time, if set.
std::pair< CAddress, NodeSeconds > SelectTriedCollision()
Randomly select an address in the tried table that another address is attempting to evict...
ServiceFlags nServices
Serialized as uint64_t in V1, and as CompactSize in V2.
AddrInfo * Find(const CService &addr, int *pnId=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs)
Find an entry.
bool Good(const CService &addr, NodeSeconds time) EXCLUSIVE_LOCKS_REQUIRED(!cs)
AddrManImpl(const NetGroupManager &netgroupman, bool deterministic, int32_t consistency_check_ratio)
double GetChance(NodeSeconds now=Now< NodeSeconds >()) const
Calculate the relative chance this entry should be given when selecting nodes to connect to...
void MakeTried(AddrInfo &info, int nId) EXCLUSIVE_LOCKS_REQUIRED(cs)
Move an entry from the "new" table(s) to the "tried" table.
std::vector< std::pair< AddrInfo, AddressPosition > > GetEntries(bool from_tried) const EXCLUSIVE_LOCKS_REQUIRED(!cs)
static constexpr int ADDRMAN_NEW_BUCKET_COUNT
static constexpr uint32_t ADDRMAN_TRIED_BUCKETS_PER_GROUP
Over how many buckets entries with tried addresses from a single group (/16 for IPv4) are spread...
void Delete(int nId) EXCLUSIVE_LOCKS_REQUIRED(cs)
Delete an entry. It must not be in tried, and have refcount 0.
void SetServices(const CService &addr, ServiceFlags nServices)
Update an entry's service bits.
Writes data to an underlying source stream, while hashing the written data.
bool fInTried
in tried set? (memory only)
std::optional< AddressPosition > FindAddressEntry_(const CAddress &addr) EXCLUSIVE_LOCKS_REQUIRED(cs)
Reads data from an underlying stream, while hashing the read data.
bool AddSingle(const CAddress &addr, const CNetAddr &source, std::chrono::seconds time_penalty) EXCLUSIVE_LOCKS_REQUIRED(cs)
Attempt to add a single address to addrman's new table.
static constexpr auto ADDRMAN_REPLACEMENT
How recent a successful connection should be before we allow an address to be evicted from tried...
std::set< int > m_tried_collisions
Holds addrs inserted into tried table that collide with existing entries. Test-before-evict disciplin...
Location information for an address in AddrMan.
Mutex cs
A mutex to protect the inner data structures.
static constexpr auto ADDRMAN_TEST_WINDOW
The maximum time we'll spend trying to resolve a tried table collision.
const int32_t m_consistency_check_ratio
Perform consistency checks every m_consistency_check_ratio operations (if non-zero).
bool Good(const CService &addr, NodeSeconds time=Now< NodeSeconds >())
Mark an address record as accessible and attempt to move it to addrman's tried table.
int GetTriedBucket(const uint256 &nKey, const NetGroupManager &netgroupman) const
Calculate in which "tried" bucket this entry belongs.
std::optional< AddressPosition > FindAddressEntry(const CAddress &addr) EXCLUSIVE_LOCKS_REQUIRED(!cs)
AddrInfo * Create(const CAddress &addr, const CNetAddr &addrSource, int *pnId=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs)
Create a new entry and add it to the internal data structures mapInfo, mapAddr and vRandom...
void SetServices(const CService &addr, ServiceFlags nServices) EXCLUSIVE_LOCKS_REQUIRED(!cs)
NodeSeconds m_last_success
last successful connection by us
static constexpr auto ADDRMAN_HORIZON
How old addresses can maximally be.
static constexpr int32_t ADDRMAN_NEW_BUCKETS_PER_ADDRESS
Maximum number of times an address can occur in the new table.
std::vector< std::pair< AddrInfo, AddressPosition > > GetEntries(bool from_tried) const
Returns an information-location pair for all addresses in the selected addrman table.
#define LOG_TIME_MILLIS_WITH_CATEGORY_MSG_ONCE(end_msg, log_category)
AddrMan(const NetGroupManager &netgroupman, bool deterministic, int32_t consistency_check_ratio)
void SetServices_(const CService &addr, ServiceFlags nServices) EXCLUSIVE_LOCKS_REQUIRED(cs)
static constexpr uint32_t ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP
Over how many buckets entries with new addresses originating from a single group are spread...