8 #include <chainparams.h>
32 return std::clamp<int32_t>(g_setup->
m_node.
args->
GetIntArg(
"-checkaddrman", 0), 0, 1000000);
39 g_setup = testing_setup.get();
57 }
catch (
const std::exception&) {
68 for (
size_t i = 0; i < 8 && !addr.
IsValid(); ++i) {
79 v4_addr.s_addr = 0x05050505;
99 for (
size_t i = 0; i < num_sources; ++i) {
100 const auto source =
RandAddr(fuzzed_data_provider, fast_random_context);
101 const size_t num_addresses = fast_random_context.randrange(500) + 1;
103 for (
size_t j = 0; j < num_addresses; ++j) {
105 const std::chrono::seconds time_penalty{fast_random_context.randrange(100000001)};
106 addrman.
Add({addr},
source, time_penalty);
108 if (n > 0 && addrman.
Size() % n == 0) {
109 addrman.
Good(addr, Now<NodeSeconds>());
113 if (fast_random_context.randrange(10) == 0 && prev_source.IsValid()) {
114 addrman.
Add({addr}, prev_source, time_penalty);
149 auto addrinfo_hasher = [](
const AddrInfo& a) {
151 auto addr_key = a.GetKey();
152 auto source_key = a.source.GetAddrBytes();
153 hasher.
Write(TicksSinceEpoch<std::chrono::seconds>(a.m_last_success));
154 hasher.
Write(a.nAttempts);
155 hasher.
Write(a.nRefCount);
156 hasher.
Write(a.fInTried);
157 hasher.
Write(a.GetNetwork());
158 hasher.
Write(a.source.GetNetwork());
159 hasher.
Write(addr_key.size());
160 hasher.
Write(source_key.size());
161 hasher.
Write(addr_key);
162 hasher.
Write(source_key);
168 std::tie(
static_cast<const CService&
>(rhs), rhs.source, rhs.m_last_success, rhs.nAttempts, rhs.nRefCount, rhs.fInTried);
171 using Addresses = std::unordered_set<
AddrInfo, decltype(addrinfo_hasher), decltype(addrinfo_eq)>;
173 const size_t num_addresses{
m_impl->mapInfo.size()};
175 Addresses addresses{num_addresses, addrinfo_hasher, addrinfo_eq};
176 for (
const auto& [
id, addr] :
m_impl->mapInfo) {
177 addresses.insert(addr);
180 Addresses other_addresses{num_addresses, addrinfo_hasher, addrinfo_eq};
181 for (
const auto& [
id, addr] : other.
m_impl->mapInfo) {
182 other_addresses.insert(addr);
185 if (addresses != other_addresses) {
190 if (
id == -1 && other_id == -1) {
193 if ((
id == -1 && other_id != -1) || (
id != -1 && other_id == -1)) {
196 return m_impl->mapInfo.at(
id) == other.
m_impl->mapInfo.at(other_id);
204 if (!IdsReferToSameAddress(
m_impl->vvNew[i][j], other.
m_impl->vvNew[i][j])) {
213 if (!IdsReferToSameAddress(
m_impl->vvTried[i][j], other.
m_impl->vvTried[i][j])) {
228 auto addr_man_ptr = std::make_unique<AddrManDeterministic>(netgroupman, fuzzed_data_provider);
234 }
catch (
const std::ios_base::failure&) {
235 addr_man_ptr = std::make_unique<AddrManDeterministic>(netgroupman, fuzzed_data_provider);
241 fuzzed_data_provider,
249 std::vector<CAddress> addresses;
268 const AddrMan& const_addr_man{addr_man};
269 std::optional<Network> network;
273 (void)const_addr_man.GetAddr(
278 (void)const_addr_man.Select(fuzzed_data_provider.
ConsumeBool(), network);
279 std::optional<bool> in_new;
283 (void)const_addr_man.Size(network, in_new);
285 data_stream << const_addr_man;
301 data_stream << addr_man1;
302 data_stream >> addr_man2;
303 assert(addr_man1 == addr_man2);
void ReadFromStream(AddrMan &addr, DataStream &ssPeers)
Only used by tests.
static constexpr int ADDRMAN_TRIED_BUCKET_COUNT
static constexpr int ADDRMAN_BUCKET_SIZE
static constexpr int ADDRMAN_NEW_BUCKET_COUNT
static int32_t GetCheckRatio(const NodeContext &node_ctx)
Extended statistics about a CAddress.
CNetAddr source
where knowledge about this address first came from
bool fInTried
in tried set? (memory only)
NodeSeconds m_last_success
last successful connection by us
int nRefCount
reference count in new sets (memory only)
int nAttempts
connection attempts since last successful attempt
AddrManDeterministic(const NetGroupManager &netgroupman, FuzzedDataProvider &fuzzed_data_provider)
bool operator==(const AddrManDeterministic &other) const
Compare with another AddrMan.
Stochastic address manager.
void Connected(const CService &addr, NodeSeconds time=Now< NodeSeconds >())
We have successfully connected to this peer.
const std::unique_ptr< AddrManImpl > m_impl
void Attempt(const CService &addr, bool fCountFailure, NodeSeconds time=Now< NodeSeconds >())
Mark an entry as connection attempted to.
size_t Size(std::optional< Network > net=std::nullopt, std::optional< bool > in_new=std::nullopt) const
Return size information about addrman.
void ResolveCollisions()
See if any to-be-evicted tried table entries have been tested and if so resolve the collisions.
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.
std::pair< CAddress, NodeSeconds > SelectTriedCollision()
Randomly select an address in the tried table that another address is attempting to evict.
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.
void SetServices(const CService &addr, ServiceFlags nServices)
Update an entry's service bits.
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const
Return integer argument or default value.
A CService with information about it as peer.
A combination of a network address (CNetAddr) and a (TCP) port.
uint64_t Finalize() const
Compute the 64-bit SipHash-2-4 of the data written so far.
CSipHasher & Write(uint64_t data)
Hash a 64-bit integer worth of data It is treated as if this was the little-endian interpretation of ...
Double ended buffer combining vector and stream-like interfaces.
T ConsumeIntegralInRange(T min, T max)
T PickValueInArray(const T(&array)[size])
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
NetGroupManager ConsumeNetGroupManager(FuzzedDataProvider &fuzzed_data_provider) noexcept
FUZZ_TARGET(data_stream_addr_man,.init=initialize_addrman)
void FillAddrman(AddrMan &addrman, FuzzedDataProvider &fuzzed_data_provider)
Fill addrman with lots of addresses from lots of sources.
CNetAddr RandAddr(FuzzedDataProvider &fuzzed_data_provider, FastRandomContext &fast_random_context)
Generate a random address.
void initialize_addrman()
CAddress ConsumeAddress(FuzzedDataProvider &fuzzed_data_provider) noexcept
CNetAddr ConsumeNetAddr(FuzzedDataProvider &fuzzed_data_provider, FastRandomContext *rand) noexcept
Create a CNetAddr.
CService ConsumeService(FuzzedDataProvider &fuzzed_data_provider) noexcept
int64_t ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
WeakEnumType ConsumeWeakEnum(FuzzedDataProvider &fuzzed_data_provider, const WeakEnumType(&all_types)[size]) noexcept
DataStream ConsumeDataStream(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
uint256 ConsumeUInt256(FuzzedDataProvider &fuzzed_data_provider) noexcept
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
std::vector< B > ConsumeRandomLengthByteVector(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
std::vector< bool > ConsumeRandomLengthBitVector(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
constexpr ServiceFlags ALL_SERVICE_FLAGS[]
constexpr auto ALL_NETWORKS
#define EXCLUSIVE_LOCKS_REQUIRED(...)
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
std::chrono::time_point< NodeClock, std::chrono::seconds > NodeSeconds
bool SanityCheckASMap(const std::vector< bool > &asmap, int bits)