|
|
@ -66,12 +66,13 @@ void WhisperHost::inject(Envelope const& _m, WhisperPeer* _p) |
|
|
|
m_expiryQueue.insert(make_pair(_m.expiry(), h)); |
|
|
|
} |
|
|
|
|
|
|
|
// if (_p)
|
|
|
|
DEV_GUARDED(m_filterLock) |
|
|
|
{ |
|
|
|
Guard l(m_filterLock); |
|
|
|
for (auto const& f: m_filters) |
|
|
|
if (f.second.filter.matches(_m)) |
|
|
|
noteChanged(h, f.first); |
|
|
|
for (auto& i: m_watches) |
|
|
|
if (i.second.id == f.first) |
|
|
|
i.second.changes.push_back(h); |
|
|
|
} |
|
|
|
|
|
|
|
// TODO p2p: capability-based rating
|
|
|
@ -85,36 +86,26 @@ void WhisperHost::inject(Envelope const& _m, WhisperPeer* _p) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void WhisperHost::noteChanged(h256 _messageHash, h256 _filter) |
|
|
|
{ |
|
|
|
for (auto& i: m_watches) |
|
|
|
if (i.second.id == _filter) |
|
|
|
{ |
|
|
|
cwatshh << "!!!" << i.first << i.second.id; |
|
|
|
i.second.changes.push_back(_messageHash); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
unsigned WhisperHost::installWatchOnId(h256 _h) |
|
|
|
{ |
|
|
|
auto ret = m_watches.size() ? m_watches.rbegin()->first + 1 : 0; |
|
|
|
m_watches[ret] = ClientWatch(_h); |
|
|
|
cwatshh << "+++" << ret << _h; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
unsigned WhisperHost::installWatch(shh::Topics const& _t) |
|
|
|
{ |
|
|
|
Guard l(m_filterLock); |
|
|
|
|
|
|
|
InstalledFilter f(_t); |
|
|
|
h256 h = f.filter.sha3(); |
|
|
|
unsigned ret = 0; |
|
|
|
|
|
|
|
if (!m_filters.count(h)) |
|
|
|
m_filters.insert(make_pair(h, f)); |
|
|
|
DEV_GUARDED(m_filterLock) |
|
|
|
{ |
|
|
|
if (!m_filters.count(h)) |
|
|
|
m_filters.insert(make_pair(h, f)); |
|
|
|
|
|
|
|
ret = m_watches.size() ? m_watches.rbegin()->first + 1 : 0; |
|
|
|
m_watches[ret] = ClientWatch(h); |
|
|
|
cwatshh << "+++" << ret << h; |
|
|
|
|
|
|
|
m_bloom.addRaw(f.filter.exportBloom()); |
|
|
|
return installWatchOnId(h); |
|
|
|
m_bloom.addRaw(f.filter.exportBloom()); |
|
|
|
} |
|
|
|
|
|
|
|
noteAdvertiseTopicsOfInterest(); |
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
h256s WhisperHost::watchMessages(unsigned _watchId) |
|
|
@ -142,21 +133,25 @@ void WhisperHost::uninstallWatch(unsigned _i) |
|
|
|
{ |
|
|
|
cwatshh << "XXX" << _i; |
|
|
|
|
|
|
|
Guard l(m_filterLock); |
|
|
|
DEV_GUARDED(m_filterLock) |
|
|
|
{ |
|
|
|
auto it = m_watches.find(_i); |
|
|
|
if (it == m_watches.end()) |
|
|
|
return; |
|
|
|
auto id = it->second.id; |
|
|
|
m_watches.erase(it); |
|
|
|
|
|
|
|
auto it = m_watches.find(_i); |
|
|
|
if (it == m_watches.end()) |
|
|
|
return; |
|
|
|
auto id = it->second.id; |
|
|
|
m_watches.erase(it); |
|
|
|
auto fit = m_filters.find(id); |
|
|
|
if (fit != m_filters.end()) |
|
|
|
{ |
|
|
|
if (!--fit->second.refCount) |
|
|
|
m_filters.erase(fit); |
|
|
|
|
|
|
|
auto fit = m_filters.find(id); |
|
|
|
if (fit != m_filters.end()) |
|
|
|
{ |
|
|
|
m_bloom.removeRaw(fit->second.filter.exportBloom()); |
|
|
|
if (!--fit->second.refCount) |
|
|
|
m_filters.erase(fit); |
|
|
|
m_bloom.removeRaw(fit->second.filter.exportBloom()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
noteAdvertiseTopicsOfInterest(); |
|
|
|
} |
|
|
|
|
|
|
|
void WhisperHost::doWork() |
|
|
@ -175,3 +170,9 @@ void WhisperHost::cleanup() |
|
|
|
for (auto it = m_expiryQueue.begin(); it != m_expiryQueue.end() && it->first <= now; it = m_expiryQueue.erase(it)) |
|
|
|
m_messages.erase(it->second); |
|
|
|
} |
|
|
|
|
|
|
|
void WhisperHost::noteAdvertiseTopicsOfInterest() |
|
|
|
{ |
|
|
|
for (auto i: peerSessions()) |
|
|
|
i.first->cap<WhisperPeer>().get()->noteAdvertiseTopicsOfInterest(); |
|
|
|
} |
|
|
|