|
|
@ -22,11 +22,21 @@ |
|
|
|
#include "Common.h" |
|
|
|
|
|
|
|
#include <libdevcrypto/SHA3.h> |
|
|
|
#include "Message.h" |
|
|
|
using namespace std; |
|
|
|
using namespace dev; |
|
|
|
using namespace dev::p2p; |
|
|
|
using namespace dev::shh; |
|
|
|
|
|
|
|
Topic BuildTopic::toTopic() const |
|
|
|
{ |
|
|
|
Topic ret; |
|
|
|
ret.reserve(m_parts.size()); |
|
|
|
for (auto const& h: m_parts) |
|
|
|
ret.push_back((TopicPart)u256(h)); |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
BuildTopic& BuildTopic::shiftBytes(bytes const& _b) |
|
|
|
{ |
|
|
|
m_parts.push_back(dev::sha3(_b)); |
|
|
@ -40,19 +50,32 @@ h256 TopicFilter::sha3() const |
|
|
|
return dev::sha3(s.out()); |
|
|
|
} |
|
|
|
|
|
|
|
bool TopicFilter::matches(Envelope const& _e) const |
|
|
|
{ |
|
|
|
for (TopicMask const& t: m_topicMasks) |
|
|
|
{ |
|
|
|
if (_e.topics().size() == t.size()) |
|
|
|
for (unsigned i = 0; i < t.size(); ++i) |
|
|
|
if (((t[i].first ^ _e.topics()[i]) & t[i].second) != 0) |
|
|
|
goto NEXT_TOPICMASK; |
|
|
|
return true; |
|
|
|
NEXT_TOPICMASK:; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
TopicMask BuildTopicMask::toTopicMask() const |
|
|
|
{ |
|
|
|
TopicMask ret; |
|
|
|
if (m_parts.size()) |
|
|
|
for (auto i = 0; i < 32; ++i) |
|
|
|
{ |
|
|
|
ret.first[i] = m_parts[i * m_parts.size() / 32][i]; |
|
|
|
ret.second[i] = m_parts[i * m_parts.size() / 32] ? 255 : 0; |
|
|
|
} |
|
|
|
ret.reserve(m_parts.size()); |
|
|
|
for (auto const& h: m_parts) |
|
|
|
ret.push_back(make_pair((TopicPart)u256(h), h ? ~(uint32_t)0 : 0)); |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
|
web3.shh.watch({}).arrived(function(m) { env.note("New message:\n"+JSON.stringify(m)); }) |
|
|
|
k = web3.shh.newIdentity() |
|
|
|
web3.shh.post({from: k, topic: web3.fromAscii("test"), payload: web3.fromAscii("Hello world!")}) |
|
|
|
*/ |
|
|
|
|
|
|
|