Browse Source

Whisper fixes.

cl-refactor
Gav Wood 10 years ago
parent
commit
5b8e26f63d
  1. 3
      exp/main.cpp
  2. 2
      libwhisper/Message.cpp
  3. 1
      libwhisper/Message.h
  4. 23
      libwhisper/WhisperPeer.cpp
  5. 2
      libwhisper/WhisperPeer.h

3
exp/main.cpp

@ -95,8 +95,7 @@ int main(int argc, char** argv)
}
Host ph("Test", NetworkPreferences(listenPort, "", false, true));
ph.registerCapability(new WhisperHost());
auto wh = ph.cap<WhisperHost>();
auto wh = ph.registerCapability(new WhisperHost());
ph.start();

2
libwhisper/Message.cpp

@ -105,7 +105,7 @@ void Envelope::proveWork(unsigned _ms)
// PoW
h256 d[2];
d[0] = sha3NoNonce();
uint32_t& n = *(uint32_t*)&(d[1][30]);
uint32_t& n = *(uint32_t*)&(d[1][28]);
unsigned bestBitSet = 0;
bytesConstRef chuck(d[0].data(), 64);

1
libwhisper/Message.h

@ -50,6 +50,7 @@ public:
m_ttl = _m[1].toInt<unsigned>();
m_topic = (Topic)_m[2];
m_data = _m[3].toBytes();
m_nonce = _m[4].toInt<u256>();
}
operator bool() const { return !!m_expiry; }

23
libwhisper/WhisperPeer.cpp

@ -86,24 +86,27 @@ void WhisperPeer::sendMessages()
RLPStream amalg;
unsigned n = 0;
Guard l(x_unseen);
while (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);
n++;
}
}
if (n)
if (!n)
// pause for a bit if no messages to send - this is horrible and broken.
// the message subsystem should really just keep pumping out messages while m_unseen.size() and there's bandwidth for them.
this_thread::sleep_for(chrono::milliseconds(20));
{
RLPStream s;
prep(s, MessagesPacket, n).appendRaw(amalg.out(), n);
sealAndSend(s);
}
else
// just pause if no messages to send
this_thread::sleep_for(chrono::milliseconds(100));
}
void WhisperPeer::noteNewMessage(h256 _h, Message const& _m)

2
libwhisper/WhisperPeer.h

@ -59,7 +59,7 @@ public:
WhisperHost* host() const;
private:
virtual bool interpret(unsigned _id, RLP const&);
virtual bool interpret(unsigned _id, RLP const&) override;
void sendMessages();

Loading…
Cancel
Save