Browse Source

expire whisper messages

cl-refactor
subtly 10 years ago
parent
commit
a769ac5102
  1. 2
      libwhisper/WhisperHost.cpp
  2. 19
      libwhisper/WhisperPeer.cpp

2
libwhisper/WhisperHost.cpp

@ -118,7 +118,6 @@ unsigned WhisperHost::installWatch(shh::TopicFilter const& _f)
h256s WhisperHost::watchMessages(unsigned _watchId) h256s WhisperHost::watchMessages(unsigned _watchId)
{ {
cleanup();
h256s ret; h256s ret;
auto wit = m_watches.find(_watchId); auto wit = m_watches.find(_watchId);
if (wit == m_watches.end()) if (wit == m_watches.end())
@ -160,6 +159,7 @@ void WhisperHost::doWork()
{ {
for (auto& i: peers()) for (auto& i: peers())
i->cap<WhisperPeer>()->sendMessages(); i->cap<WhisperPeer>()->sendMessages();
cleanup();
} }
void WhisperHost::cleanup() void WhisperHost::cleanup()

19
libwhisper/WhisperPeer.cpp

@ -82,9 +82,10 @@ bool WhisperPeer::interpret(unsigned _id, RLP const& _r)
void WhisperPeer::sendMessages() void WhisperPeer::sendMessages()
{ {
if (m_unseen.size())
{
RLPStream amalg; RLPStream amalg;
unsigned n = 0; unsigned msgCount = m_unseen.size();
{ {
Guard l(x_unseen); Guard l(x_unseen);
while (m_unseen.size()) while (m_unseen.size())
@ -92,23 +93,11 @@ void WhisperPeer::sendMessages()
auto p = *m_unseen.begin(); auto p = *m_unseen.begin();
m_unseen.erase(m_unseen.begin()); m_unseen.erase(m_unseen.begin());
host()->streamMessage(p.second, amalg); host()->streamMessage(p.second, amalg);
n++;
} }
} }
// the message subsystem should really just keep pumping out messages while m_unseen.size() and there's bandwidth for them.
auto diff = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - m_timer);
if (n || diff.count() > 0)
{
RLPStream s;
prep(s, MessagesPacket, n).appendRaw(amalg.out(), n);
sealAndSend(s);
m_timer = chrono::system_clock::now();
}
{
RLPStream s; RLPStream s;
prep(s, MessagesPacket, n).appendRaw(amalg.out(), n); prep(s, MessagesPacket, msgCount).appendRaw(amalg.out(), msgCount);
sealAndSend(s); sealAndSend(s);
} }
} }

Loading…
Cancel
Save