diff --git a/libwhisper/WhisperHost.cpp b/libwhisper/WhisperHost.cpp index 150d5cd63..9d97816f2 100644 --- a/libwhisper/WhisperHost.cpp +++ b/libwhisper/WhisperHost.cpp @@ -66,21 +66,31 @@ void WhisperHost::inject(Envelope const& _m, WhisperPeer* _p) m_expiryQueue.insert(make_pair(_m.expiry(), h)); } - DEV_GUARDED(m_filterLock) - { - for (auto const& f: m_filters) - if (f.second.filter.matches(_m)) - for (auto& i: m_watches) - if (i.second.id == f.first) - i.second.changes.push_back(h); - } + int rating = 1; // rating is based upon: 1. installed watch; 2. proof of work + + //if (bloomfilter.check) + //{ + // rating *= 10; + if (_p) // originated externally + DEV_GUARDED(m_filterLock) + { + for (auto const& f: m_filters) + if (f.second.filter.matches(_m)) + for (auto& i: m_watches) + if (i.second.id == f.first) + { + i.second.changes.push_back(h); + rating *= 10; + } + } + //} // TODO p2p: capability-based rating for (auto i: peerSessions()) { auto w = i.first->cap().get(); if (w == _p) - w->addRating(1); + w->addRating(rating); else w->noteNewMessage(h, _m); } diff --git a/libwhisper/WhisperPeer.cpp b/libwhisper/WhisperPeer.cpp index d749aa26e..feae5b72c 100644 --- a/libwhisper/WhisperPeer.cpp +++ b/libwhisper/WhisperPeer.cpp @@ -114,8 +114,16 @@ void WhisperPeer::sendMessages() void WhisperPeer::noteNewMessage(h256 _h, Envelope const& _m) { + unsigned rate = rating(_m); Guard l(x_unseen); - m_unseen.insert(make_pair(rating(_m), _h)); + m_unseen.insert(make_pair(rate, _h)); +} + +unsigned WhisperPeer::rating(Envelope const&) const +{ + // rated by: 1. installed watch; 2. proof of work + + return 0; } void WhisperPeer::sendTopicsOfInterest(TopicBloomFilterHash const& _bloom) diff --git a/libwhisper/WhisperPeer.h b/libwhisper/WhisperPeer.h index 48f984013..313cec28d 100644 --- a/libwhisper/WhisperPeer.h +++ b/libwhisper/WhisperPeer.h @@ -62,7 +62,7 @@ public: private: virtual bool interpret(unsigned _id, RLP const&) override; void sendMessages(); - unsigned rating(Envelope const&) const { return 0; } // TODO + unsigned rating(Envelope const&) const; void noteNewMessage(h256 _h, Envelope const& _m); void setBloom(TopicBloomFilterHash const& _b) { dev::Guard g(x_bloom); m_bloom = _b; }