From 98c852970177c953b0a37c5d7d2e43edcb0f66a1 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 9 Jul 2012 15:49:46 -0700 Subject: [PATCH] Some extra validation operations needed by CLC. --- src/ValidationCollection.cpp | 20 +++++++++++++++++--- src/ValidationCollection.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/ValidationCollection.cpp b/src/ValidationCollection.cpp index 07f88cc38c..4701e9bc54 100644 --- a/src/ValidationCollection.cpp +++ b/src/ValidationCollection.cpp @@ -68,7 +68,7 @@ void ValidationCollection::getValidationCount(const uint256& ledger, bool curren trusted = false; } if (trusted) - ++trusted; + ++trusted; else ++untrusted; } @@ -79,8 +79,8 @@ int ValidationCollection::getTrustedValidationCount(const uint256& ledger) { int trusted = 0; boost::mutex::scoped_lock sl(mValidationLock); - boost::unordered_map::iterator it = mValidations.find(ledger); - if (it != mValidations.end()) + for (boost::unordered_map::iterator it = mValidations.find(ledger), + end = mValidations.end(); it != end; ++it) { for (ValidationSet::iterator vit = it->second.begin(), end = it->second.end(); vit != end; ++vit) { @@ -88,6 +88,20 @@ int ValidationCollection::getTrustedValidationCount(const uint256& ledger) ++trusted; } } + return trusted; +} + +int ValidationCollection::getCurrentValidationCount(uint64 afterTime) +{ + int count = 0; + boost::mutex::scoped_lock sl(mValidationLock); + for (boost::unordered_map::iterator it = mCurrentValidations.begin(), + end = mCurrentValidations.end(); it != end; ++it) + { + if (it->second->isTrusted() && (it->second->getCloseTime() > afterTime)) + ++count; + } + return count; } boost::unordered_map ValidationCollection::getCurrentValidations() diff --git a/src/ValidationCollection.h b/src/ValidationCollection.h index f381337830..c4c82e9d58 100644 --- a/src/ValidationCollection.h +++ b/src/ValidationCollection.h @@ -25,6 +25,7 @@ public: ValidationSet getValidations(const uint256& ledger); void getValidationCount(const uint256& ledger, bool currentOnly, int& trusted, int& untrusted); int getTrustedValidationCount(const uint256& ledger); + int getCurrentValidationCount(uint64 afterTime); boost::unordered_map getCurrentValidations(); };