Browse Source

Merge branch 'develop'

cl-refactor
Gav Wood 11 years ago
parent
commit
591e0c5ef8
  1. 69
      alethzero/Main.ui
  2. 11
      alethzero/MainWin.cpp
  3. 2
      libethereum/Client.cpp
  4. 13
      libethereum/PeerServer.cpp
  5. 81
      libethereum/PeerSession.cpp
  6. 8
      libethereum/PeerSession.h
  7. 4
      libpyserpent/CMakeLists.txt
  8. 1
      sc/cmdline.cpp
  9. 4
      walleth/MainWin.cpp

69
alethzero/Main.ui

@ -269,7 +269,7 @@
</widget> </widget>
<widget class="QWidget" name="layoutWidget"> <widget class="QWidget" name="layoutWidget">
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="1"> <item row="1" column="2">
<widget class="QSpinBox" name="port"> <widget class="QSpinBox" name="port">
<property name="minimum"> <property name="minimum">
<number>1024</number> <number>1024</number>
@ -282,53 +282,66 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="1" column="1">
<widget class="QSpinBox" name="idealPeers"> <widget class="QLineEdit" name="forceAddress">
<property name="minimum"> <property name="inputMask">
<number>1</number> <string/>
</property> </property>
<property name="value"> <property name="text">
<number>5</number> <string/>
</property>
<property name="placeholderText">
<string>Automatic</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="1" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>Ideal &amp;Peers</string> <string>&amp;Listen on</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>idealPeers</cstring> <cstring>port</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>&amp;Client Name</string> <string>Ideal &amp;Peers</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>clientName</cstring> <cstring>idealPeers</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="0" column="1" colspan="2">
<widget class="QLabel" name="label"> <widget class="QSpinBox" name="idealPeers">
<property name="text"> <property name="minimum">
<string>&amp;Listen on</string> <number>1</number>
</property> </property>
<property name="buddy"> <property name="value">
<cstring>port</cstring> <number>5</number>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1" colspan="2">
<widget class="QLineEdit" name="clientName"> <widget class="QLineEdit" name="clientName">
<property name="placeholderText"> <property name="placeholderText">
<string>Anonymous</string> <string>Anonymous</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>&amp;Client Name</string>
</property>
<property name="buddy">
<cstring>clientName</cstring>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
@ -485,7 +498,6 @@
<addaction name="connect"/> <addaction name="connect"/>
<addaction name="preview"/> <addaction name="preview"/>
<addaction name="mine"/> <addaction name="mine"/>
<addaction name="paranoia"/>
</widget> </widget>
<widget class="QDockWidget" name="dockWidget_5"> <widget class="QDockWidget" name="dockWidget_5">
<property name="sizePolicy"> <property name="sizePolicy">
@ -754,17 +766,6 @@
</layout> </layout>
</widget> </widget>
</widget> </widget>
<widget class="QToolBar" name="toolBar_2">
<property name="windowTitle">
<string>toolBar_2</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QDockWidget" name="dockWidget_6"> <widget class="QDockWidget" name="dockWidget_6">
<property name="features"> <property name="features">
<set>QDockWidget::DockWidgetFeatureMask</set> <set>QDockWidget::DockWidgetFeatureMask</set>

11
alethzero/MainWin.cpp

@ -104,10 +104,10 @@ Main::Main(QWidget *parent) :
m_servers.append("192.168.0.10:30301"); m_servers.append("192.168.0.10:30301");
#else #else
int pocnumber = QString(eth::EthVersion).section('.', 1, 1).toInt(); int pocnumber = QString(eth::EthVersion).section('.', 1, 1).toInt();
if (pocnumber == 4) if (pocnumber == 5)
m_servers.push_back("54.72.31.55:30303");
else if (pocnumber == 5)
m_servers.push_back("54.72.69.180:30303"); m_servers.push_back("54.72.69.180:30303");
else if (pocnumber == 6)
m_servers.push_back("54.72.69.180:30303"/*"54.72.31.55:30303"*/);
else else
{ {
connect(&m_webCtrl, &QNetworkAccessManager::finished, [&](QNetworkReply* _r) connect(&m_webCtrl, &QNetworkAccessManager::finished, [&](QNetworkReply* _r)
@ -144,7 +144,6 @@ Main::Main(QWidget *parent) :
connect(ui->ourAccounts->model(), SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), SLOT(ourAccountsRowsMoved())); connect(ui->ourAccounts->model(), SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)), SLOT(ourAccountsRowsMoved()));
m_client.reset(new Client("AlethZero")); m_client.reset(new Client("AlethZero"));
m_client->start(); m_client->start();
@ -373,6 +372,7 @@ void Main::writeSettings()
s.setValue("address", b); s.setValue("address", b);
s.setValue("upnp", ui->upnp->isChecked()); s.setValue("upnp", ui->upnp->isChecked());
s.setValue("forceAddress", ui->forceAddress->text());
s.setValue("usePast", ui->usePast->isChecked()); s.setValue("usePast", ui->usePast->isChecked());
s.setValue("paranoia", ui->paranoia->isChecked()); s.setValue("paranoia", ui->paranoia->isChecked());
s.setValue("showAll", ui->showAll->isChecked()); s.setValue("showAll", ui->showAll->isChecked());
@ -419,6 +419,7 @@ void Main::readSettings()
m_client->setAddress(m_myKeys.back().address()); m_client->setAddress(m_myKeys.back().address());
m_peers = s.value("peers").toByteArray(); m_peers = s.value("peers").toByteArray();
ui->upnp->setChecked(s.value("upnp", true).toBool()); ui->upnp->setChecked(s.value("upnp", true).toBool());
ui->forceAddress->setText(s.value("forceAddress", "").toString());
ui->usePast->setChecked(s.value("usePast", true).toBool()); ui->usePast->setChecked(s.value("usePast", true).toBool());
ui->paranoia->setChecked(s.value("paranoia", false).toBool()); ui->paranoia->setChecked(s.value("paranoia", false).toBool());
ui->showAll->setChecked(s.value("showAll", false).toBool()); ui->showAll->setChecked(s.value("showAll", false).toBool());
@ -1267,7 +1268,7 @@ void Main::on_net_triggered()
m_client->setClientVersion(n); m_client->setClientVersion(n);
if (ui->net->isChecked()) if (ui->net->isChecked())
{ {
m_client->startNetwork(ui->port->value(), string(), 0, NodeMode::Full, ui->idealPeers->value(), std::string(), ui->upnp->isChecked()); m_client->startNetwork(ui->port->value(), string(), 0, NodeMode::Full, ui->idealPeers->value(), ui->forceAddress->text().toStdString(), ui->upnp->isChecked());
if (m_peers.size() && ui->usePast->isChecked()) if (m_peers.size() && ui->usePast->isChecked())
m_client->peerServer()->restorePeers(bytesConstRef((byte*)m_peers.data(), m_peers.size())); m_client->peerServer()->restorePeers(bytesConstRef((byte*)m_peers.data(), m_peers.size()));
} }

2
libethereum/Client.cpp

@ -556,6 +556,6 @@ PastMessages Client::transactions(TransactionFilter const& _f) const
if (n == end) if (n == end)
break; break;
} }
cdebug << (begin - n) << "searched; " << skipped << "skipped; " << falsePos << "false +ves"; // cdebug << (begin - n) << "searched; " << skipped << "skipped; " << falsePos << "false +ves";
return ret; return ret;
} }

13
libethereum/PeerServer.cpp

@ -117,6 +117,19 @@ unsigned PeerServer::protocolVersion()
return c_protocolVersion; return c_protocolVersion;
} }
void PeerServer::seal(bytes& _b)
{
_b[0] = 0x22;
_b[1] = 0x40;
_b[2] = 0x08;
_b[3] = 0x91;
uint32_t len = (uint32_t)_b.size() - 8;
_b[4] = (len >> 24) & 0xff;
_b[5] = (len >> 16) & 0xff;
_b[6] = (len >> 8) & 0xff;
_b[7] = len & 0xff;
}
void PeerServer::determinePublic(string const& _publicAddress, bool _upnp) void PeerServer::determinePublic(string const& _publicAddress, bool _upnp)
{ {
if (_upnp) if (_upnp)

81
libethereum/PeerSession.cpp

@ -37,7 +37,6 @@ static const eth::uint c_maxBlocksAsk = 256; ///< Maximum number of blocks we as
PeerSession::PeerSession(PeerServer* _s, bi::tcp::socket _socket, uint _rNId, bi::address _peerAddress, unsigned short _peerPort): PeerSession::PeerSession(PeerServer* _s, bi::tcp::socket _socket, uint _rNId, bi::address _peerAddress, unsigned short _peerPort):
m_server(_s), m_server(_s),
m_strand(_socket.get_io_service()),
m_socket(std::move(_socket)), m_socket(std::move(_socket)),
m_reqNetworkId(_rNId), m_reqNetworkId(_rNId),
m_listenPort(_peerPort), m_listenPort(_peerPort),
@ -50,16 +49,13 @@ PeerSession::PeerSession(PeerServer* _s, bi::tcp::socket _socket, uint _rNId, bi
PeerSession::~PeerSession() PeerSession::~PeerSession()
{ {
m_strand.post([=]() // Read-chain finished for one reason or another.
try
{ {
if (!m_writeq.empty())
m_writeq.clear();
try {
if (m_socket.is_open()) if (m_socket.is_open())
m_socket.close(); m_socket.close();
}catch (...){} }
}); catch (...){}
} }
bi::tcp::endpoint PeerSession::endpoint() const bi::tcp::endpoint PeerSession::endpoint() const
@ -395,19 +391,6 @@ RLPStream& PeerSession::prep(RLPStream& _s)
return _s.appendRaw(bytes(8, 0)); return _s.appendRaw(bytes(8, 0));
} }
void PeerServer::seal(bytes& _b)
{
_b[0] = 0x22;
_b[1] = 0x40;
_b[2] = 0x08;
_b[3] = 0x91;
uint32_t len = (uint32_t)_b.size() - 8;
_b[4] = (len >> 24) & 0xff;
_b[5] = (len >> 16) & 0xff;
_b[6] = (len >> 8) & 0xff;
_b[7] = len & 0xff;
}
void PeerSession::sealAndSend(RLPStream& _s) void PeerSession::sealAndSend(RLPStream& _s)
{ {
bytes b; bytes b;
@ -441,7 +424,7 @@ void PeerSession::sendDestroy(bytes& _msg)
} }
bytes buffer = bytes(std::move(_msg)); bytes buffer = bytes(std::move(_msg));
m_strand.post(boost::bind(&PeerSession::writeImpl, this, buffer)); writeImpl(buffer);
} }
void PeerSession::send(bytesConstRef _msg) void PeerSession::send(bytesConstRef _msg)
@ -454,59 +437,66 @@ void PeerSession::send(bytesConstRef _msg)
} }
bytes buffer = bytes(_msg.toBytes()); bytes buffer = bytes(_msg.toBytes());
m_strand.post(boost::bind(&PeerSession::writeImpl, this, buffer)); writeImpl(buffer);
} }
void PeerSession::writeImpl(bytes& _buffer) void PeerSession::writeImpl(bytes& _buffer)
{ {
m_writeq.push_back(_buffer); // cerr << (void*)this << " writeImpl" << endl;
if (m_writeq.size() > 1) if (!m_socket.is_open())
return; return;
this->write(); lock_guard<recursive_mutex> l(m_writeLock);
m_writeQueue.push_back(_buffer);
if (m_writeQueue.size() == 1)
write();
} }
void PeerSession::write() void PeerSession::write()
{ {
if (m_writeq.empty()) // cerr << (void*)this << " write" << endl;
lock_guard<recursive_mutex> l(m_writeLock);
if (m_writeQueue.empty())
return; return;
const bytes& bytes = m_writeq[0]; const bytes& bytes = m_writeQueue[0];
if (m_socket.is_open()) auto self(shared_from_this());
ba::async_write(m_socket, ba::buffer(bytes), m_strand.wrap([this](boost::system::error_code ec, std::size_t /*length*/) ba::async_write(m_socket, ba::buffer(bytes), [this, self](boost::system::error_code ec, std::size_t /*length*/)
{ {
// must check que, as write callback can occur following dropped() // cerr << (void*)this << " write.callback" << endl;
if (!m_writeq.empty())
this->m_writeq.pop_front();
// must check queue, as write callback can occur following dropped()
if (ec) if (ec)
{ {
cwarn << "Error sending: " << ec.message(); cwarn << "Error sending: " << ec.message();
this->dropped(); dropped();
} else }
m_strand.post(boost::bind(&PeerSession::write, this)); else
})); {
m_writeQueue.pop_front();
write();
}
});
} }
void PeerSession::dropped() void PeerSession::dropped()
{ {
// cerr << (void*)this << " dropped" << endl;
if (m_socket.is_open()) if (m_socket.is_open())
try { try
{
clogS(NetNote) << "Closing " << m_socket.remote_endpoint(); clogS(NetNote) << "Closing " << m_socket.remote_endpoint();
m_socket.close(); m_socket.close();
}catch (...){} }
catch (...) {}
// block future writes by running in strand and clearing queue // Remove from peer server
m_strand.post([=]()
{
m_writeq.clear();
for (auto i = m_server->m_peers.begin(); i != m_server->m_peers.end(); ++i) for (auto i = m_server->m_peers.begin(); i != m_server->m_peers.end(); ++i)
if (i->second.lock().get() == this) if (i->second.lock().get() == this)
{ {
m_server->m_peers.erase(i); m_server->m_peers.erase(i);
break; break;
} }
});
} }
void PeerSession::disconnect(int _reason) void PeerSession::disconnect(int _reason)
@ -568,10 +558,7 @@ void PeerSession::doRead()
while (m_incoming.size() > 8) while (m_incoming.size() > 8)
{ {
if (m_incoming[0] != 0x22 || m_incoming[1] != 0x40 || m_incoming[2] != 0x08 || m_incoming[3] != 0x91) if (m_incoming[0] != 0x22 || m_incoming[1] != 0x40 || m_incoming[2] != 0x08 || m_incoming[3] != 0x91)
{
doRead(); doRead();
}
else else
{ {
uint32_t len = fromBigEndian<uint32_t>(bytesConstRef(m_incoming.data() + 4, 4)); uint32_t len = fromBigEndian<uint32_t>(bytesConstRef(m_incoming.data() + 4, 4));

8
libethereum/PeerSession.h

@ -21,6 +21,7 @@
#pragma once #pragma once
#include <mutex>
#include <array> #include <array>
#include <set> #include <set>
#include <memory> #include <memory>
@ -65,8 +66,9 @@ private:
void writeImpl(bytes& _buffer); void writeImpl(bytes& _buffer);
void write(); void write();
PeerServer* m_server; PeerServer* m_server;
boost::asio::strand m_strand;
std::deque<bytes> m_writeq; std::recursive_mutex m_writeLock;
std::deque<bytes> m_writeQueue;
bi::tcp::socket m_socket; bi::tcp::socket m_socket;
std::array<byte, 65536> m_data; std::array<byte, 65536> m_data;
@ -89,6 +91,8 @@ private:
std::set<h256> m_knownBlocks; std::set<h256> m_knownBlocks;
std::set<h256> m_knownTransactions; std::set<h256> m_knownTransactions;
bool m_willBeDeleted = false; ///< True if we already posted a deleter on the strand.
}; };
} }

4
libpyserpent/CMakeLists.txt

@ -7,9 +7,6 @@ set(EXECUTABLE pyserpent)
# set(CMAKE_INSTALL_PREFIX ../lib) # set(CMAKE_INSTALL_PREFIX ../lib)
add_library(${EXECUTABLE} SHARED ${SRC_LIST}) add_library(${EXECUTABLE} SHARED ${SRC_LIST})
if (UNIX)
FIND_PACKAGE(Boost 1.53 REQUIRED COMPONENTS python)
endif()
file(GLOB HEADERS "*.h") file(GLOB HEADERS "*.h")
include_directories(..) include_directories(..)
@ -21,7 +18,6 @@ target_link_libraries(${EXECUTABLE} ethential)
target_link_libraries(${EXECUTABLE} ${PYTHON_LS}) target_link_libraries(${EXECUTABLE} ${PYTHON_LS})
if("${TARGET_PLATFORM}" STREQUAL "w64") if("${TARGET_PLATFORM}" STREQUAL "w64")
target_link_libraries(${EXECUTABLE} boost_python_win32-mt-s)
target_link_libraries(${EXECUTABLE} boost_thread_win32-mt-s) target_link_libraries(${EXECUTABLE} boost_thread_win32-mt-s)
target_link_libraries(${EXECUTABLE} iphlpapi) target_link_libraries(${EXECUTABLE} iphlpapi)
target_link_libraries(${EXECUTABLE} ws2_32) target_link_libraries(${EXECUTABLE} ws2_32)

1
sc/cmdline.cpp

@ -1,4 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <string>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <map> #include <map>

4
walleth/MainWin.cpp

@ -243,10 +243,10 @@ void Main::on_net_triggered(bool _auto)
if (_auto) if (_auto)
{ {
QString s = m_servers[rand() % m_servers.size()]; QString s = m_servers[rand() % m_servers.size()];
client()->startNetwork(m_port, s.section(':', 0, 0).toStdString(), s.section(':', 1).toInt(), NodeMode::Full, m_idealPeers, std::string(), ui->upnp->isChecked()); client()->startNetwork(m_port, s.section(':', 0, 0).toStdString(), s.section(':', 1).toInt(), NodeMode::Full, m_idealPeers, "", ui->upnp->isChecked());
} }
else else
client()->startNetwork(m_port, string(), 0, NodeMode::Full, m_idealPeers, std::string(), ui->upnp->isChecked()); client()->startNetwork(m_port, string(), 0, NodeMode::Full, m_idealPeers, "", ui->upnp->isChecked());
if (m_peers.size()) if (m_peers.size())
client()->peerServer()->restorePeers(bytesConstRef((byte*)m_peers.data(), m_peers.size())); client()->peerServer()->restorePeers(bytesConstRef((byte*)m_peers.data(), m_peers.size()));
} }

Loading…
Cancel
Save