Browse Source

Dev.

cl-refactor
Gav Wood 10 years ago
parent
commit
5f523e146d
  1. 3
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  2. 10
      libwhisper/Interface.h
  3. 6
      libwhisper/Message.h
  4. 2
      libwhisper/WhisperHost.h
  5. 2
      test/whisperTopic.cpp

3
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -583,8 +583,7 @@ Json::Value WebThreeStubServerBase::shh_changed(int const& _id)
else else
{ {
unsigned i = 0; unsigned i = 0;
for (; i < face()->getFilter(_id).size() && !face()->getFilter(_id)[i]; ++i) {} m = e.open(face()->filterKey(_id));
m = e.open(face()->getFilter(_id)[i], i);
} }
ret.append(toJson(h, e, m)); ret.append(toJson(h, e, m));
} }

10
libwhisper/Interface.h

@ -45,10 +45,18 @@ namespace shh
class Watch; class Watch;
struct FilterKey
{
unsigned topicIndex = (unsigned)-1;
Secret key;
};
struct InstalledFilter struct InstalledFilter
{ {
InstalledFilter(FullTopic const& _f): full(_f), filter(_f) {} 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; FullTopic full;
TopicFilter filter; TopicFilter filter;
unsigned refCount = 1; unsigned refCount = 1;
@ -70,7 +78,7 @@ public:
virtual void inject(Envelope const& _m, WhisperPeer* _from = nullptr) = 0; 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 installWatch(FullTopic const& _mask) = 0;
virtual unsigned installWatchOnId(h256 _filterId) = 0; virtual unsigned installWatchOnId(h256 _filterId) = 0;
virtual void uninstallWatch(unsigned _watchId) = 0; virtual void uninstallWatch(unsigned _watchId) = 0;

6
libwhisper/Message.h

@ -45,6 +45,8 @@ enum IncludeNonce
WithNonce = 1 WithNonce = 1
}; };
static const unsigned NotPublic = (unsigned)-1;
class Envelope class Envelope
{ {
friend class Message; friend class Message;
@ -64,7 +66,7 @@ public:
Topic const& topic() const { return m_topic; } Topic const& topic() const { return m_topic; }
bytes const& data() const { return m_data; } 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; unsigned workProved() const;
void proveWork(unsigned _ms); void proveWork(unsigned _ms);
@ -85,8 +87,6 @@ enum /*Message Flags*/
ContainsSignature = 1 ContainsSignature = 1
}; };
static const unsigned NotPublic = (unsigned)-1;
/// An (unencrypted) message, constructed from the combination of an Envelope, and, potentially, /// An (unencrypted) message, constructed from the combination of an Envelope, and, potentially,
/// a Secret key to decrypt the Message. /// a Secret key to decrypt the Message.
class Message class Message

2
libwhisper/WhisperHost.h

@ -51,7 +51,7 @@ public:
virtual void inject(Envelope const& _e, WhisperPeer* _from = nullptr) override; 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 installWatch(FullTopic const& _filter) override;
virtual unsigned installWatchOnId(h256 _filterId) override; virtual unsigned installWatchOnId(h256 _filterId) override;
virtual void uninstallWatch(unsigned _watchId) override; virtual void uninstallWatch(unsigned _watchId) override;

2
test/whisperTopic.cpp

@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(topic)
{ {
for (auto i: wh->checkWatch(w)) 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<unsigned>(); last = RLP(msg.payload()).toInt<unsigned>();
cnote << "New message from:" << msg.from().abridged() << RLP(msg.payload()).toInt<unsigned>(); cnote << "New message from:" << msg.from().abridged() << RLP(msg.payload()).toInt<unsigned>();
result += last; result += last;

Loading…
Cancel
Save