diff options
author | MacroFake <falke.marco@gmail.com> | 2022-07-11 18:14:36 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-07-12 08:41:24 +0200 |
commit | fa7098947ceff1964812d430e769af6d1ad561bd (patch) | |
tree | c2cf047ea1373c98f356d22478208677325f3a68 /src/test/util | |
parent | 6c0c2620c21f6160235130541b643e9e3910faf8 (diff) | |
download | bitcoin-fa7098947ceff1964812d430e769af6d1ad561bd.tar.xz |
move-only: Version handshake to libtest_util
Diffstat (limited to 'src/test/util')
-rw-r--r-- | src/test/util/net.cpp | 56 | ||||
-rw-r--r-- | src/test/util/net.h | 7 |
2 files changed, 63 insertions, 0 deletions
diff --git a/src/test/util/net.cpp b/src/test/util/net.cpp index 071193b550..2cc1d10513 100644 --- a/src/test/util/net.cpp +++ b/src/test/util/net.cpp @@ -7,10 +7,66 @@ #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}; + + 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; |