Line data Source code
1 : // Copyright (c) 2024-2026 The Dash Core developers 2 : // Distributed under the MIT software license, see the accompanying 3 : // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 : 5 : #ifndef BITCOIN_MSG_RESULT_H 6 : #define BITCOIN_MSG_RESULT_H 7 : 8 : #include <protocol.h> 9 : #include <uint256.h> 10 : 11 : #include <optional> 12 : #include <string> 13 : #include <utility> 14 : #include <variant> 15 : #include <vector> 16 : 17 : struct MisbehavingError 18 : { 19 : int score; 20 : std::string message; 21 : 22 0 : MisbehavingError(int s) : score{s} {} 23 : 24 : // Constructor does a perfect forwarding reference 25 : template <typename T> 26 0 : MisbehavingError(int s, T&& msg) : 27 0 : score{s}, 28 0 : message{std::forward<T>(msg)} 29 0 : {} 30 : }; 31 : 32 : /** 33 : * This struct is a helper to return values from handlers that are processing 34 : * network messages but implemented outside of net_processing.cpp, 35 : * for example llmq's messages. 36 : * 37 : * These handlers do not supposed to know anything about PeerManager to avoid 38 : * circular dependencies. 39 : * 40 : * See `PeerManagerImpl::PostProcessMessage` to see how each type of return code 41 : * is processed. 42 : */ 43 : struct MessageProcessingResult 44 : { 45 : //! @m_error triggers Misbehaving error with score and optional message if not nullopt 46 : std::optional<MisbehavingError> m_error; 47 : 48 : //! @m_inventory will relay these inventories to connected peers 49 : std::vector<CInv> m_inventory; 50 : 51 : //! @m_transactions will relay transactions to peers which is ready to accept it (some peers does not accept transactions) 52 : std::vector<uint256> m_transactions; 53 : 54 : //! @m_to_erase triggers EraseObjectRequest from PeerManager for this inventory if not nullopt 55 : std::optional<CInv> m_to_erase; 56 : 57 0 : MessageProcessingResult() = default; 58 0 : MessageProcessingResult(CInv inv) : 59 0 : m_inventory({inv}) 60 0 : { 61 0 : } 62 0 : MessageProcessingResult(MisbehavingError error) : 63 0 : m_error(error) 64 0 : {} 65 : 66 : bool empty() const { return !m_error.has_value() && m_inventory.empty() && m_transactions.empty() && !m_to_erase.has_value(); } 67 : }; 68 : 69 : #endif // BITCOIN_MSG_RESULT_H