Browse Source

Whispers pane.

cl-refactor
Gav Wood 10 years ago
parent
commit
2df5cc9fda
  1. 37
      alethzero/Main.ui
  2. 29
      alethzero/MainWin.cpp
  3. 1
      alethzero/MainWin.h
  4. 2
      libdevcrypto/EC.cpp
  5. 9
      libwhisper/Message.cpp
  6. 2
      libwhisper/Message.h
  7. 2
      libwhisper/WhisperHost.h

37
alethzero/Main.ui

@ -1720,6 +1720,43 @@ font-size: 14pt</string>
</layout>
</widget>
</widget>
<widget class="QDockWidget" name="dockWidget_15">
<property name="features">
<set>QDockWidget::DockWidgetFeatureMask</set>
</property>
<property name="windowTitle">
<string>Active Whispers</string>
</property>
<attribute name="dockWidgetArea">
<number>2</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents_15">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QListWidget" name="whispers">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<action name="quit">
<property name="text">
<string>&amp;Quit</string>

29
alethzero/MainWin.cpp

@ -763,7 +763,6 @@ void Main::refreshNetwork()
{
auto ps = web3()->peers();
ui->peerCount->setText(QString::fromStdString(toString(ps.size())) + " peer(s)");
ui->peers->clear();
ui->nodes->clear();
@ -1006,6 +1005,7 @@ void Main::timerEvent(QTimerEvent*)
{
interval = 0;
refreshNetwork();
refreshWhispers();
}
else
interval += 100;
@ -2108,6 +2108,33 @@ void Main::refreshWhisper()
ui->shhFrom->addItem(QString::fromStdString(toHex(i.first.ref())));
}
void Main::refreshWhispers()
{
ui->whispers->clear();
for (auto const& w: whisper()->all())
{
shh::Envelope const& e = w.second;
shh::Message m;
for (pair<Public, Secret> const& i: m_whisper->ids())
if (!!(m = e.open(i.second)))
break;
if (!m)
m = e.open();
QString msg;
if (m.from())
// Good message.
msg = QString("%1->%2: %3").arg(m.from() ? m.from().abridged().c_str() : "?").arg(m.to() ? m.to().abridged().c_str() : "?").arg(toHex(m.payload()).c_str());
else if (m)
// Maybe message.
msg = QString("%1->%2: %3 (?)").arg(m.from() ? m.from().abridged().c_str() : "?").arg(m.to() ? m.to().abridged().c_str() : "?").arg(toHex(m.payload()).c_str());
time_t ex = e.expiry();
QString item = QString("[%1 - %2s] *%3 %5 %4").arg(asctime(localtime(&ex))).arg(e.ttl()).arg(e.workProved()).arg(toString(e.topic()).c_str()).arg(msg);
ui->whispers->addItem(item);
}
}
// extra bits needed to link on VS
#ifdef _MSC_VER

1
alethzero/MainWin.h

@ -206,6 +206,7 @@ private:
void refreshNetwork();
void refreshMining();
void refreshWhispers();
void refreshAll();
void refreshPending();

2
libdevcrypto/EC.cpp

@ -52,7 +52,7 @@ void dev::crypto::encrypt(Public const& _key, bytes& io_cipher)
c.resize(e.CiphertextLength(plen));
// todo: use StringSource with _plain as input and output.
e.Encrypt(pp::PRNG(), io_cipher.data(), plen, c.data());
bzero(io_cipher.data(), io_cipher.size());
memset(io_cipher.data(), 0, io_cipher.size());
io_cipher = std::move(c);
}

9
libwhisper/Message.cpp

@ -34,7 +34,7 @@ Message::Message(Envelope const& _e, Secret const& _s)
if (_s)
if (!decrypt(_s, &(_e.data()), b))
return;
populate(_s ? b : _e.data());
if (populate(_s ? b : _e.data()))
m_to = KeyPair(_s).pub();
}
catch (...) // Invalid secret? TODO: replace ... with InvalidSecret
@ -42,10 +42,10 @@ Message::Message(Envelope const& _e, Secret const& _s)
}
}
void Message::populate(bytes const& _data)
bool Message::populate(bytes const& _data)
{
if (!_data.size())
return;
return false;
byte flags = _data[0];
if (!!(flags & ContainsSignature) && _data.size() > sizeof(Signature) + 1) // has a signature
@ -54,10 +54,13 @@ void Message::populate(bytes const& _data)
h256 h = sha3(payload);
Signature const& sig = *(Signature const*)&(_data[1 + payload.size()]);
m_from = recover(sig, h);
if (!m_from)
return false;
m_payload = payload.toBytes();
}
else
m_payload = bytesConstRef(&_data).cropped(1).toBytes();
return true;
}
Envelope Message::seal(Secret _from, Topic const& _topic, unsigned _ttl, unsigned _workToProve) const

2
libwhisper/Message.h

@ -116,7 +116,7 @@ public:
Envelope sealTo(Secret _from, Public _to, Topic const& _topic, unsigned _workToProve = 50, unsigned _ttl = 50) { m_to = _to; return seal(_from, _topic, _workToProve, _ttl); }
private:
void populate(bytes const& _data);
bool populate(bytes const& _data);
Public m_from;
Public m_to;

2
libwhisper/WhisperHost.h

@ -60,6 +60,8 @@ public:
virtual Envelope envelope(h256 _m) const override { try { dev::ReadGuard l(x_messages); return m_messages.at(_m); } catch (...) { return Envelope(); } }
std::map<h256, Envelope> all() const { ReadGuard l(x_messages); return m_messages; }
void cleanup();
private:

Loading…
Cancel
Save