6#include <chainparams.h>
28 return std::clamp<int32_t>(g_setup->
m_node.
args->
GetIntArg(
"-checkaddrman", 0), 0, 1000000);
35 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
36 g_setup = testing_setup.get();
45 auto addr_man_ptr{std::make_unique<AddrManDeterministic>(netgroupman, fuzzed_data_provider,
GetCheckRatio())};
46 if (fuzzed_data_provider.ConsumeBool()) {
51 }
catch (
const std::ios_base::failure&) {
52 addr_man_ptr = std::make_unique<AddrManDeterministic>(netgroupman, fuzzed_data_provider,
GetCheckRatio());
60 CreateSock = [&fuzzed_data_provider](int, int, int) {
61 return std::make_unique<FuzzedSock>(fuzzed_data_provider);
66 g_dns_lookup = [&fuzzed_data_provider](
const std::string&, bool) {
67 return std::vector<CNetAddr>{
ConsumeNetAddr(fuzzed_data_provider)};
70 ConnmanTestMsg connman{fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
71 fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
75 fuzzed_data_provider.ConsumeBool(),
78 const uint64_t max_outbound_limit{fuzzed_data_provider.ConsumeIntegral<uint64_t>()};
82 connman.Init(options);
88 std::string random_string;
92 connman.AddTestNode(p2p_node);
108 random_string = fuzzed_data_provider.ConsumeRandomLengthString(64);
111 connman.AddNode({random_string, fuzzed_data_provider.ConsumeBool()});
114 connman.CheckIncomingNonce(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
117 connman.DisconnectNode(fuzzed_data_provider.ConsumeIntegral<
NodeId>());
120 connman.DisconnectNode(random_netaddr);
123 connman.DisconnectNode(random_string);
126 connman.DisconnectNode(random_subnet);
129 connman.ForEachNode([](
auto) {});
132 (void)connman.ForNode(fuzzed_data_provider.ConsumeIntegral<
NodeId>(), [&](
auto) {
return fuzzed_data_provider.ConsumeBool(); });
135 auto max_addresses = fuzzed_data_provider.ConsumeIntegral<
size_t>();
136 auto max_pct = fuzzed_data_provider.ConsumeIntegralInRange<
size_t>(0, 100);
137 auto filtered = fuzzed_data_provider.ConsumeBool();
138 (void)connman.GetAddressesUnsafe(max_addresses, max_pct, std::nullopt, filtered);
141 auto max_addresses = fuzzed_data_provider.ConsumeIntegral<
size_t>();
142 auto max_pct = fuzzed_data_provider.ConsumeIntegralInRange<
size_t>(0, 100);
143 (void)connman.GetAddresses(random_node, max_addresses, max_pct);
146 (void)connman.GetDeterministicRandomizer(fuzzed_data_provider.ConsumeIntegral<uint64_t>());
152 (void)connman.OutboundTargetReached(fuzzed_data_provider.ConsumeBool());
158 connman.PushMessage(&random_node, std::move(serialized_net_msg));
161 connman.RemoveAddedNode(random_string);
164 connman.SetNetworkActive(fuzzed_data_provider.ConsumeBool());
167 connman.SetTryNewOutboundPeer(fuzzed_data_provider.ConsumeBool());
176 connman.OpenNetworkConnection(
178 fuzzed_data_provider.ConsumeBool(),
180 fuzzed_data_provider.ConsumeBool() ?
nullptr : random_string.c_str(),
182 fuzzed_data_provider.ConsumeBool());
185 connman.SetNetworkActive(fuzzed_data_provider.ConsumeBool());
187 connman.CreateNodeFromAcceptedSocketPublic(
188 CreateSock(AF_INET, SOCK_STREAM, IPPROTO_TCP),
198 options.
vWhiteBinds = std::vector<NetWhitebindPermissions>{
199 fuzzed_data_provider.ConsumeIntegralInRange<
size_t>(0, 5)};
210 connman.InitBindsPublic(options);
213 connman.SocketHandlerPublic();
216 (void)connman.GetAddedNodeInfo(fuzzed_data_provider.ConsumeBool());
217 (void)connman.GetExtraFullOutboundCount();
218 (void)connman.GetLocalServices();
219 assert(connman.GetMaxOutboundTarget() == max_outbound_limit);
220 (void)connman.GetMaxOutboundTimeframe();
221 (void)connman.GetMaxOutboundTimeLeftInCycle();
222 (void)connman.GetNetworkActive();
223 std::vector<CNodeStats> stats;
224 connman.GetNodeStats(stats);
225 (void)connman.GetOutboundTargetBytesLeft();
226 (void)connman.GetTotalBytesRecv();
227 (void)connman.GetTotalBytesSent();
228 (void)connman.GetTryNewOutboundPeer();
229 (void)connman.GetUseAddrmanOutgoing();
230 (void)connman.ASMapHealthCheck();
232 connman.ClearTestNodes();
static int32_t GetCheckRatio(const NodeContext &node_ctx)
const CChainParams & Params()
Return the currently selected parameters.
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.
Information about a peer.
Double ended buffer combining vector and stream-like interfaces.
ConnectionType
Different types of connections to a peer.
@ OUTBOUND_FULL_RELAY
These are the default connections that we use to connect with the network.
@ INBOUND
Inbound connections are those initiated by a peer.
void initialize_connman()
FUZZ_TARGET(connman,.init=initialize_connman)
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
std::function< std::unique_ptr< Sock >(int, int, int)> CreateSock
Socket factory.
std::vector< NetWhitebindPermissions > vWhiteBinds
uint64_t nMaxOutboundLimit
std::vector< CService > onion_binds
NetEventsInterface * m_msgproc
std::vector< CService > vBinds
bool bind_on_any
True if the user did not specify -bind= or -whitebind= and thus we should bind on 0....
std::vector< unsigned char > data
Testing setup that configures a complete environment.
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
CSubNet ConsumeSubNet(FuzzedDataProvider &fuzzed_data_provider) noexcept
NetGroupManager ConsumeNetGroupManager(FuzzedDataProvider &fuzzed_data_provider) noexcept
std::unique_ptr< CNode > ConsumeNodeAsUniquePtr(FuzzedDataProvider &fdp, const std::optional< NodeId > &node_id_in=std::nullopt)
std::vector< CService > ConsumeServiceVector(FuzzedDataProvider &fuzzed_data_provider, size_t max_vector_size=5) noexcept
auto ConsumeNode(FuzzedDataProvider &fuzzed_data_provider, const std::optional< NodeId > &node_id_in=std::nullopt) noexcept
FuzzedNetEvents ConsumeNetEvents(FuzzedDataProvider &fdp) noexcept
std::shared_ptr< CThreadInterrupt > ConsumeThreadInterrupt(FuzzedDataProvider &fuzzed_data_provider)
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
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 ConnectionType ALL_CONNECTION_TYPES[]
constexpr NetPermissionFlags ALL_NET_PERMISSION_FLAGS[]
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.