27 return fuzzed_data_provider.ConsumeIntegralInRange<int64_t>(std::numeric_limits<int64_t>::min(), std::numeric_limits<int32_t>::max());
48 fs::path banlist_file =
gArgs.GetDataDirNet() /
"fuzzed_banlist";
50 const bool start_with_corrupted_banlist{fuzzed_data_provider.
ConsumeBool()};
51 bool force_read_and_write_to_err{
false};
52 if (start_with_corrupted_banlist) {
56 force_read_and_write_to_err = fuzzed_data_provider.
ConsumeBool();
57 if (force_read_and_write_to_err) {
58 banlist_file = fs::path{
"path"} /
"to" /
"inaccessible" /
"fuzzed_banlist";
63 BanMan ban_man{banlist_file,
nullptr, ConsumeBanTimeOffset(fuzzed_data_provider)};
67 bool contains_invalid{
false};
76 if (addr.has_value() && addr->IsValid()) {
79 contains_invalid =
true;
82 auto ban_time_offset = ConsumeBanTimeOffset(fuzzed_data_provider);
83 auto since_unix_epoch = fuzzed_data_provider.
ConsumeBool();
84 ban_man.
Ban(net_addr, ban_time_offset, since_unix_epoch);
90 contains_invalid =
true;
92 auto ban_time_offset = ConsumeBanTimeOffset(fuzzed_data_provider);
93 auto since_unix_epoch = fuzzed_data_provider.
ConsumeBool();
94 ban_man.
Ban(subnet, ban_time_offset, since_unix_epoch);
125 if (!force_read_and_write_to_err) {
130 BanMan ban_man_read{banlist_file,
nullptr, 0};
133 if (!contains_invalid) {
134 assert(banmap == banmap_read);
138 fs::remove(fs::PathToString(banlist_file +
".json"));
void DumpBanlist() EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex)
void Ban(const CNetAddr &net_addr, int64_t ban_time_offset=0, bool since_unix_epoch=false) EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex)
bool IsBanned(const CNetAddr &net_addr) EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex)
Return whether net_addr is banned.
void GetBanned(banmap_t &banmap) EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex)
void ClearBanned() EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex)
bool Unban(const CNetAddr &net_addr) EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex)
bool IsDiscouraged(const CNetAddr &net_addr) EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex)
Return whether net_addr is discouraged.
void Discourage(const CNetAddr &net_addr) EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex)
std::string ToStringAddr() const
std::string ToString() const
std::string ConsumeRandomLengthString(size_t max_length)
#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.
std::unique_ptr< T > MakeNoLogFileContext(const ChainType chain_type=ChainType::REGTEST, TestOpts opts={})
Make a test setup that has disk access to the debug.log file disabled.
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.
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.