Browse Source

a minor refactoring

cl-refactor
Vlad Gluhovsky 10 years ago
parent
commit
baf4d450eb
  1. 1
      libwhisper/Interface.h
  2. 6
      libwhisper/WhisperHost.h
  3. 6
      test/libwhisper/bloomFilter.cpp

1
libwhisper/Interface.h

@ -67,7 +67,6 @@ public:
virtual Topics const& fullTopics(unsigned _id) const = 0;
virtual unsigned installWatch(Topics const& _filter) = 0;
// virtual unsigned installWatchOnId(h256 _filterId) = 0;
virtual void uninstallWatch(unsigned _watchId) = 0;
virtual h256s peekWatch(unsigned _watchId) const = 0;
virtual h256s checkWatch(unsigned _watchId) = 0;

6
libwhisper/WhisperHost.h

@ -51,7 +51,8 @@ public:
WhisperHost();
virtual ~WhisperHost();
unsigned protocolVersion() const { return WhisperProtocolVersion; }
void cleanup(); ///< remove old messages
/// remove old messages
void cleanup();
std::map<h256, Envelope> all() const { dev::ReadGuard l(x_messages); return m_messages; }
FixedHash<TopicBloomFilterSize> bloom() const { dev::Guard l(m_filterLock); return m_bloom; }
@ -61,7 +62,8 @@ public:
virtual void uninstallWatch(unsigned _watchId) override;
virtual h256s peekWatch(unsigned _watchId) const override { dev::Guard l(m_filterLock); try { return m_watches.at(_watchId).changes; } catch (...) { return h256s(); } }
virtual h256s checkWatch(unsigned _watchId) override { cleanup(); dev::Guard l(m_filterLock); h256s ret; try { ret = m_watches.at(_watchId).changes; m_watches.at(_watchId).changes.clear(); } catch (...) {} return ret; }
virtual h256s watchMessages(unsigned _watchId) override; ///< returns IDs of messages, which match specific watch criteria
/// returns IDs of messages, which match specific watch criteria
virtual h256s watchMessages(unsigned _watchId) override;
virtual Envelope envelope(h256 _m) const override { try { dev::ReadGuard l(x_messages); return m_messages.at(_m); } catch (...) { return Envelope(); } }
protected:

6
test/libwhisper/bloomFilter.cpp

@ -58,7 +58,7 @@ void testRemoveExistingBloom(TopicBloomFilterShort& _f, AbridgedTopic const& _h)
BOOST_REQUIRE(!_f.containsBloom(_h));
}
double calculateExpected(TopicBloomFilterTest const& f, int const n)
double calculateExpected(TopicBloomFilterTest const& f, int n)
{
int const m = f.size * 8; // number of bits in the bloom
int const k = f.BitsPerBloom; // number of hash functions (e.g. bits set to 1 in every bloom)
@ -79,7 +79,7 @@ double calculateExpected(TopicBloomFilterTest const& f, int const n)
return kBitsSet;
}
double testFalsePositiveRate(TopicBloomFilterTest const& f, int const inserted, Topic& x)
double testFalsePositiveRate(TopicBloomFilterTest const& f, int inserted, Topic& x)
{
int const c_sampleSize = 1000;
int falsePositive = 0;
@ -114,7 +114,7 @@ BOOST_AUTO_TEST_CASE(falsePositiveRate)
double expectedRate = 0;
for (int i = 1; i < 50 && expectedRate < 0.5; ++i)
for (int i = 1; i < 50 && isless(expectedRate, 0.5); ++i)
{
x = sha3(x);
f.addBloom(AbridgedTopic(x));

Loading…
Cancel
Save