Add listener interface to listen for recovered sigs

This commit is contained in:
Alexander Block 2019-01-22 14:12:04 +01:00
parent 189cee2108
commit 9f211ef12d
2 changed files with 32 additions and 0 deletions

View File

@ -414,8 +414,10 @@ void CSigningManager::ProcessRecoveredSig(NodeId nodeId, const CRecoveredSig& re
connman.RemoveAskFor(recoveredSig.GetHash());
}
std::vector<CRecoveredSigsListener*> listeners;
{
LOCK(cs);
listeners = recoveredSigsListeners;
auto signHash = CLLMQUtils::BuildSignHash(recoveredSig);
@ -435,6 +437,10 @@ void CSigningManager::ProcessRecoveredSig(NodeId nodeId, const CRecoveredSig& re
CInv inv(MSG_QUORUM_RECOVERED_SIG, recoveredSig.GetHash());
g_connman->RelayInv(inv);
for (auto& l : listeners) {
l->HandleNewRecoveredSig(recoveredSig);
}
}
void CSigningManager::Cleanup()
@ -451,6 +457,19 @@ void CSigningManager::Cleanup()
lastCleanupTime = GetTimeMillis();
}
void CSigningManager::RegisterRecoveredSigsListener(CRecoveredSigsListener* l)
{
LOCK(cs);
recoveredSigsListeners.emplace_back(l);
}
void CSigningManager::UnregisterRecoveredSigsListener(CRecoveredSigsListener* l)
{
LOCK(cs);
auto itRem = std::remove(recoveredSigsListeners.begin(), recoveredSigsListeners.end(), l);
recoveredSigsListeners.erase(itRem, recoveredSigsListeners.end());
}
bool CSigningManager::AsyncSignIfMember(Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash)
{
auto& params = Params().GetConsensus().llmqs.at(llmqType);

View File

@ -91,6 +91,14 @@ private:
bool ReadRecoveredSig(Consensus::LLMQType llmqType, const uint256& id, CRecoveredSig& ret);
};
class CRecoveredSigsListener
{
public:
virtual ~CRecoveredSigsListener() {}
virtual void HandleNewRecoveredSig(const CRecoveredSig& recoveredSig) = 0;
};
class CSigningManager
{
friend class CSigSharesManager;
@ -109,6 +117,8 @@ private:
int64_t lastCleanupTime{0};
std::vector<CRecoveredSigsListener*> recoveredSigsListeners;
public:
CSigningManager(bool fMemory);
@ -128,6 +138,9 @@ private:
public:
// public interface
void RegisterRecoveredSigsListener(CRecoveredSigsListener* l);
void UnregisterRecoveredSigsListener(CRecoveredSigsListener* l);
bool AsyncSignIfMember(Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash);
bool HasRecoveredSig(Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash);
bool HasRecoveredSigForId(Consensus::LLMQType llmqType, const uint256& id);