Browse Source

Whisper test fix.

cl-refactor
Gav Wood 10 years ago
parent
commit
8f36428c70
  1. 10
      libwhisper/Common.cpp
  2. 16
      test/whisperTopic.cpp

10
libwhisper/Common.cpp

@ -54,10 +54,16 @@ bool TopicFilter::matches(Envelope const& _e) const
{ {
for (TopicMask const& t: m_topicMasks) for (TopicMask const& t: m_topicMasks)
{ {
if (_e.topics().size() == t.size())
for (unsigned i = 0; i < t.size(); ++i) for (unsigned i = 0; i < t.size(); ++i)
if (((t[i].first ^ _e.topics()[i]) & t[i].second) != 0) {
for (auto et: _e.topics())
if (((t[i].first ^ et) & t[i].second) == 0)
goto NEXT_TOPICPART;
// failed to match topicmask against any topics: move on to next mask
goto NEXT_TOPICMASK; goto NEXT_TOPICMASK;
NEXT_TOPICPART:;
}
// all topicmasks matched.
return true; return true;
NEXT_TOPICMASK:; NEXT_TOPICMASK:;
} }

16
test/whisperTopic.cpp

@ -32,7 +32,7 @@ BOOST_AUTO_TEST_SUITE(whisper)
BOOST_AUTO_TEST_CASE(topic) BOOST_AUTO_TEST_CASE(topic)
{ {
g_logVerbosity = 0; g_logVerbosity = 20;
bool started = false; bool started = false;
unsigned result = 0; unsigned result = 0;
@ -40,16 +40,16 @@ BOOST_AUTO_TEST_CASE(topic)
{ {
setThreadName("other"); setThreadName("other");
Host ph("Test", NetworkPreferences(30303, "", false, true)); Host ph("Test", NetworkPreferences(50303, "", false, true));
auto wh = ph.registerCapability(new WhisperHost()); auto wh = ph.registerCapability(new WhisperHost());
ph.start(); ph.start();
started = true; started = true;
/// Only interested in odd packets /// Only interested in odd packets
auto w = wh->installWatch(BuildTopicMask()("odd")); auto w = wh->installWatch(BuildTopicMask("odd"));
for (int i = 0, last = 0; i < 100 && last < 81; ++i) for (int i = 0, last = 0; i < 200 && last < 81; ++i)
{ {
for (auto i: wh->checkWatch(w)) for (auto i: wh->checkWatch(w))
{ {
@ -65,10 +65,12 @@ BOOST_AUTO_TEST_CASE(topic)
while (!started) while (!started)
this_thread::sleep_for(chrono::milliseconds(50)); this_thread::sleep_for(chrono::milliseconds(50));
Host ph("Test", NetworkPreferences(30300, "", false, true)); Host ph("Test", NetworkPreferences(50300, "", false, true));
auto wh = ph.registerCapability(new WhisperHost()); auto wh = ph.registerCapability(new WhisperHost());
this_thread::sleep_for(chrono::milliseconds(500));
ph.start(); ph.start();
ph.connect("127.0.0.1", 30303); this_thread::sleep_for(chrono::milliseconds(500));
ph.connect("127.0.0.1", 50303);
KeyPair us = KeyPair::create(); KeyPair us = KeyPair::create();
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
@ -78,6 +80,8 @@ BOOST_AUTO_TEST_CASE(topic)
} }
listener.join(); listener.join();
g_logVerbosity = 0;
BOOST_REQUIRE_EQUAL(result, 1 + 9 + 25 + 49 + 81); BOOST_REQUIRE_EQUAL(result, 1 + 9 + 25 + 49 + 81);
} }

Loading…
Cancel
Save