diff --git a/libwhisper/Common.h b/libwhisper/Common.h index 4f5bda540..ca84469ae 100644 --- a/libwhisper/Common.h +++ b/libwhisper/Common.h @@ -59,6 +59,7 @@ enum WhisperPacket }; enum { TopicBloomFilterSize = 64 }; +enum { WhisperProtocolVersion = 2 }; using AbridgedTopic = FixedHash<4>; using Topic = h256; diff --git a/libwhisper/WhisperHost.h b/libwhisper/WhisperHost.h index 69a1280aa..75ee15887 100644 --- a/libwhisper/WhisperHost.h +++ b/libwhisper/WhisperHost.h @@ -50,7 +50,7 @@ class WhisperHost: public HostCapability, public Interface, public public: WhisperHost(); virtual ~WhisperHost(); - unsigned protocolVersion() const { return 2; } + unsigned protocolVersion() const { return WhisperProtocolVersion; } void cleanup(); ///< remove old messages std::map all() const { dev::ReadGuard l(x_messages); return m_messages; } FixedHash bloom() const { dev::Guard l(m_filterLock); return m_bloom; } diff --git a/libwhisper/WhisperPeer.cpp b/libwhisper/WhisperPeer.cpp index ff73732ce..97b533bdf 100644 --- a/libwhisper/WhisperPeer.cpp +++ b/libwhisper/WhisperPeer.cpp @@ -117,10 +117,11 @@ void WhisperPeer::noteNewMessage(h256 _h, Envelope const& _m) void WhisperPeer::sendTopicsOfInterest(FixedHash const& _bloom) { + Guard g(x_advertiseTopicsOfInterest); RLPStream s; prep(s, TopicFilterPacket, 1); s << _bloom; sealAndSend(s); - m_advertiseTopicsOfInterest = false; } + diff --git a/libwhisper/WhisperPeer.h b/libwhisper/WhisperPeer.h index 9c242dc1f..1be2df97e 100644 --- a/libwhisper/WhisperPeer.h +++ b/libwhisper/WhisperPeer.h @@ -53,11 +53,11 @@ public: virtual ~WhisperPeer(); WhisperHost* host() const; static std::string name() { return "shh"; } - static u256 version() { return 3; } + static u256 version() { return WhisperProtocolVersion; } static unsigned messageCount() { return PacketCount; } FixedHash bloom() const { dev::Guard g(x_bloom); return m_bloom; } void sendTopicsOfInterest(FixedHash const& _bloom); ///< sends our bloom filter to remote peer - void noteAdvertiseTopicsOfInterest() { m_advertiseTopicsOfInterest = true; } + void noteAdvertiseTopicsOfInterest() { dev::Guard g(x_advertiseTopicsOfInterest); m_advertiseTopicsOfInterest = true; } private: virtual bool interpret(unsigned _id, RLP const&) override; @@ -73,6 +73,7 @@ private: mutable dev::Mutex x_bloom; FixedHash m_bloom; ///< Peer's topics of interest + mutable dev::Mutex x_advertiseTopicsOfInterest; bool m_advertiseTopicsOfInterest; };