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. 11
      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)); Host ph("Test", NetworkPreferences(listenPort, "", false, true));
ph.registerCapability(new WhisperHost()); auto wh = ph.registerCapability(new WhisperHost());
auto wh = ph.cap<WhisperHost>();
ph.start(); ph.start();

2
libwhisper/Message.cpp

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

1
libwhisper/Message.h

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

11
libwhisper/WhisperPeer.cpp

@ -86,6 +86,7 @@ void WhisperPeer::sendMessages()
RLPStream amalg; RLPStream amalg;
unsigned n = 0; unsigned n = 0;
{
Guard l(x_unseen); Guard l(x_unseen);
while (m_unseen.size()) while (m_unseen.size())
{ {
@ -94,16 +95,18 @@ void WhisperPeer::sendMessages()
host()->streamMessage(p.second, amalg); host()->streamMessage(p.second, amalg);
n++; 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));
if (n)
{ {
RLPStream s; RLPStream s;
prep(s, MessagesPacket, n).appendRaw(amalg.out(), n); prep(s, MessagesPacket, n).appendRaw(amalg.out(), n);
sealAndSend(s); 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) void WhisperPeer::noteNewMessage(h256 _h, Message const& _m)

2
libwhisper/WhisperPeer.h

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

Loading…
Cancel
Save