Browse Source

expire whisper messages

cl-refactor
subtly 10 years ago
parent
commit
a769ac5102
  1. 2
      libwhisper/WhisperHost.cpp
  2. 35
      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()

35
libwhisper/WhisperPeer.cpp

@ -82,33 +82,22 @@ bool WhisperPeer::interpret(unsigned _id, RLP const& _r)
void WhisperPeer::sendMessages() void WhisperPeer::sendMessages()
{ {
RLPStream amalg; if (m_unseen.size())
unsigned n = 0;
{ {
Guard l(x_unseen); RLPStream amalg;
while (m_unseen.size()) unsigned msgCount = m_unseen.size();
{ {
auto p = *m_unseen.begin(); Guard l(x_unseen);
m_unseen.erase(m_unseen.begin()); while (m_unseen.size())
host()->streamMessage(p.second, amalg); {
n++; auto p = *m_unseen.begin();
m_unseen.erase(m_unseen.begin());
host()->streamMessage(p.second, amalg);
}
} }
}
// 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