6#include <chainparams.h>
27int32_t GetCheckRatio()
47 auto addr_man_ptr{std::make_unique<AddrManDeterministic>(netgroupman, fuzzed_data_provider, GetCheckRatio())};
53 }
catch (
const std::ios_base::failure&) {
54 addr_man_ptr = std::make_unique<AddrManDeterministic>(netgroupman, fuzzed_data_provider, GetCheckRatio());
62 CreateSock = [&fuzzed_data_provider, &steady_clock](int, int, int) {
63 return std::make_unique<FuzzedSock>(fuzzed_data_provider, steady_clock);
68 g_dns_lookup = [&fuzzed_data_provider](
const std::string&, bool) {
69 return std::vector<CNetAddr>{
ConsumeNetAddr(fuzzed_data_provider)};
80 const uint64_t max_outbound_limit{fuzzed_data_provider.
ConsumeIntegral<uint64_t>()};
88 const auto use_addrman_outgoing{fuzzed_data_provider.
ConsumeBool()};
92 auto consume_whitelist = [&]() {
94 for (
auto& entry : result) {
103 connman.
Init(options);
113 std::vector<NodeId> node_ids;
114 std::vector<std::string> node_addr_names;
121 node_ids.push_back(p2p_node.
GetId());
127 fuzzed_data_provider,
141 const std::string& node_str = (!node_addr_names.empty() && fuzzed_data_provider.
ConsumeBool())
142 ?
PickValue(fuzzed_data_provider, node_addr_names)
147 assert(!connman.
AddNode({node_str, fuzzed_data_provider.ConsumeBool()}));
149 const auto remove{fuzzed_data_provider.
ConsumeBool()};
177 :
PickValue(fuzzed_data_provider, node_ids);
179 (void)pnode->GetId();
180 (void)pnode->IsInboundConn();
181 (void)pnode->IsFullOutboundConn();
188 auto filtered = fuzzed_data_provider.
ConsumeBool();
194 (void)connman.
GetAddresses(random_node, max_addresses, max_pct);
200 (void)connman.
GetNodeCount(fuzzed_data_provider.
PickValueInArray({ConnectionDirection::None, ConnectionDirection::In, ConnectionDirection::Out, ConnectionDirection::Both}));
209 connman.
PushMessage(&random_node, std::move(serialized_net_msg));
212 const auto set_active{fuzzed_data_provider.
ConsumeBool()};
242 std::optional<Proxy> proxy_override;
260 CreateSock(AF_INET, SOCK_STREAM, IPPROTO_TCP),
270 options.
vWhiteBinds = std::vector<NetWhitebindPermissions>{
289 (void)pnode->
GetId();
299 std::vector<CNodeStats> stats;
302 assert(bytes_left <= max_outbound_limit);
303 if (max_outbound_limit == 0) {
305 assert(time_left_in_cycle == std::chrono::seconds{0});
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.
void RemoveLocalServices(ServiceFlags services)
bool GetNetworkActive() const
bool GetTryNewOutboundPeer() const
std::vector< CAddress > GetAddresses(CNode &requestor, size_t max_addresses, size_t max_pct)
Return addresses from the per-requestor cache.
void SetTryNewOutboundPeer(bool flag)
bool OutboundTargetReached(bool historicalBlockServingLimit) const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex)
uint64_t GetMaxOutboundTarget() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex)
void ForEachNode(const NodeFn &func) EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex)
ServiceFlags GetLocalServices() const
bool AddNode(const AddedNodeParams &add) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex)
std::vector< AddedNodeInfo > GetAddedNodeInfo(bool include_connected) const EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex
CSipHasher GetDeterministicRandomizer(uint64_t id) const
Get a unique deterministic randomizer.
uint64_t GetTotalBytesRecv() const
bool OpenNetworkConnection(const CAddress &addrConnect, bool fCountFailure, CountingSemaphoreGrant<> &&grant_outbound, const char *pszDest, ConnectionType conn_type, bool use_v2transport, const std::optional< Proxy > &proxy_override) EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex
Open a new P2P connection and initialize it with the PeerManager at m_msgproc.
void SetNetworkActive(bool active)
std::chrono::seconds GetMaxOutboundTimeLeftInCycle() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex)
void GetNodeStats(std::vector< CNodeStats > &vstats) const EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex)
void AddLocalServices(ServiceFlags services)
bool ForNode(NodeId id, std::function< bool(CNode *pnode)> func) EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex)
bool RemoveAddedNode(std::string_view node) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex)
std::vector< CAddress > GetAddressesUnsafe(size_t max_addresses, size_t max_pct, std::optional< Network > network, bool filtered=true) const
Return randomly selected addresses.
bool DisconnectNode(std::string_view node) EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex)
void Init(const Options &connOptions) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex
uint64_t GetTotalBytesSent() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex)
size_t GetNodeCount(ConnectionDirection) const EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex)
int GetExtraFullOutboundCount() const EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex)
uint64_t GetOutboundTargetBytesLeft() const EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex)
void PushMessage(CNode *pnode, CSerializedNetMsg &&msg) EXCLUSIVE_LOCKS_REQUIRED(!m_total_bytes_sent_mutex)
bool GetUseAddrmanOutgoing() const
bool CheckIncomingNonce(uint64_t nonce) EXCLUSIVE_LOCKS_REQUIRED(!m_nodes_mutex)
Information about a peer.
bool IsInboundConn() const
const std::string m_addr_name
std::string ConnectionTypeAsString() const
std::atomic_bool fSuccessfullyConnected
fSuccessfullyConnected is set to true on receiving VERACK from the peer.
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()
#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::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.
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
void SocketHandlerPublic()
void CreateNodeFromAcceptedSocketPublic(std::unique_ptr< Sock > sock, NetPermissionFlags permissions, const CAddress &addr_bind, const CAddress &addr_peer)
bool InitBindsPublic(const CConnman::Options &options)
void AddTestNode(CNode &node)
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)