31 static const auto testing_setup = MakeNoLogFileContext<TestingSetup>(
38constexpr std::array INBOUND_MSG_TYPES{
67 node.addrman = std::make_unique<AddrMan>(
68 *
node.netgroupman,
true, 0);
73 .reconcile_txs = true,
74 .deterministic_rng = true,
76 connman.SetMsgProc(
node.peerman.get());
77 connman.SetAddrman(*
node.addrman);
82 std::vector<CTransactionRef> seeded_txs;
83 for (
int i = 0; i < num_txs; ++i) {
85 (void)
node.peerman->InitiateTxBroadcastPrivate(tx);
86 seeded_txs.push_back(tx);
93 std::vector<CNode*> peers;
107 peers.push_back(pb_node);
108 connman.AddTestNode(*pb_node);
111 connman.SetCaptureMessages(
true);
114 std::optional<uint64_t> pb_ping_nonce;
116 std::span<const unsigned char>
data,
bool is_incoming) {
117 if (is_incoming || addr != pb_addr)
return;
122 pb_ping_nonce =
nonce;
128 uint64_t my_services, your_services, my_services_dup,
nonce;
131 std::string user_agent;
134 ds >> version >> my_services >> my_time >>
137 nonce >> user_agent >> height >> relay;
143 Assert(user_agent ==
"/pynode:0.0.1/");
150 std::vector<CInv> invs;
153 Assert(invs[0].IsMsgTx());
167 for (
int i = 0; i < extra_peers; ++i) {
171 if (extra_peer->addr == pb_addr)
continue;
172 peers.push_back(extra_peer.release());
173 connman.AddTestNode(*peers.back());
174 node.peerman->InitializeNode(
187 std::optional<CSerializedNetMsg> net_msg;
199 (void)
node.peerman->InitiateTxBroadcastPrivate(
206 !seeded_txs.empty()) {
210 std::vector<CInv>{{
MSG_TX, tx->GetHash().ToUint256()}}));
215 if (&p2p_node == pb_node && pb_ping_nonce) {
224 !seeded_txs.empty()) {
231 if (net_msg->data.empty()) {
234 connman.FlushSendBuffer(p2p_node);
235 (void)connman.ReceiveMsgFrom(p2p_node, std::move(*net_msg));
237 bool more_work{
true};
241 more_work = connman.ProcessMessagesOnce(p2p_node);
242 }
catch (
const std::ios_base::failure&) {
244 node.peerman->SendMessages(p2p_node);
250 connman.SetCaptureMessages(
false);
252 node.connman->StopNodes();
const TestingSetup * g_setup
#define Assert(val)
Identity function.
A CService with information about it as peer.
static constexpr SerParams V1
Information about a peer.
std::atomic_bool fSuccessfullyConnected
fSuccessfullyConnected is set to true on receiving VERACK from the peer.
std::atomic_bool fPauseSend
bool IsPrivateBroadcastConn() const
std::atomic_bool fDisconnect
A combination of a network address (CNetAddr) and a (TCP) port.
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)
static Mutex g_msgproc_mutex
Mutex for anything that is only accessed via the msg processing thread.
static std::unique_ptr< PeerManager > make(CConnman &connman, AddrMan &addrman, BanMan *banman, ChainstateManager &chainman, CTxMemPool &pool, node::Warnings &warnings, Options opts)
Minimal stream for reading from an existing byte array by std::span.
static const PrecomputedData data
Precomputed COutPoint and CCoins values.
LIMITED_WHILE(provider.remaining_bytes(), 10000)
@ PRIVATE_BROADCAST
Private broadcast connections are short-lived and only opened to privacy networks (Tor,...
CSerializedNetMsg Make(std::string msg_type, Args &&... args)
constexpr const char * PONG
The pong message replies to a ping message, proving to the pinging node that the ponging node is stil...
constexpr const char * PING
The ping message is sent periodically to help confirm that the receiving peer is still connected.
constexpr const char * VERACK
The verack message acknowledges a previously-received version message, informing the connecting node ...
constexpr const char * GETDATA
The getdata message requests one or more data objects from another node.
constexpr const char * INV
The inv message (inventory message) transmits one or more inventories of objects known to the transmi...
constexpr const char * TX
The tx message transmits a single transaction.
constexpr const char * VERSION
The version message provides information about the transmitting node to the receiving node at the beg...
std::function< void(const CAddress &addr, const std::string &msg_type, std::span< const unsigned char > data, bool is_incoming)> CaptureMessage
Defaults to CaptureMessageToFile(), but can be overridden by unit tests.
static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH
Maximum length of incoming protocol messages (no message over 4 MB is currently acceptable).
FUZZ_TARGET(p2p_private_broadcast,.init=::initialize)
static constexpr TransactionSerParams TX_WITH_WITNESS
static CTransactionRef MakeTransactionRef(Tx &&txIn)
ServiceFlags
nServices flags
static const int WTXID_RELAY_VERSION
"wtxidrelay" message type for wtxid-based relay starts with this version
static const int PROTOCOL_VERSION
network protocol versioning
void Reset()
Reset the internal state.
Testing setup that configures a complete environment.
SeedRandomStateForTest(SeedRand::ZEROS)
CAddress ConsumeAddress(FuzzedDataProvider &fuzzed_data_provider) noexcept
std::unique_ptr< CNode > ConsumeNodeAsUniquePtr(FuzzedDataProvider &fdp, FakeSteadyClock &clock, const std::optional< NodeId > &node_id_in=std::nullopt)
CMutableTransaction ConsumeTransaction(FuzzedDataProvider &fuzzed_data_provider, const std::optional< std::vector< Txid > > &prevout_txids, const int max_num_in, const int max_num_out) 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
@ ZEROS
Seed with a compile time constant of zeros.
FuzzedDataProvider & fuzzed_data_provider