Line data Source code
1 : // Copyright (c) 2025 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_LLMQ_NET_SIGNING_H 6 : #define BITCOIN_LLMQ_NET_SIGNING_H 7 : 8 : #include <ctpl_stl.h> 9 : #include <llmq/signing_shares.h> 10 : #include <llmq/types.h> 11 : #include <net_processing.h> 12 : #include <util/threadinterrupt.h> 13 : #include <util/time.h> 14 : #include <validationinterface.h> 15 : 16 : #include <thread> 17 : 18 : #include <memory> 19 : 20 : class CSporkManager; 21 : 22 : namespace llmq { 23 : class CSigSharesManager; 24 : class CSigningManager; 25 : 26 : class NetSigning final : public NetHandler, public CValidationInterface 27 : { 28 : public: 29 11428 : NetSigning(PeerManagerInternal* peer_manager, CSigningManager& sig_manager, CSigSharesManager* shares_manager, 30 : const CSporkManager& sporkman) : 31 2857 : NetHandler(peer_manager), 32 2857 : m_sig_manager{sig_manager}, 33 2857 : m_shares_manager{shares_manager}, 34 2857 : m_sporkman{sporkman} 35 8571 : { 36 2857 : workInterrupt.reset(); 37 5714 : } 38 : void ProcessMessage(CNode& pfrom, const std::string& msg_type, CDataStream& vRecv) override; 39 : 40 : [[nodiscard]] bool ProcessPendingRecoveredSigs(); 41 : void ProcessRecoveredSig(std::shared_ptr<const CRecoveredSig> recoveredSig, bool consider_proactive_relay); 42 : 43 : protected: 44 : // CValidationInterface 45 : void NotifyRecoveredSig(const std::shared_ptr<const CRecoveredSig>& sig, bool proactive_relay) override; 46 : 47 : // NetSigning 48 : void Start() override; 49 : void Stop() override; 50 5714 : void Interrupt() override { workInterrupt(); }; 51 : 52 : private: 53 : void WorkThreadSigning(); 54 : void WorkThreadCleaning(); 55 : void WorkThreadDispatcher(); 56 : 57 : void ProcessPendingSigShares( 58 : std::unordered_map<NodeId, std::vector<CSigShare>>&& sigSharesByNodes, 59 : std::unordered_map<std::pair<Consensus::LLMQType, uint256>, CQuorumCPtr, StaticSaltedHasher>&& quorums); 60 : 61 : void RemoveBannedNodeStates(); 62 : void BanNode(NodeId nodeid); 63 : 64 : private: 65 : CSigningManager& m_sig_manager; 66 : CSigSharesManager* m_shares_manager; 67 : const CSporkManager& m_sporkman; 68 : 69 : CleanupThrottler<NodeClock> cleanupThrottler; 70 : 71 : std::thread signing_thread; 72 : std::thread shares_cleaning_thread; 73 : std::thread shares_dispatcher_thread; 74 : mutable ctpl::thread_pool worker_pool; 75 : 76 : CThreadInterrupt workInterrupt; 77 : }; 78 : 79 : } // namespace llmq 80 : 81 : #endif // BITCOIN_LLMQ_NET_SIGNING_H