Browse Source

Merge pull request #2330 from gluk256/_bugfix

libp2p test and bugfix
cl-refactor
Gav Wood 10 years ago
parent
commit
51363e6b62
  1. 12
      libwhisper/WhisperHost.cpp
  2. 3
      libwhisper/WhisperPeer.cpp
  3. 14
      test/libwhisper/whisperTopic.cpp

12
libwhisper/WhisperHost.cpp

@ -94,14 +94,16 @@ unsigned WhisperHost::installWatch(shh::Topics const& _t)
DEV_GUARDED(m_filterLock)
{
if (!m_filters.count(h))
auto it = m_filters.find(h);
if (m_filters.end() == it)
m_filters.insert(make_pair(h, f));
else
it->second.refCount++;
m_bloom.addRaw(f.filter.exportBloom());
ret = m_watches.size() ? m_watches.rbegin()->first + 1 : 0;
m_watches[ret] = ClientWatch(h);
cwatshh << "+++" << ret << h;
m_bloom.addRaw(f.filter.exportBloom());
}
noteAdvertiseTopicsOfInterest();
@ -138,16 +140,16 @@ void WhisperHost::uninstallWatch(unsigned _i)
auto it = m_watches.find(_i);
if (it == m_watches.end())
return;
auto id = it->second.id;
m_watches.erase(it);
auto fit = m_filters.find(id);
if (fit != m_filters.end())
{
m_bloom.removeRaw(fit->second.filter.exportBloom());
if (!--fit->second.refCount)
m_filters.erase(fit);
m_bloom.removeRaw(fit->second.filter.exportBloom());
}
}

3
libwhisper/WhisperPeer.cpp

@ -58,7 +58,10 @@ bool WhisperPeer::interpret(unsigned _id, RLP const& _r)
disable("Invalid protocol version.");
for (auto const& m: host()->all())
{
Guard l(x_unseen);
m_unseen.insert(make_pair(0, m.first));
}
if (session()->id() < host()->host()->id())
sendMessages();

14
test/libwhisper/whisperTopic.cpp

@ -320,7 +320,7 @@ BOOST_AUTO_TEST_CASE(topicAdvertising)
Host host2("second", NetworkPreferences("127.0.0.1", 30305, false));
host2.setIdealPeerCount(1);
auto whost2 = host2.registerCapability(new WhisperHost());
whost2->installWatch(BuildTopicMask("test2"));
unsigned w2 = whost2->installWatch(BuildTopicMask("test2"));
host2.start();
while (!host2.haveNetwork())
@ -354,7 +354,7 @@ BOOST_AUTO_TEST_CASE(topicAdvertising)
BOOST_REQUIRE(bf1);
BOOST_REQUIRE(!whost1->bloom());
whost1->installWatch(BuildTopicMask("test1"));
unsigned w1 = whost1->installWatch(BuildTopicMask("test1"));
for (int i = 0; i < 600; ++i)
{
@ -372,6 +372,16 @@ BOOST_AUTO_TEST_CASE(topicAdvertising)
bf1 = whost1->bloom();
BOOST_REQUIRE_EQUAL(bf1, bf2);
BOOST_REQUIRE(bf1);
unsigned random = 0xC0FFEE;
whost1->uninstallWatch(w1);
whost1->uninstallWatch(random);
whost1->uninstallWatch(w1);
whost1->uninstallWatch(random);
whost2->uninstallWatch(random);
whost2->uninstallWatch(w2);
whost2->uninstallWatch(random);
whost2->uninstallWatch(w2);
}
BOOST_AUTO_TEST_SUITE_END()

Loading…
Cancel
Save