Browse Source

initial rating introduction

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

28
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<WhisperPeer>().get();
if (w == _p)
w->addRating(1);
w->addRating(rating);
else
w->noteNewMessage(h, _m);
}

10
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)

2
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; }

Loading…
Cancel
Save