Browse Source

Move eth over to WebThreeDirect.

cl-refactor
Gav Wood 10 years ago
parent
commit
dde79b2b88
  1. 4
      eth/CMakeLists.txt
  2. 14
      eth/main.cpp
  3. 1
      libethereum/EthereumHost.cpp
  4. 2
      libethereum/EthereumPeer.cpp
  5. 2
      libethereum/EthereumPeer.h
  6. 6
      libp2p/Host.cpp
  7. 4
      libwebthree/WebThree.h

4
eth/CMakeLists.txt

@ -4,13 +4,13 @@ aux_source_directory(. SRC_LIST)
include_directories(..)
link_directories(../libethcore)
link_directories(../libethereum)
link_directories(../libwebthree)
set(EXECUTABLE eth)
add_executable(${EXECUTABLE} ${SRC_LIST})
target_link_libraries(${EXECUTABLE} ethereum)
target_link_libraries(${EXECUTABLE} webthree)
target_link_libraries(${EXECUTABLE} secp256k1)
target_link_libraries(${EXECUTABLE} gmp)
if(MINIUPNPC_LS)

14
eth/main.cpp

@ -33,6 +33,7 @@
#include <libevmface/Instruction.h>
#include <libevm/VM.h>
#include <libethereum/All.h>
#include <libwebthree/WebThree.h>
#if ETH_READLINE
#include <readline/readline.h>
#include <readline/history.h>
@ -43,6 +44,7 @@
#include "BuildInfo.h"
using namespace std;
using namespace dev;
using namespace dev::p2p;
using namespace dev::eth;
using namespace boost::algorithm;
using dev::eth::Instruction;
@ -296,16 +298,18 @@ int main(int argc, char** argv)
if (!clientName.empty())
clientName += "/";
Client c("Ethereum(++)/" + clientName + "v" + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), coinbase, dbPath);
c.setForceMining(true);
cout << credits();
dev::WebThreeDirect web3("Ethereum(++)/" + clientName + "v" + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), dbPath, false, mode == NodeMode::Full ? set<string>{"eth", "shh"} : set<string>{}, NetworkPreferences(listenPort, publicIP, upnp, false));
web3.setIdealPeerCount(peers);
eth::Client& c = *web3.ethereum();
c.setForceMining(forceMining);
c.setAddress(coinbase);
cout << "Address: " << endl << toHex(us.address().asArray()) << endl;
c.startNetwork(listenPort, remoteHost, remotePort, mode, peers, publicIP, upnp);
web3.startNetwork();
web3.connect(remoteHost, remotePort);
#if ETH_JSONRPC
auto_ptr<EthStubServer> jsonrpcServer;

1
libethereum/EthereumHost.cpp

@ -205,6 +205,7 @@ void EthereumHost::maintainBlocks(BlockQueue& _bq, h256 _currentHash)
for (auto j: peers())
{
auto p = j->cap<EthereumPeer>();
Guard l(p->x_knownBlocks);
if (!p->m_knownBlocks.count(_currentHash))
p->send(&b);
p->m_knownBlocks.clear();

2
libethereum/EthereumPeer.cpp

@ -235,6 +235,7 @@ bool EthereumPeer::interpret(RLP const& _r)
if (host()->noteBlock(h, _r[i].data()))
used++;
m_askedBlocks.erase(h);
Guard l(x_knownBlocks);
m_knownBlocks.insert(h);
}
addRating(used);
@ -246,6 +247,7 @@ bool EthereumPeer::interpret(RLP const& _r)
{
auto h = BlockInfo::headerHash(_r[i].data());
BlockInfo bi(_r[i].data());
Guard l(x_knownBlocks);
if (!host()->m_chain->details(bi.parentHash) && !m_knownBlocks.count(bi.parentHash))
{
unknownParents++;

2
libethereum/EthereumPeer.h

@ -27,6 +27,7 @@
#include <memory>
#include <utility>
#include <libdevcore/RLP.h>
#include <libdevcore/Guards.h>
#include <libethcore/CommonEth.h>
#include <libp2p/Capability.h>
#include "CommonNet.h"
@ -80,6 +81,7 @@ private:
bool m_requireTransactions;
Mutex x_knownBlocks;
std::set<h256> m_knownBlocks;
std::set<h256> m_knownTransactions;
};

6
libp2p/Host.cpp

@ -70,7 +70,6 @@ Host::Host(std::string const& _clientVersion, NetworkPreferences const& _n, bool
Host::~Host()
{
disconnectPeers();
stop();
}
@ -86,6 +85,8 @@ void Host::start()
m_acceptor.set_option(ba::socket_base::reuse_address(true));
m_acceptor.bind(endpoint);
m_acceptor.listen();
m_listenPort = i ? m_acceptor.local_endpoint().port() : m_netPrefs.listenPort;
break;
}
catch (...)
{
@ -98,7 +99,6 @@ void Host::start()
continue;
}
}
m_listenPort = m_acceptor.local_endpoint().port();
determinePublic(m_netPrefs.publicIP, m_netPrefs.upnp);
ensureAccepting();
@ -117,6 +117,7 @@ void Host::stop()
}
if (m_socket.is_open())
m_socket.close();
disconnectPeers();
}
unsigned Host::protocolVersion() const
@ -339,6 +340,7 @@ void Host::connect(std::string const& _addr, unsigned short _port) noexcept
{
try
{
// TODO: actual DNS lookup.
connect(bi::tcp::endpoint(bi::address::from_string(_addr), _port));
}
catch (exception const& e)

4
libwebthree/WebThree.h

@ -104,7 +104,9 @@ public:
/// Sets the ideal number of peers.
void setIdealPeerCount(size_t _n);
void setNetworkPreferences(p2p::NetworkPreferences const& _n) { stopNetwork(); m_netPrefs = _n; startNetwork(); }
bool haveNetwork() const { return !!m_work; }
void setNetworkPreferences(p2p::NetworkPreferences const& _n) { auto had = haveNetwork(); if (had) stopNetwork(); m_netPrefs = _n; if (had) startNetwork(); }
/// Start the network subsystem.
void startNetwork();

Loading…
Cancel
Save