Browse Source

initial rating introduction

cl-refactor
Vlad Gluhovsky 10 years ago
parent
commit
447ba77006
  1. 12
      libwhisper/WhisperHost.cpp
  2. 10
      libwhisper/WhisperPeer.cpp
  3. 2
      libwhisper/WhisperPeer.h

12
libwhisper/WhisperHost.cpp

@ -66,21 +66,31 @@ void WhisperHost::inject(Envelope const& _m, WhisperPeer* _p)
m_expiryQueue.insert(make_pair(_m.expiry(), h)); m_expiryQueue.insert(make_pair(_m.expiry(), 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) DEV_GUARDED(m_filterLock)
{ {
for (auto const& f: m_filters) for (auto const& f: m_filters)
if (f.second.filter.matches(_m)) if (f.second.filter.matches(_m))
for (auto& i: m_watches) for (auto& i: m_watches)
if (i.second.id == f.first) if (i.second.id == f.first)
{
i.second.changes.push_back(h); i.second.changes.push_back(h);
rating *= 10;
}
} }
//}
// TODO p2p: capability-based rating // TODO p2p: capability-based rating
for (auto i: peerSessions()) for (auto i: peerSessions())
{ {
auto w = i.first->cap<WhisperPeer>().get(); auto w = i.first->cap<WhisperPeer>().get();
if (w == _p) if (w == _p)
w->addRating(1); w->addRating(rating);
else else
w->noteNewMessage(h, _m); w->noteNewMessage(h, _m);
} }

10
libwhisper/WhisperPeer.cpp

@ -114,8 +114,16 @@ void WhisperPeer::sendMessages()
void WhisperPeer::noteNewMessage(h256 _h, Envelope const& _m) void WhisperPeer::noteNewMessage(h256 _h, Envelope const& _m)
{ {
unsigned rate = rating(_m);
Guard l(x_unseen); 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) void WhisperPeer::sendTopicsOfInterest(TopicBloomFilterHash const& _bloom)

2
libwhisper/WhisperPeer.h

@ -62,7 +62,7 @@ public:
private: private:
virtual bool interpret(unsigned _id, RLP const&) override; virtual bool interpret(unsigned _id, RLP const&) override;
void sendMessages(); void sendMessages();
unsigned rating(Envelope const&) const { return 0; } // TODO unsigned rating(Envelope const&) const;
void noteNewMessage(h256 _h, Envelope const& _m); void noteNewMessage(h256 _h, Envelope const& _m);
void setBloom(TopicBloomFilterHash const& _b) { dev::Guard g(x_bloom); m_bloom = _b; } void setBloom(TopicBloomFilterHash const& _b) { dev::Guard g(x_bloom); m_bloom = _b; }

Loading…
Cancel
Save