34 static const auto testing_setup = MakeNoLogFileContext<>();
52 bool force_read_and_write_to_err{
false};
53 if (start_with_corrupted_banlist) {
58 if (force_read_and_write_to_err) {
59 banlist_file = fs::path{
"path"} /
"to" /
"inaccessible" /
"fuzzed_banlist";
68 bool contains_invalid{
false};
75 if (!net_addr.IsCJDNS() || !net_addr.IsValid()) {
76 const std::optional<CNetAddr>& addr{
LookupHost(net_addr.ToStringAddr(),
false)};
77 if (addr.has_value() && addr->IsValid()) {
80 contains_invalid =
true;
85 ban_man.Ban(net_addr, ban_time_offset, since_unix_epoch);
90 if (!subnet.IsValid()) {
91 contains_invalid =
true;
95 ban_man.Ban(subnet, ban_time_offset, since_unix_epoch);
98 ban_man.ClearBanned();
114 ban_man.GetBanned(banmap);
117 ban_man.DumpBanlist();
126 if (!force_read_and_write_to_err) {
127 ban_man.DumpBanlist();
130 ban_man.GetBanned(banmap);
131 BanMan ban_man_read{banlist_file,
nullptr, 0};
134 if (!contains_invalid) {
135 assert(banmap == banmap_read);
fs::path GetDataDirNet() const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Get data directory path with appended network identifier.
void GetBanned(banmap_t &banmap) EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex)
std::string ConsumeRandomLengthString(size_t max_length)
T ConsumeIntegralInRange(T min, T max)
Helper to initialize the global NodeClock, let a duration elapse, and reset it after use in a test.
static std::string PathToString(const path &path)
Convert path object to a byte string.
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
std::map< CSubNet, CBanEntry > banmap_t
CSubNet LookupSubNet(const std::string &subnet_str)
Parse and resolve a specified subnet string into the appropriate internal representation.
std::vector< CNetAddr > LookupHost(const std::string &name, unsigned int nMaxSolutions, bool fAllowLookup, DNSLookupFn dns_lookup_function)
Resolve a host string to its corresponding network addresses.
bool WriteBinaryFile(const fs::path &filename, const std::string &data)
Write contents of std::string to a file.
FUZZ_TARGET(banman,.init=initialize_banman)
static bool operator==(const CBanEntry &lhs, const CBanEntry &rhs)
CNetAddr ConsumeNetAddr(FuzzedDataProvider &fuzzed_data_provider, FastRandomContext *rand) noexcept
Create a CNetAddr.
CSubNet ConsumeSubNet(FuzzedDataProvider &fuzzed_data_provider) noexcept
NodeSeconds ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
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.
FuzzedDataProvider & fuzzed_data_provider