Browse Source

deleted method InstallWatchOnID()

cl-refactor
Vlad Gluhovsky 10 years ago
parent
commit
52cbbda15d
  1. 2
      libwhisper/Common.h
  2. 2
      libwhisper/Interface.h
  3. 66
      libwhisper/WhisperHost.cpp
  4. 2
      libwhisper/WhisperHost.h

2
libwhisper/Common.h

@ -59,7 +59,7 @@ enum WhisperPacket
};
enum { TopicBloomFilterSize = 64 };
enum { WhisperProtocolVersion = 2 };
enum { WhisperProtocolVersion = 3 };
using AbridgedTopic = FixedHash<4>;
using Topic = h256;

2
libwhisper/Interface.h

@ -67,7 +67,7 @@ public:
virtual Topics const& fullTopics(unsigned _id) const = 0;
virtual unsigned installWatch(Topics const& _filter) = 0;
virtual unsigned installWatchOnId(h256 _filterId) = 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;

66
libwhisper/WhisperHost.cpp

@ -85,16 +85,9 @@ void WhisperHost::inject(Envelope const& _m, WhisperPeer* _p)
}
}
void WhisperHost::advertiseTopicsOfInterest()
{
FixedHash<TopicBloomFilterSize> b = bloom();
for (auto i: peerSessions())
i.first->cap<WhisperPeer>().get()->sendTopicsOfInterest(b);
}
void WhisperHost::noteChanged(h256 _messageHash, h256 _filter)
{
Guard l(m_filterLock);
for (auto& i: m_watches)
if (i.second.id == _filter)
{
@ -103,27 +96,26 @@ void WhisperHost::noteChanged(h256 _messageHash, h256 _filter)
}
}
unsigned WhisperHost::installWatchOnId(h256 _h)
{
auto ret = m_watches.size() ? m_watches.rbegin()->first + 1 : 0;
m_watches[ret] = ClientWatch(_h);
cwatshh << "+++" << ret << _h;
return ret;
}
unsigned WhisperHost::installWatch(shh::Topics const& _t)
{
InstalledFilter f(_t);
h256 h = f.filter.sha3();
unsigned ret = 0;
Guard l(m_filterLock);
if (!m_filters.count(h))
m_filters.insert(make_pair(h, f));
DEV_GUARDED(m_filterLock)
{
if (!m_filters.count(h))
m_filters.insert(make_pair(h, f));
m_bloom.addRaw(f.filter.exportBloom());
noteAdvertiseTopicsOfInterest();
ret = m_watches.size() ? m_watches.rbegin()->first + 1 : 0;
m_watches[ret] = ClientWatch(h);
cwatshh << "+++" << ret << h;
return installWatchOnId(h);
m_bloom.addRaw(f.filter.exportBloom());
}
noteAdvertiseTopicsOfInterest();
return ret;
}
h256s WhisperHost::watchMessages(unsigned _watchId)
@ -151,23 +143,25 @@ void WhisperHost::uninstallWatch(unsigned _i)
{
cwatshh << "XXX" << _i;
Guard l(m_filterLock);
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())
DEV_GUARDED(m_filterLock)
{
if (!--fit->second.refCount)
m_filters.erase(fit);
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())
{
if (!--fit->second.refCount)
m_filters.erase(fit);
m_bloom.removeRaw(fit->second.filter.exportBloom());
noteAdvertiseTopicsOfInterest();
m_bloom.removeRaw(fit->second.filter.exportBloom());
}
}
noteAdvertiseTopicsOfInterest();
}
void WhisperHost::doWork()

2
libwhisper/WhisperHost.h

@ -58,7 +58,6 @@ public:
virtual void inject(Envelope const& _e, WhisperPeer* _from = nullptr) override;
virtual Topics const& fullTopics(unsigned _id) const override { try { return m_filters.at(m_watches.at(_id).id).full; } catch (...) { return EmptyTopics; } }
virtual unsigned installWatch(Topics const& _filter) override;
virtual unsigned installWatchOnId(h256 _filterId) override;
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; }
@ -75,7 +74,6 @@ private:
void streamMessage(h256 _m, RLPStream& _s) const;
void noteChanged(h256 _messageHash, h256 _filter);
void advertiseTopicsOfInterest(); ///< send our bloom filter to remote peers
mutable dev::SharedMutex x_messages;
std::map<h256, Envelope> m_messages;

Loading…
Cancel
Save