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();
51 }
catch (
const std::exception&) {
62 for (
size_t i = 0; i < 8 && !addr.
IsValid(); ++i) {
73 v4_addr.s_addr = 0x05050505;
93 for (
size_t i = 0; i < num_sources; ++i) {
94 const auto source =
RandAddr(fuzzed_data_provider, fast_random_context);
95 const size_t num_addresses = fast_random_context.randrange(500) + 1;
97 for (
size_t j = 0; j < num_addresses; ++j) {
99 const std::chrono::seconds time_penalty{fast_random_context.randrange(100000001)};
100 addrman.
Add({addr},
source, time_penalty);
102 if (n > 0 && addrman.
Size() % n == 0) {
103 addrman.
Good(addr, Now<NodeSeconds>());
107 if (fast_random_context.randrange(10) == 0 && prev_source.IsValid()) {
108 addrman.
Add({addr}, prev_source, time_penalty);
121 auto addr_man_ptr = std::make_unique<AddrManDeterministic>(netgroupman, fuzzed_data_provider,
GetCheckRatio());
127 }
catch (
const std::ios_base::failure&) {
128 addr_man_ptr = std::make_unique<AddrManDeterministic>(netgroupman, fuzzed_data_provider,
GetCheckRatio());
134 fuzzed_data_provider,
142 std::vector<CAddress> addresses;
147 auto time_penalty = std::chrono::seconds{
ConsumeTime(fuzzed_data_provider, 0, 100000000)};
148 addr_man.
Add(addresses, net_addr, time_penalty);
153 addr_man.
Good(addr, time);
157 auto count_failure = fuzzed_data_provider.
ConsumeBool();
159 addr_man.
Attempt(addr, count_failure, time);
172 const AddrMan& const_addr_man{addr_man};
173 std::optional<Network> network;
179 auto filtered = fuzzed_data_provider.
ConsumeBool();
180 (void)const_addr_man.GetAddr(max_addresses, max_pct, network, filtered);
182 std::unordered_set<Network> nets;
188 (void)const_addr_man.Select(fuzzed_data_provider.
ConsumeBool(), nets);
190 std::optional<bool> in_new;
194 (void)const_addr_man.Size(network, in_new);
196 data_stream << const_addr_man;
213 data_stream << addr_man1;
214 data_stream >> addr_man2;
215 assert(addr_man1 == addr_man2);
void ReadFromStream(AddrMan &addr, DataStream &ssPeers)
Only used by tests.
static int32_t GetCheckRatio(const NodeContext &node_ctx)
Stochastic address manager.
void Connected(const CService &addr, NodeSeconds time=Now< NodeSeconds >())
We have successfully connected to this peer.
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.
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.
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
NetGroupManager ConsumeNetGroupManager(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
constexpr ServiceFlags ALL_SERVICE_FLAGS[]
constexpr auto ALL_NETWORKS
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
@ ZEROS
Seed with a compile time constant of zeros.
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
std::chrono::time_point< NodeClock, std::chrono::seconds > NodeSeconds