Browse Source

protocol changed

cl-refactor
Vlad Gluhovsky 10 years ago
parent
commit
aaec62722e
  1. 6
      libwhisper/Common.cpp
  2. 5
      libwhisper/WhisperHost.cpp
  3. 10
      libwhisper/WhisperPeer.cpp
  4. 3
      libwhisper/WhisperPeer.h

6
libwhisper/Common.cpp

@ -95,12 +95,12 @@ TopicFilter::TopicFilter(RLP const& _r)
} }
} }
FixedHash<TopicBloomFilter::size> TopicFilter::exportBloom() const FixedHash<TopicBloomFilterSize> TopicFilter::exportBloom() const
{ {
FixedHash<TopicBloomFilter::size> ret; FixedHash<TopicBloomFilterSize> ret;
for (TopicMask const& t: m_topicMasks) for (TopicMask const& t: m_topicMasks)
for (auto const& i: t) for (auto const& i: t)
ret |= i.first.template bloomPart<TopicBloomFilter::BitsPerBloom, TopicBloomFilter::size>(); ret |= i.first.template bloomPart<TopicBloomFilter::BitsPerBloom, TopicBloomFilterSize>();
return ret; return ret;
} }

5
libwhisper/WhisperHost.cpp

@ -88,10 +88,7 @@ void WhisperHost::inject(Envelope const& _m, WhisperPeer* _p)
void WhisperHost::advertizeTopicsOfInterest() void WhisperHost::advertizeTopicsOfInterest()
{ {
for (auto i: peerSessions()) for (auto i: peerSessions())
{ i.first->cap<WhisperPeer>().get()->advertizeTopicsOfInterest();
auto w = i.first->cap<WhisperPeer>().get();
w->advertizeTopicsOfInterest(m_bloom);
}
} }
void WhisperHost::noteChanged(h256 _messageHash, h256 _filter) void WhisperHost::noteChanged(h256 _messageHash, h256 _filter)

10
libwhisper/WhisperPeer.cpp

@ -31,6 +31,7 @@ using namespace dev::shh;
WhisperPeer::WhisperPeer(std::shared_ptr<Session> _s, HostCapabilityFace* _h, unsigned _i, CapDesc const&): Capability(_s, _h, _i) WhisperPeer::WhisperPeer(std::shared_ptr<Session> _s, HostCapabilityFace* _h, unsigned _i, CapDesc const&): Capability(_s, _h, _i)
{ {
RLPStream s; RLPStream s;
//sealAndSend(prep(s, StatusPacket, 1) << version());
prep(s, StatusPacket, 2); prep(s, StatusPacket, 2);
s << version(); s << version();
s << host()->bloom(); s << host()->bloom();
@ -58,9 +59,12 @@ bool WhisperPeer::interpret(unsigned _id, RLP const& _r)
if (protocolVersion != version()) if (protocolVersion != version())
disable("Invalid protocol version."); disable("Invalid protocol version.");
else
{
if (_r.itemCount() > 1) // for backwards compatibility if (_r.itemCount() > 1) // for backwards compatibility
m_bloom = (FixedHash<TopicBloomFilterSize>)_r[1]; m_bloom = (FixedHash<TopicBloomFilterSize>)_r[1];
advertizeTopicsOfInterest();
}
for (auto const& m: host()->all()) for (auto const& m: host()->all())
m_unseen.insert(make_pair(0, m.first)); m_unseen.insert(make_pair(0, m.first));
@ -115,10 +119,10 @@ void WhisperPeer::noteNewMessage(h256 _h, Envelope const& _m)
m_unseen.insert(make_pair(rating(_m), _h)); m_unseen.insert(make_pair(rating(_m), _h));
} }
void WhisperPeer::advertizeTopicsOfInterest(FixedHash<TopicBloomFilterSize> const& _bloom) void WhisperPeer::advertizeTopicsOfInterest()
{ {
RLPStream s; RLPStream s;
prep(s, UpdateTopicFilterPacket, 1); prep(s, UpdateTopicFilterPacket, 1);
s << _bloom; s << host()->bloom();
sealAndSend(s); sealAndSend(s);
} }

3
libwhisper/WhisperPeer.h

@ -56,8 +56,7 @@ public:
static u256 version() { return 2; } static u256 version() { return 2; }
static unsigned messageCount() { return PacketCount; } static unsigned messageCount() { return PacketCount; }
FixedHash<TopicBloomFilterSize> const& bloom() const { return m_bloom; } FixedHash<TopicBloomFilterSize> const& bloom() const { return m_bloom; }
void advertizeTopicsOfInterest(FixedHash<TopicBloomFilterSize> const& _bloom); ///< sends our bloom filter to remote peer void advertizeTopicsOfInterest(); ///< sends our bloom filter to remote peer
FixedHash<TopicBloomFilterSize> const& bloom() { return m_bloom; }
private: private:
virtual bool interpret(unsigned _id, RLP const&) override; virtual bool interpret(unsigned _id, RLP const&) override;

Loading…
Cancel
Save