diff options
author | MacroFake <falke.marco@gmail.com> | 2022-07-12 17:05:37 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-07-12 17:05:42 +0200 |
commit | dd13d7bf16eae9125c2aca72a484370cead265b8 (patch) | |
tree | 0e188c21c3520d8fe248574a507af15995fefadf /src/test/util | |
parent | 39d111aee769cefee1fc7fedda8973b2e3b3b678 (diff) | |
parent | fa4be8e7c324835d3b9eecb5a3825a4c8f77fb2f (diff) | |
download | bitcoin-dd13d7bf16eae9125c2aca72a484370cead265b8.tar.xz |
Merge bitcoin/bitcoin#25591: move-only: Version handshake to libtest_util
fa4be8e7c324835d3b9eecb5a3825a4c8f77fb2f move-only: InitializeNode to handshake helper (MacroFake)
fa7098947ceff1964812d430e769af6d1ad561bd move-only: Version handshake to libtest_util (MacroFake)
Pull request description:
The version handshake after setting up a peer is an integral part of (unit) testing net processing logic.
Thus, make the helper accessible in libtest_util.
Also, remove the peerman argument from `FillNode`, as it must be equal to connman's peerman, which can then be used instead.
ACKs for top commit:
dergoegge:
ACK fa4be8e7c324835d3b9eecb5a3825a4c8f77fb2f
Tree-SHA512: 8296399dc2c29196bd56584c9b61f1c5a088f96dd3438b07b84e1acf525d867f1e37fdfdeede8a831add25848cda0c221ce3fb873e5ae5ca805a1765aa08eb12
Diffstat (limited to 'src/test/util')
-rw-r--r-- | src/test/util/net.cpp | 58 | ||||
-rw-r--r-- | src/test/util/net.h | 7 |
2 files changed, 65 insertions, 0 deletions
diff --git a/src/test/util/net.cpp b/src/test/util/net.cpp index 071193b550..e70ad036bd 100644 --- a/src/test/util/net.cpp +++ b/src/test/util/net.cpp @@ -7,10 +7,68 @@ #include <chainparams.h> #include <node/eviction.h> #include <net.h> +#include <net_processing.h> +#include <netmessagemaker.h> #include <span.h> #include <vector> +void ConnmanTestMsg::Handshake(CNode& node, + bool successfully_connected, + ServiceFlags remote_services, + NetPermissionFlags permission_flags, + int32_t version, + bool relay_txs) +{ + auto& peerman{static_cast<PeerManager&>(*m_msgproc)}; + auto& connman{*this}; + const CNetMsgMaker mm{0}; + + peerman.InitializeNode(&node); + + CSerializedNetMsg msg_version{ + mm.Make(NetMsgType::VERSION, + version, // + Using<CustomUintFormatter<8>>(remote_services), // + int64_t{}, // dummy time + int64_t{}, // ignored service bits + CService{}, // dummy + int64_t{}, // ignored service bits + CService{}, // ignored + uint64_t{1}, // dummy nonce + std::string{}, // dummy subver + int32_t{}, // dummy starting_height + relay_txs), + }; + + (void)connman.ReceiveMsgFrom(node, msg_version); + node.fPauseSend = false; + connman.ProcessMessagesOnce(node); + { + LOCK(node.cs_sendProcessing); + peerman.SendMessages(&node); + } + if (node.fDisconnect) return; + assert(node.nVersion == version); + assert(node.GetCommonVersion() == std::min(version, PROTOCOL_VERSION)); + assert(node.nServices == remote_services); + CNodeStateStats statestats; + assert(peerman.GetNodeStateStats(node.GetId(), statestats)); + assert(statestats.m_relay_txs == (relay_txs && !node.IsBlockOnlyConn())); + node.m_permissionFlags = permission_flags; + if (successfully_connected) { + CSerializedNetMsg msg_verack{mm.Make(NetMsgType::VERACK)}; + (void)connman.ReceiveMsgFrom(node, msg_verack); + node.fPauseSend = false; + connman.ProcessMessagesOnce(node); + { + LOCK(node.cs_sendProcessing); + peerman.SendMessages(&node); + } + assert(node.fSuccessfullyConnected == true); + } +} + void ConnmanTestMsg::NodeReceiveMsgBytes(CNode& node, Span<const uint8_t> msg_bytes, bool& complete) const { assert(node.ReceiveMsgBytes(msg_bytes, complete)); diff --git a/src/test/util/net.h b/src/test/util/net.h index 34ab9958c6..0cf55f8a22 100644 --- a/src/test/util/net.h +++ b/src/test/util/net.h @@ -39,6 +39,13 @@ struct ConnmanTestMsg : public CConnman { m_nodes.clear(); } + void Handshake(CNode& node, + bool successfully_connected, + ServiceFlags remote_services, + NetPermissionFlags permission_flags, + int32_t version, + bool relay_txs); + void ProcessMessagesOnce(CNode& node) { m_msgproc->ProcessMessages(&node, flagInterruptMsgProc); } void NodeReceiveMsgBytes(CNode& node, Span<const uint8_t> msg_bytes, bool& complete) const; |