From 15106cef742909134dc61c5d86fd577642ca744d Mon Sep 17 00:00:00 2001 From: Vlad Gluhovsky Date: Fri, 3 Jul 2015 16:33:36 +0200 Subject: [PATCH] another test introduced --- libwhisper/WhisperPeer.cpp | 5 ++--- test/libwhisper/whisperTopic.cpp | 36 +++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/libwhisper/WhisperPeer.cpp b/libwhisper/WhisperPeer.cpp index 27662926e..30a188f2d 100644 --- a/libwhisper/WhisperPeer.cpp +++ b/libwhisper/WhisperPeer.cpp @@ -127,9 +127,8 @@ unsigned WhisperPeer::ratingForPeer(Envelope const& e) const unsigned rating = 0; - DEV_GUARDED(x_bloom) - if (e.matchesBloomFilter(m_bloom)) - ++rating; + if (e.matchesBloomFilter(bloom())) + ++rating; rating *= 256; unsigned ttlReward = (256 > e.ttl() ? 256 - e.ttl() : 0); diff --git a/test/libwhisper/whisperTopic.cpp b/test/libwhisper/whisperTopic.cpp index 82825c5d0..8d0f603bb 100644 --- a/test/libwhisper/whisperTopic.cpp +++ b/test/libwhisper/whisperTopic.cpp @@ -78,7 +78,6 @@ BOOST_AUTO_TEST_CASE(topic) } this_thread::sleep_for(chrono::milliseconds(50)); } - }); Host host2("Test", NetworkPreferences("127.0.0.1", 30300, false)); @@ -384,4 +383,39 @@ BOOST_AUTO_TEST_CASE(topicAdvertising) whost2->uninstallWatch(w2); } +BOOST_AUTO_TEST_CASE(selfAddressed) +{ + VerbosityHolder setTemporaryLevel(10); + cnote << "Testing self-addressed messaging with bloom filter matching..."; + + char const* text = "deterministic pseudorandom test"; + BuildTopicMask mask(text); + + Host host("first", NetworkPreferences("127.0.0.1", 30305, false)); + auto wh = host.registerCapability(new WhisperHost()); + auto watch = wh->installWatch(BuildTopicMask(text)); + + unsigned const sample = 0xFEED; + KeyPair us = KeyPair::create(); + wh->post(us.sec(), RLPStream().append(sample).out(), BuildTopic(text)); + + TopicBloomFilterHash f = wh->bloom(); + Envelope e = Message(RLPStream().append(sample).out()).seal(us.sec(), BuildTopic(text), 50, 50); + bool ok = e.matchesBloomFilter(f); + BOOST_REQUIRE(ok); + + this_thread::sleep_for(chrono::milliseconds(50)); + + unsigned single = 0; + unsigned result = 0; + for (auto j: wh->checkWatch(watch)) + { + Message msg = wh->envelope(j).open(wh->fullTopics(watch)); + single = RLP(msg.payload()).toInt(); + result += single; + } + + BOOST_REQUIRE_EQUAL(sample, result); +} + BOOST_AUTO_TEST_SUITE_END()