Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251{252return {ConsumeNetAddr(fuzzed_data_provider), fuzzed_data_provider.ConsumeIntegral<uint16_t>()};253}255inline std::vector<CService> ConsumeServiceVector(FuzzedDataProvider& fuzzed_data_provider,256size_t max_vector_size = 5) noexcept257{258std::vector<CService> ret;259const size_t size = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, max_vector_size);260ret.reserve(size);261for (size_t i = 0; i < size; ++i) {262ret.emplace_back(ConsumeService(fuzzed_data_provider));263}264return ret;265}267CAddress ConsumeAddress(FuzzedDataProvider& fuzzed_data_provider) noexcept;269template <bool ReturnUniquePtr = false>270auto ConsumeNode(FuzzedDataProvider& fuzzed_data_provider, FakeSteadyClock& clock, const std::optional<NodeId>& node_id_in = std::nullopt) noexcept271{272const NodeId node_id = node_id_in.value_or(fuzzed_data_provider.ConsumeIntegralInRange<NodeId>(0, std::numeric_limits<NodeId>::max()));273const auto sock = std::make_shared<FuzzedSock>(fuzzed_data_provider, clock);274const CAddress address = ConsumeAddress(fuzzed_data_provider);275const uint64_t keyed_net_group = fuzzed_data_provider.ConsumeIntegral<uint64_t>();276const uint64_t local_host_nonce = fuzzed_data_provider.ConsumeIntegral<uint64_t>();277const CAddress addr_bind = ConsumeAddress(fuzzed_data_provider);278const std::string addr_name = fuzzed_data_provider.ConsumeRandomLengthString(64);279const ConnectionType conn_type = fuzzed_data_provider.PickValueInArray(ALL_CONNECTION_TYPES);280const bool inbound_onion{conn_type == ConnectionType::INBOUND ? fuzzed_data_provider.ConsumeBool() : false};281const uint64_t network_id = fuzzed_data_provider.ConsumeIntegral<uint64_t>();283NetPermissionFlags permission_flags = ConsumeWeakEnum(fuzzed_data_provider, ALL_NET_PERMISSION_FLAGS);284if constexpr (ReturnUniquePtr) {285return std::make_unique<CNode>(node_id,286sock,287address,288keyed_net_group,289local_host_nonce,290addr_bind,291addr_name,292conn_type,293inbound_onion,294network_id,295CNodeOptions{ .permission_flags = permission_flags });296} else {297return CNode{node_id,298sock,299address,300keyed_net_group,301local_host_nonce,302addr_bind,303addr_name,304conn_type,305inbound_onion,306network_id,307CNodeOptions{ .permission_flags = permission_flags }};308}309}310inline std::unique_ptr<CNode> ConsumeNodeAsUniquePtr(FuzzedDataProvider& fdp, FakeSteadyClock& clock, const std::optional<NodeId>& node_id_in = std::nullopt) { return ConsumeNode<true>(fdp, clock, node_id_in); }312void FillNode(FuzzedDataProvider& fuzzed_data_provider, ConnmanTestMsg& connman, CNode& node) noexcept EXCLUSIVE_LOCKS_REQUIRED(NetEventsInterface::g_msgproc_mutex);314#endif // BITCOIN_TEST_FUZZ_UTIL_NET_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.