From 5b8e26f63d234789f3ed79bb47f8b518c52a433a Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 23 Oct 2014 11:50:24 +0200 Subject: [PATCH] Whisper fixes. --- exp/main.cpp | 3 +-- libwhisper/Message.cpp | 2 +- libwhisper/Message.h | 1 + libwhisper/WhisperPeer.cpp | 23 +++++++++++++---------- libwhisper/WhisperPeer.h | 2 +- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/exp/main.cpp b/exp/main.cpp index 30ef36408..0717ad051 100644 --- a/exp/main.cpp +++ b/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(); + auto wh = ph.registerCapability(new WhisperHost()); ph.start(); diff --git a/libwhisper/Message.cpp b/libwhisper/Message.cpp index 04f510917..5d8466a2c 100644 --- a/libwhisper/Message.cpp +++ b/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); diff --git a/libwhisper/Message.h b/libwhisper/Message.h index cbe6355be..17ddb3f7f 100644 --- a/libwhisper/Message.h +++ b/libwhisper/Message.h @@ -50,6 +50,7 @@ public: m_ttl = _m[1].toInt(); m_topic = (Topic)_m[2]; m_data = _m[3].toBytes(); + m_nonce = _m[4].toInt(); } operator bool() const { return !!m_expiry; } diff --git a/libwhisper/WhisperPeer.cpp b/libwhisper/WhisperPeer.cpp index 58f9a4cf4..343f7ca1a 100644 --- a/libwhisper/WhisperPeer.cpp +++ b/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) diff --git a/libwhisper/WhisperPeer.h b/libwhisper/WhisperPeer.h index 3da246562..45d72ba89 100644 --- a/libwhisper/WhisperPeer.h +++ b/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();