6#include <chainparams.h>
36 static const auto testing_setup = MakeNoLogFileContext<const TestingSetup>();
53 }
catch (
const std::ios_base::failure&) {
92 auto consume_whitelist = [&]() {
94 for (
auto& entry : result) {
103 connman.Init(options);
105 const uint64_t total_bytes_recv_initial{connman.GetTotalBytesRecv()};
106 const uint64_t total_bytes_sent_initial{connman.GetTotalBytesSent()};
113 std::vector<NodeId> node_ids;
114 std::vector<std::string> node_addr_names;
119 p2p_node.fSuccessfullyConnected =
true;
120 connman.AddTestNode(p2p_node);
121 node_ids.push_back(p2p_node.GetId());
122 node_addr_names.push_back(p2p_node.m_addr_name);
144 const auto added_node_info{connman.GetAddedNodeInfo(
true)};
147 assert(!connman.AddNode({node_str, fuzzed_data_provider.ConsumeBool()}));
148 assert(added_node_info.size() < connman.GetAddedNodeInfo(
true).size());
151 assert(connman.RemoveAddedNode(node_str));
152 assert(added_node_info.size() == connman.GetAddedNodeInfo(
true).size());
166 connman.DisconnectNode(random_netaddr);
172 connman.DisconnectNode(random_subnet);
178 (void)connman.ForNode(
id, [&](
CNode* pnode) {
179 (void)pnode->
GetId();
189 (void)connman.GetAddressesUnsafe(max_addresses, max_pct, std::nullopt, filtered);
194 (void)connman.GetAddresses(random_node, max_addresses, max_pct);
209 connman.PushMessage(&random_node, std::move(serialized_net_msg));
213 connman.SetNetworkActive(set_active);
214 assert(connman.GetNetworkActive() == set_active);
221 const auto before{connman.GetLocalServices()};
223 connman.AddLocalServices(services);
224 assert((connman.GetLocalServices() & services) == services);
226 connman.RemoveLocalServices(
ServiceFlags(services & ~before));
228 connman.RemoveLocalServices(services);
229 assert((connman.GetLocalServices() & services) == 0);
231 connman.AddLocalServices(
ServiceFlags(services & before));
233 assert(connman.GetLocalServices() == before);
242 std::optional<Proxy> proxy_override;
247 connman.OpenNetworkConnection(
259 connman.CreateNodeFromAcceptedSocketPublic(
260 CreateSock(AF_INET, SOCK_STREAM, IPPROTO_TCP),
270 options.
vWhiteBinds = std::vector<NetWhitebindPermissions>{
282 connman.InitBindsPublic(options);
285 connman.SocketHandlerPublic();
288 connman.ForEachNode([](
CNode* pnode) {
289 (void)pnode->
GetId();
294 (void)connman.GetAddedNodeInfo(
false);
295 (void)connman.GetExtraFullOutboundCount();
296 assert(connman.GetLocalServices() == local_services);
297 assert(connman.GetMaxOutboundTarget() == max_outbound_limit);
298 const auto time_left_in_cycle{connman.GetMaxOutboundTimeLeftInCycle()};
299 std::vector<CNodeStats> stats;
300 connman.GetNodeStats(stats);
301 const auto bytes_left{connman.GetOutboundTargetBytesLeft()};
302 assert(bytes_left <= max_outbound_limit);
303 if (max_outbound_limit == 0) {
305 assert(time_left_in_cycle == std::chrono::seconds{0});
306 assert(!connman.OutboundTargetReached(
false));
307 assert(!connman.OutboundTargetReached(
true));
309 assert(connman.GetTotalBytesRecv() >= total_bytes_recv_initial);
310 assert(connman.GetTotalBytesSent() >= total_bytes_sent_initial);
311 (void)connman.GetTryNewOutboundPeer();
312 assert(connman.GetUseAddrmanOutgoing() == use_addrman_outgoing);
313 (void)connman.ASMapHealthCheck();
315 connman.ClearTestNodes();
static int32_t GetCheckRatio(const NodeContext &node_ctx)
const TestingSetup * g_setup
const CChainParams & Params()
Return the currently selected parameters.
int64_t GetIntArg(const std::string &strArg, int64_t nDefault) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
A CService with information about it as peer.
Information about a peer.
bool IsInboundConn() const
std::string ConnectionTypeAsString() const
bool IsFullOutboundConn() const
Double ended buffer combining vector and stream-like interfaces.
Helper to initialize the global NodeClock, let a duration elapse, and reset it after use in a test.
Helper to initialize the global MockableSteadyClock, let a duration elapse, and reset it after use in...
std::string ConsumeRandomLengthString(size_t max_length)
T ConsumeIntegralInRange(T min, T max)
T PickValueInArray(const T(&array)[size])
ConnectionType
Different types of connections to a peer.
@ PRIVATE_BROADCAST
Private broadcast connections are short-lived and only opened to privacy networks (Tor,...
@ 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.
ServiceFlags
nServices flags
std::vector< NetWhitebindPermissions > vWhiteBinds
uint64_t nMaxOutboundLimit
std::vector< NetWhitelistPermissions > vWhitelistedRangeIncoming
std::vector< CService > onion_binds
NetEventsInterface * m_msgproc
std::vector< CService > vBinds
int m_max_automatic_connections
ServiceFlags m_local_services
bool m_use_addrman_outgoing
bool bind_on_any
True if the user did not specify -bind= or -whitebind= and thus we should bind on 0....
std::vector< NetWhitelistPermissions > vWhitelistedRangeOutgoing
std::vector< unsigned char > data
Testing setup that configures a complete environment.
SeedRandomStateForTest(SeedRand::ZEROS)
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
auto ConsumeNode(FuzzedDataProvider &fuzzed_data_provider, FakeSteadyClock &clock, const std::optional< NodeId > &node_id_in=std::nullopt) noexcept
std::unique_ptr< CNode > ConsumeNodeAsUniquePtr(FuzzedDataProvider &fdp, FakeSteadyClock &clock, const std::optional< NodeId > &node_id_in=std::nullopt)
std::vector< CService > ConsumeServiceVector(FuzzedDataProvider &fuzzed_data_provider, size_t max_vector_size=5) noexcept
FuzzedNetEvents ConsumeNetEvents(FuzzedDataProvider &fdp) noexcept
std::shared_ptr< CThreadInterrupt > ConsumeThreadInterrupt(FuzzedDataProvider &fuzzed_data_provider)
NodeSeconds 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
auto & PickValue(FuzzedDataProvider &fuzzed_data_provider, Collection &col)
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 ConnectionType ALL_CONNECTION_TYPES[]
constexpr NetPermissionFlags ALL_NET_PERMISSION_FLAGS[]
@ ZEROS
Seed with a compile time constant of zeros.
std::string random_string(uint32_t length)
FuzzedDataProvider & fuzzed_data_provider