|
|
@ -91,19 +91,17 @@ void WhisperPeer::sendMessages() |
|
|
|
if (m_advertiseTopicsOfInterest) |
|
|
|
sendTopicsOfInterest(host()->bloom()); |
|
|
|
|
|
|
|
multimap<unsigned, h256> available; |
|
|
|
DEV_GUARDED(x_unseen) |
|
|
|
m_unseen.swap(available); |
|
|
|
|
|
|
|
RLPStream amalg; |
|
|
|
unsigned msgCount = 0; |
|
|
|
{ |
|
|
|
Guard l(x_unseen); |
|
|
|
msgCount = m_unseen.size(); |
|
|
|
while (m_unseen.size()) |
|
|
|
{ |
|
|
|
auto p = *m_unseen.begin(); |
|
|
|
m_unseen.erase(m_unseen.begin()); |
|
|
|
host()->streamMessage(p.second, amalg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// send the highest rated messages first
|
|
|
|
for (auto i = available.rbegin(); i != available.rend(); ++i) |
|
|
|
host()->streamMessage(i->second, amalg); |
|
|
|
|
|
|
|
unsigned msgCount = available.size(); |
|
|
|
if (msgCount) |
|
|
|
{ |
|
|
|
RLPStream s; |
|
|
@ -114,16 +112,27 @@ void WhisperPeer::sendMessages() |
|
|
|
|
|
|
|
void WhisperPeer::noteNewMessage(h256 _h, Envelope const& _m) |
|
|
|
{ |
|
|
|
unsigned rate = rating(_m); |
|
|
|
unsigned rate = ratingForPeer(_m); |
|
|
|
Guard l(x_unseen); |
|
|
|
m_unseen.insert(make_pair(rate, _h)); |
|
|
|
} |
|
|
|
|
|
|
|
unsigned WhisperPeer::rating(Envelope const&) const |
|
|
|
unsigned WhisperPeer::ratingForPeer(Envelope const& e) const |
|
|
|
{ |
|
|
|
// rated by: 1. installed watch; 2. proof of work
|
|
|
|
// we try to estimate, how valuable this nessage will be for the remote peer,
|
|
|
|
// according to the following criteria:
|
|
|
|
// 1. bloom filter
|
|
|
|
// 2. proof of work
|
|
|
|
|
|
|
|
return 0; |
|
|
|
static const unsigned BloomFilterMatchReward = 256; // vlad todo: move to common.h
|
|
|
|
unsigned rating = 0; |
|
|
|
|
|
|
|
DEV_GUARDED(x_bloom) |
|
|
|
if (e.matchesBloomFilter(m_bloom)) |
|
|
|
rating += BloomFilterMatchReward; |
|
|
|
|
|
|
|
rating += e.sha3().firstBitSet(); // proof of work assessment
|
|
|
|
return rating; |
|
|
|
} |
|
|
|
|
|
|
|
void WhisperPeer::sendTopicsOfInterest(TopicBloomFilterHash const& _bloom) |
|
|
|