LCOV - code coverage report
Current view: top level - src - msg_result.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 13 13 100.0 %
Date: 2026-06-25 07:23:43 Functions: 16 27 59.3 %

          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           2 :     MisbehavingError(int s) : score{s} {}
      23             : 
      24             :     // Constructor does a perfect forwarding reference
      25             :     template <typename T>
      26           6 :     MisbehavingError(int s, T&& msg) :
      27           3 :         score{s},
      28           3 :         message{std::forward<T>(msg)}
      29           6 :     {}
      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      644332 :     MessageProcessingResult() = default;
      58       27098 :     MessageProcessingResult(CInv inv) :
      59       13549 :         m_inventory({inv})
      60       13549 :     {
      61       27098 :     }
      62          12 :     MessageProcessingResult(MisbehavingError error) :
      63           4 :         m_error(error)
      64           8 :     {}
      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

Generated by: LCOV version 1.16