33 WhisperHost::WhisperHost(
bool _storeMessagesInDB):
Worker(
"shh"), m_storeMessagesInDB(_storeMessagesInDB)
85 if (
f.second.filter.matches(_m))
87 if (i.second.id ==
f.first)
89 i.second.changes.push_back(
h);
97 unsigned ttlReward = (256 > _m.
ttl() ? 256 - _m.
ttl() : 0);
104 for (
auto i: peerSessions())
106 auto w = capabilityFromSession<WhisperPeer>(*i.first).
get();
108 w->addRating(rating);
110 w->noteNewMessage(
h, _m);
126 it->second.refCount++;
148 auto id = it->second.id;
155 if (!--fit->second.refCount)
172 auto fit =
m_filters.find(wit->second.id);
175 f = fit->second.filter;
180 ret.push_back(m.first);
204 for (
auto i: peerSessions())
205 capabilityFromSession<WhisperPeer>(*i.first)->sendMessages();
221 for (
auto i: peerSessions())
230 if (
f.second.filter.matches(_e))
232 if (i.second.id ==
f.first)
248 if (m.second.expiry() > now)
254 cwarn <<
"Exception in WhisperHost::saveMessagesToBD() - failed to open DB:" << ex.
what();
258 cwarn <<
"Exception in WhisperHost::saveMessagesToBD():" << ex.
what();
262 cwarn <<
"Unknown Exception in WhisperHost::saveMessagesToBD()";
273 map<h256, Envelope> m;
278 for (
auto const& msg: m)
279 m_expiryQueue.insert(make_pair(msg.second.expiry(), msg.first));
283 cwarn <<
"Exception in WhisperHost::loadMessagesFromBD():" << ex.
what();
287 cwarn <<
"Unknown Exception in WhisperHost::loadMessagesFromBD()";
TopicBloomFilterHash exportBloom() const
void noteAdvertiseTopicsOfInterest()
std::map< unsigned, ClientWatch > m_watches
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
h256 sha3(IncludeNonce _withNonce=WithNonce) const
dev::SharedMutex x_messages
virtual void inject(Envelope const &_e, WhisperPeer *_from=nullptr) override
void removeRaw(FixedHash< N > const &_h)
uint64_t utcTime()
Get the current time in seconds since the epoch in UTC.
void streamMessage(h256 _m, RLPStream &_s) const
const char * what() const noexceptoverride
boost::upgrade_to_unique_lock< boost::shared_mutex > UpgradeGuard
std::map< h256, InstalledFilter > m_filters
std::hash for asio::adress
boost::upgrade_lock< boost::shared_mutex > UpgradableGuard
virtual h256s watchMessages(unsigned _watchId) override
returns IDs of messages, which match specific watch criteria
void loadAllMessages(std::map< h256, Envelope > &o_dst)
void cleanup()
remove old messages
#define DEV_GUARDED(MUTEX)
Simple block guard.
Base class for all exceptions.
std::lock_guard< std::mutex > Guard
virtual void uninstallWatch(unsigned _watchId) override
void saveSingleMessage(dev::h256 const &_key, Envelope const &_e)
boost::shared_lock< boost::shared_mutex > ReadGuard
unsigned workProved() const
virtual unsigned installWatch(Topics const &_filter) override
boost::unique_lock< boost::shared_mutex > WriteGuard
void addRaw(FixedHash< N > const &_h)
void loadMessagesFromBD()
virtual void doWork() override
Called continuously following sleep for m_idleWaitMs.
bool matches(Envelope const &_m) const
bool isWatched(Envelope const &_e) const
bool m_storeMessagesInDB
needed for tests and other special cases
bool matchesBloomFilter(TopicBloomFilterHash const &f) const
std::multimap< unsigned, h256 > m_expiryQueue
std::map< h256, Envelope > m_messages
virtual h256s checkWatch(unsigned _watchId) override
std::vector< h256 > h256s
Class for writing to an RLP bytestream.