Browse Source

New net is compiling.

cl-refactor
Gav Wood 11 years ago
parent
commit
aecb8c8c1a
  1. 2
      libethereum/All.h
  2. 1
      libethereum/CMakeLists.txt
  3. 8
      libethereum/Client.cpp
  4. 4
      libethereum/Client.h
  5. 2
      libethereum/CommonNet.h
  6. 1
      libethereumx/Ethereum.h
  7. 9
      libethnet/PeerHost.h
  8. 2
      libethnet/PeerSession.h
  9. 11
      test/peer.cpp

2
libethereum/All.h

@ -8,7 +8,7 @@
#include "ExtVM.h" #include "ExtVM.h"
#include "CommonNet.h" #include "CommonNet.h"
#include "EthereumHost.h" #include "EthereumHost.h"
#include "EthereumSession.h" #include "EthereumPeer.h"
#include "State.h" #include "State.h"
#include "Transaction.h" #include "Transaction.h"
#include "TransactionQueue.h" #include "TransactionQueue.h"

1
libethereum/CMakeLists.txt

@ -20,6 +20,7 @@ include_directories(..)
target_link_libraries(${EXECUTABLE} evm) target_link_libraries(${EXECUTABLE} evm)
target_link_libraries(${EXECUTABLE} lll) target_link_libraries(${EXECUTABLE} lll)
target_link_libraries(${EXECUTABLE} ethcore) target_link_libraries(${EXECUTABLE} ethcore)
target_link_libraries(${EXECUTABLE} ethnet)
target_link_libraries(${EXECUTABLE} secp256k1) target_link_libraries(${EXECUTABLE} secp256k1)
if(MINIUPNPC_LS) if(MINIUPNPC_LS)
target_link_libraries(${EXECUTABLE} ${MINIUPNPC_LS}) target_link_libraries(${EXECUTABLE} ${MINIUPNPC_LS})

8
libethereum/Client.cpp

@ -215,15 +215,15 @@ void Client::startNetwork(unsigned short _listenPort, std::string const& _seedHo
try try
{ {
m_net.reset(new PeerHost(m_clientVersion, _listenPort, _publicIP, _upnp)); m_net.reset(new PeerHost(m_clientVersion, _listenPort, _publicIP, _upnp));
if (_mode == NodeMode::Full)
m_net->registerCapability(new EthereumHost(m_bc, _networkId));
} }
catch (std::exception const&) catch (std::exception const&)
{ {
// Probably already have the port open. // Probably already have the port open.
cwarn << "Could not initialize with specified/default port. Trying system-assigned port"; cwarn << "Could not initialize with specified/default port. Trying system-assigned port";
m_net.reset(new EthereumHost(m_clientVersion, m_bc, 0, _mode, _publicIP, _upnp)); m_net.reset(new PeerHost(m_clientVersion, 0, _publicIP, _upnp));
} }
if (_mode == NodeMode::Full)
m_net->registerCapability(new EthereumHost(m_bc, _networkId));
} }
m_net->setIdealPeerCount(_peers); m_net->setIdealPeerCount(_peers);
} }
@ -442,7 +442,7 @@ void Client::workNet()
// returns h256Set as block hashes, once for each block that has come in/gone out. // returns h256Set as block hashes, once for each block that has come in/gone out.
cwork << "NET <==> TQ ; CHAIN ==> NET ==> BQ"; cwork << "NET <==> TQ ; CHAIN ==> NET ==> BQ";
m_net->sync(m_tq, m_bq); m_net->cap<EthereumHost>()->sync(m_tq, m_bq);
cwork << "TQ:" << m_tq.items() << "; BQ:" << m_bq.items(); cwork << "TQ:" << m_tq.items() << "; BQ:" << m_bq.items();
} }

4
libethereum/Client.h

@ -54,7 +54,7 @@ enum ClientWorkState
enum class NodeMode enum class NodeMode
{ {
Peer, PeerServer,
Full Full
}; };
@ -305,7 +305,7 @@ private:
std::unique_ptr<std::thread> m_workNet; ///< The network thread. std::unique_ptr<std::thread> m_workNet; ///< The network thread.
std::atomic<ClientWorkState> m_workNetState; std::atomic<ClientWorkState> m_workNetState;
mutable boost::shared_mutex x_net; ///< Lock for the network existance. mutable boost::shared_mutex x_net; ///< Lock for the network existance.
std::unique_ptr<EthereumHost> m_net; ///< Should run in background and send us events when blocks found and allow us to send blocks as required. std::unique_ptr<PeerHost> m_net; ///< Should run in background and send us events when blocks found and allow us to send blocks as required.
std::unique_ptr<std::thread> m_work; ///< The work thread. std::unique_ptr<std::thread> m_work; ///< The work thread.
std::atomic<ClientWorkState> m_workState; std::atomic<ClientWorkState> m_workState;

2
libethereum/CommonNet.h

@ -43,7 +43,7 @@ class TransactionQueue;
class EthereumHost; class EthereumHost;
class EthereumPeer; class EthereumPeer;
enum enum EthereumPacket
{ {
StatusPacket = 0x10, StatusPacket = 0x10,
GetTransactionsPacket, GetTransactionsPacket,

1
libethereumx/Ethereum.h

@ -30,6 +30,7 @@
#include <libethential/CommonIO.h> #include <libethential/CommonIO.h>
#include <libethential/Guards.h> #include <libethential/Guards.h>
#include <libevm/FeeStructure.h> #include <libevm/FeeStructure.h>
#include <libethnet/Common.h>
#include <libethcore/Dagger.h> #include <libethcore/Dagger.h>
#include <libethereum/PastMessage.h> #include <libethereum/PastMessage.h>
#include <libethereum/MessageFilter.h> #include <libethereum/MessageFilter.h>

9
libethnet/PeerHost.h

@ -68,7 +68,11 @@ public:
unsigned protocolVersion() const; unsigned protocolVersion() const;
/// Register a peer-capability; all new peer connections will have this capability. /// Register a peer-capability; all new peer connections will have this capability.
template <class T> void registerCapability(T* _t) { _t->m_host = this; m_capabilities[T::name()] = std::shared_ptr<HostCapabilityFace>(_t); } template <class T> void registerCapability(T* _t) { _t->m_host = this; m_capabilities[T::staticName()] = std::shared_ptr<HostCapabilityFace>(_t); }
bool haveCapability(std::string const& _name) const { return m_capabilities.count(_name); }
std::vector<std::string> caps() const { std::vector<std::string> ret; for (auto const& i: m_capabilities) ret.push_back(i.first); return ret; }
template <class T> std::shared_ptr<T> cap() const { try { return std::static_pointer_cast<T>(m_capabilities.at(T::staticName())); } catch (...) { return nullptr; } }
/// Connect to a peer explicitly. /// Connect to a peer explicitly.
void connect(std::string const& _addr, unsigned short _port = 30303) noexcept; void connect(std::string const& _addr, unsigned short _port = 30303) noexcept;
@ -105,9 +109,6 @@ public:
void registerPeer(std::shared_ptr<PeerSession> _s, std::vector<std::string> const& _caps); void registerPeer(std::shared_ptr<PeerSession> _s, std::vector<std::string> const& _caps);
bool haveCapability(std::string const& _name) const { return m_capabilities.count(_name); }
std::vector<std::string> caps() const { std::vector<std::string> ret; for (auto const& i: m_capabilities) ret.push_back(i.first); return ret; }
protected: protected:
/// Called when the session has provided us with a new peer we can connect to. /// Called when the session has provided us with a new peer we can connect to.
void noteNewPeers() {} void noteNewPeers() {}

2
libethnet/PeerSession.h

@ -58,7 +58,7 @@ public:
bi::tcp::endpoint endpoint() const; ///< for other peers to connect to. bi::tcp::endpoint endpoint() const; ///< for other peers to connect to.
template <class PeerCap> template <class PeerCap>
PeerCap* cap() const { try { return static_cast<PeerCap*>(m_capabilities.at(PeerCap::name())); } catch (...) { return nullptr; } } std::shared_ptr<PeerCap> cap() const { try { return std::static_pointer_cast<PeerCap>(m_capabilities.at(PeerCap::name())); } catch (...) { return nullptr; } }
static RLPStream& prep(RLPStream& _s); static RLPStream& prep(RLPStream& _s);
void sealAndSend(RLPStream& _s); void sealAndSend(RLPStream& _s);

11
test/peer.cpp

@ -22,9 +22,7 @@
#include <chrono> #include <chrono>
#include <thread> #include <thread>
#include <boost/filesystem/operations.hpp> #include <libethnet/PeerHost.h>
#include <libethereum/BlockChain.h>
#include <libethereum/EthereumHost.h>
using namespace std; using namespace std;
using namespace eth; using namespace eth;
using boost::asio::ip::tcp; using boost::asio::ip::tcp;
@ -48,18 +46,17 @@ int peerTest(int argc, char** argv)
remoteHost = argv[i]; remoteHost = argv[i];
} }
BlockChain ch(boost::filesystem::temp_directory_path().string()); PeerHost ph("Test", listenPort);
EthereumHost pn("Test", ch, 0, listenPort);
if (!remoteHost.empty()) if (!remoteHost.empty())
pn.connect(remoteHost, remotePort); ph.connect(remoteHost, remotePort);
for (int i = 0; ; ++i) for (int i = 0; ; ++i)
{ {
this_thread::sleep_for(chrono::milliseconds(100)); this_thread::sleep_for(chrono::milliseconds(100));
// pn.sync(); // pn.sync();
if (!(i % 10)) if (!(i % 10))
pn.pingAll(); ph.pingAll();
} }
return 0; return 0;

Loading…
Cancel
Save