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. 14
      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 (auto const& i: t)
ret |= i.first.template bloomPart<TopicBloomFilter::BitsPerBloom, TopicBloomFilter::size>();
ret |= i.first.template bloomPart<TopicBloomFilter::BitsPerBloom, TopicBloomFilterSize>();
return ret;
}

5
libwhisper/WhisperHost.cpp

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

14
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)
{
RLPStream s;
//sealAndSend(prep(s, StatusPacket, 1) << version());
prep(s, StatusPacket, 2);
s << version();
s << host()->bloom();
@ -58,9 +59,12 @@ bool WhisperPeer::interpret(unsigned _id, RLP const& _r)
if (protocolVersion != version())
disable("Invalid protocol version.");
if (_r.itemCount() > 1) // for backwards compatibility
m_bloom = (FixedHash<TopicBloomFilterSize>)_r[1];
else
{
if (_r.itemCount() > 1) // for backwards compatibility
m_bloom = (FixedHash<TopicBloomFilterSize>)_r[1];
advertizeTopicsOfInterest();
}
for (auto const& m: host()->all())
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));
}
void WhisperPeer::advertizeTopicsOfInterest(FixedHash<TopicBloomFilterSize> const& _bloom)
void WhisperPeer::advertizeTopicsOfInterest()
{
RLPStream s;
prep(s, UpdateTopicFilterPacket, 1);
s << _bloom;
s << host()->bloom();
sealAndSend(s);
}

3
libwhisper/WhisperPeer.h

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

Loading…
Cancel
Save