Browse Source

expire whisper messages

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

2
libwhisper/WhisperHost.cpp

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

33
libwhisper/WhisperPeer.cpp

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

Loading…
Cancel
Save