Browse Source

intermediate

cl-refactor
Vlad Gluhovsky 10 years ago
parent
commit
d272ff8cee
  1. 2
      libwhisper/WhisperHost.cpp
  2. 17
      libwhisper/WhisperPeer.cpp
  3. 14
      test/libwhisper/whisperMessage.cpp

2
libwhisper/WhisperHost.cpp

@ -68,7 +68,7 @@ void WhisperHost::inject(Envelope const& _m, WhisperPeer* _p)
m_expiryQueue.insert(make_pair(_m.expiry(), h));
}
int rating = 1; // rating for local host is based upon: 1. installed watch; 2. proof of work
int rating = 1; // rating for local host is based upon: 1. installed watch; 2. ttl; 3. proof of work
if (_p) // incoming message from remote peer
DEV_GUARDED(m_filterLock)

17
libwhisper/WhisperPeer.cpp

@ -121,17 +121,22 @@ unsigned WhisperPeer::ratingForPeer(Envelope const& e) const
{
// 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
// 1. bloom filter
// 2. time to live
// 3. proof of work
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();
++rating;
rating *= 256;
unsigned ttlReward = (256 > e.ttl() ? 256 - e.ttl() : 0);
rating += ttlReward;
rating *= 256;
rating += e.workProved();
return rating;
}

14
test/libwhisper/whisperMessage.cpp

@ -89,4 +89,18 @@ BOOST_AUTO_TEST_CASE(seal)
sealAndOpenSingleMessage(i);
}
BOOST_AUTO_TEST_CASE(work)
{
VerbosityHolder setTemporaryLevel(10);
cnote << "Testing proof of work...";
Secret zero;
Topics topics = createRandomTopics(0xDEAD);
bytes const payload = createRandomPayload(0xFFFFF);
Message m(payload);
Envelope e = m.seal(zero, topics, 1, 50);
unsigned x = e.workProved();
BOOST_REQUIRE(x > 0);
}
BOOST_AUTO_TEST_SUITE_END()

Loading…
Cancel
Save