diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index bd09ac9c6..d6f00f7cb 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -583,8 +583,7 @@ Json::Value WebThreeStubServerBase::shh_changed(int const& _id) else { unsigned i = 0; - for (; i < face()->getFilter(_id).size() && !face()->getFilter(_id)[i]; ++i) {} - m = e.open(face()->getFilter(_id)[i], i); + m = e.open(face()->filterKey(_id)); } ret.append(toJson(h, e, m)); } diff --git a/libwhisper/Interface.h b/libwhisper/Interface.h index 1ee36c756..2a14b4a16 100644 --- a/libwhisper/Interface.h +++ b/libwhisper/Interface.h @@ -45,10 +45,18 @@ namespace shh class Watch; +struct FilterKey +{ + unsigned topicIndex = (unsigned)-1; + Secret key; +}; + struct InstalledFilter { InstalledFilter(FullTopic const& _f): full(_f), filter(_f) {} + FilterKey filterKey() const { unsigned i; for (i = 0; i < full.size() && !full[i]; ++i) {} return i < full.size() ? FilterKey{i, full[i]} : FilterKey(); } + FullTopic full; TopicFilter filter; unsigned refCount = 1; @@ -70,7 +78,7 @@ public: virtual void inject(Envelope const& _m, WhisperPeer* _from = nullptr) = 0; - virtual FullTopic getFilter(unsigned _id) const = 0; + virtual FilterKey filterKey(unsigned _id) const = 0; virtual unsigned installWatch(FullTopic const& _mask) = 0; virtual unsigned installWatchOnId(h256 _filterId) = 0; virtual void uninstallWatch(unsigned _watchId) = 0; diff --git a/libwhisper/Message.h b/libwhisper/Message.h index b23e5d576..0eef832eb 100644 --- a/libwhisper/Message.h +++ b/libwhisper/Message.h @@ -45,6 +45,8 @@ enum IncludeNonce WithNonce = 1 }; +static const unsigned NotPublic = (unsigned)-1; + class Envelope { friend class Message; @@ -64,7 +66,7 @@ public: Topic const& topic() const { return m_topic; } bytes const& data() const { return m_data; } - Message open(Secret const& _s = Secret(), unsigned _topicIndex = (unsigned)-1) const; + Message open(Secret const& _s, unsigned _topicIndex = NotPublic) const; unsigned workProved() const; void proveWork(unsigned _ms); @@ -85,8 +87,6 @@ enum /*Message Flags*/ ContainsSignature = 1 }; -static const unsigned NotPublic = (unsigned)-1; - /// An (unencrypted) message, constructed from the combination of an Envelope, and, potentially, /// a Secret key to decrypt the Message. class Message diff --git a/libwhisper/WhisperHost.h b/libwhisper/WhisperHost.h index 07207989e..425fe3108 100644 --- a/libwhisper/WhisperHost.h +++ b/libwhisper/WhisperHost.h @@ -51,7 +51,7 @@ public: virtual void inject(Envelope const& _e, WhisperPeer* _from = nullptr) override; - virtual FullTopic getFilter(unsigned _id) const { try { return m_filters.at(m_watches.at(_id).id).full; } catch (...) { return FullTopic(); } } + virtual FilterKey filterKey(unsigned _id) const { try { return m_filters.at(m_watches.at(_id).id).filterKey(); } catch (...) { return FilterKey(); } } virtual unsigned installWatch(FullTopic const& _filter) override; virtual unsigned installWatchOnId(h256 _filterId) override; virtual void uninstallWatch(unsigned _watchId) override; diff --git a/test/whisperTopic.cpp b/test/whisperTopic.cpp index 31cefdb8a..a47b0a574 100644 --- a/test/whisperTopic.cpp +++ b/test/whisperTopic.cpp @@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(topic) { for (auto i: wh->checkWatch(w)) { - Message msg = wh->envelope(i).open(); + Message msg = wh->envelope(i).open(wh->filterKey()); last = RLP(msg.payload()).toInt(); cnote << "New message from:" << msg.from().abridged() << RLP(msg.payload()).toInt(); result += last;