From aecb8c8c1a37f1f24037a2b053f2a3a84f342249 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 1 Sep 2014 18:54:06 +0200 Subject: [PATCH] New net is compiling. --- libethereum/All.h | 2 +- libethereum/CMakeLists.txt | 1 + libethereum/Client.cpp | 8 ++++---- libethereum/Client.h | 4 ++-- libethereum/CommonNet.h | 2 +- libethereumx/Ethereum.h | 1 + libethnet/PeerHost.h | 9 +++++---- libethnet/PeerSession.h | 2 +- test/peer.cpp | 11 ++++------- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/libethereum/All.h b/libethereum/All.h index 17151f1b0..ba22640e7 100644 --- a/libethereum/All.h +++ b/libethereum/All.h @@ -8,7 +8,7 @@ #include "ExtVM.h" #include "CommonNet.h" #include "EthereumHost.h" -#include "EthereumSession.h" +#include "EthereumPeer.h" #include "State.h" #include "Transaction.h" #include "TransactionQueue.h" diff --git a/libethereum/CMakeLists.txt b/libethereum/CMakeLists.txt index 22637d301..68597f249 100644 --- a/libethereum/CMakeLists.txt +++ b/libethereum/CMakeLists.txt @@ -20,6 +20,7 @@ include_directories(..) target_link_libraries(${EXECUTABLE} evm) target_link_libraries(${EXECUTABLE} lll) target_link_libraries(${EXECUTABLE} ethcore) +target_link_libraries(${EXECUTABLE} ethnet) target_link_libraries(${EXECUTABLE} secp256k1) if(MINIUPNPC_LS) target_link_libraries(${EXECUTABLE} ${MINIUPNPC_LS}) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index c5bdf4c1a..b29c808ba 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -215,15 +215,15 @@ void Client::startNetwork(unsigned short _listenPort, std::string const& _seedHo try { 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&) { // Probably already have the port open. 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); } @@ -442,7 +442,7 @@ void Client::workNet() // returns h256Set as block hashes, once for each block that has come in/gone out. cwork << "NET <==> TQ ; CHAIN ==> NET ==> BQ"; - m_net->sync(m_tq, m_bq); + m_net->cap()->sync(m_tq, m_bq); cwork << "TQ:" << m_tq.items() << "; BQ:" << m_bq.items(); } diff --git a/libethereum/Client.h b/libethereum/Client.h index 2848bd85a..1ff553082 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -54,7 +54,7 @@ enum ClientWorkState enum class NodeMode { - Peer, + PeerServer, Full }; @@ -305,7 +305,7 @@ private: std::unique_ptr m_workNet; ///< The network thread. std::atomic m_workNetState; mutable boost::shared_mutex x_net; ///< Lock for the network existance. - std::unique_ptr m_net; ///< Should run in background and send us events when blocks found and allow us to send blocks as required. + std::unique_ptr m_net; ///< Should run in background and send us events when blocks found and allow us to send blocks as required. std::unique_ptr m_work; ///< The work thread. std::atomic m_workState; diff --git a/libethereum/CommonNet.h b/libethereum/CommonNet.h index 1ab4ab2d3..bb459ce99 100644 --- a/libethereum/CommonNet.h +++ b/libethereum/CommonNet.h @@ -43,7 +43,7 @@ class TransactionQueue; class EthereumHost; class EthereumPeer; -enum +enum EthereumPacket { StatusPacket = 0x10, GetTransactionsPacket, diff --git a/libethereumx/Ethereum.h b/libethereumx/Ethereum.h index 0966fd699..6ede791cf 100644 --- a/libethereumx/Ethereum.h +++ b/libethereumx/Ethereum.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/libethnet/PeerHost.h b/libethnet/PeerHost.h index d56b512c7..a67e03f48 100644 --- a/libethnet/PeerHost.h +++ b/libethnet/PeerHost.h @@ -68,7 +68,11 @@ public: unsigned protocolVersion() const; /// Register a peer-capability; all new peer connections will have this capability. - template void registerCapability(T* _t) { _t->m_host = this; m_capabilities[T::name()] = std::shared_ptr(_t); } + template void registerCapability(T* _t) { _t->m_host = this; m_capabilities[T::staticName()] = std::shared_ptr(_t); } + + bool haveCapability(std::string const& _name) const { return m_capabilities.count(_name); } + std::vector caps() const { std::vector ret; for (auto const& i: m_capabilities) ret.push_back(i.first); return ret; } + template std::shared_ptr cap() const { try { return std::static_pointer_cast(m_capabilities.at(T::staticName())); } catch (...) { return nullptr; } } /// Connect to a peer explicitly. void connect(std::string const& _addr, unsigned short _port = 30303) noexcept; @@ -105,9 +109,6 @@ public: void registerPeer(std::shared_ptr _s, std::vector const& _caps); - bool haveCapability(std::string const& _name) const { return m_capabilities.count(_name); } - std::vector caps() const { std::vector ret; for (auto const& i: m_capabilities) ret.push_back(i.first); return ret; } - protected: /// Called when the session has provided us with a new peer we can connect to. void noteNewPeers() {} diff --git a/libethnet/PeerSession.h b/libethnet/PeerSession.h index 13ab6bb90..4983bce4b 100644 --- a/libethnet/PeerSession.h +++ b/libethnet/PeerSession.h @@ -58,7 +58,7 @@ public: bi::tcp::endpoint endpoint() const; ///< for other peers to connect to. template - PeerCap* cap() const { try { return static_cast(m_capabilities.at(PeerCap::name())); } catch (...) { return nullptr; } } + std::shared_ptr cap() const { try { return std::static_pointer_cast(m_capabilities.at(PeerCap::name())); } catch (...) { return nullptr; } } static RLPStream& prep(RLPStream& _s); void sealAndSend(RLPStream& _s); diff --git a/test/peer.cpp b/test/peer.cpp index 63f2b0861..4825eea30 100644 --- a/test/peer.cpp +++ b/test/peer.cpp @@ -22,9 +22,7 @@ #include #include -#include -#include -#include +#include using namespace std; using namespace eth; using boost::asio::ip::tcp; @@ -48,18 +46,17 @@ int peerTest(int argc, char** argv) remoteHost = argv[i]; } - BlockChain ch(boost::filesystem::temp_directory_path().string()); - EthereumHost pn("Test", ch, 0, listenPort); + PeerHost ph("Test", listenPort); if (!remoteHost.empty()) - pn.connect(remoteHost, remotePort); + ph.connect(remoteHost, remotePort); for (int i = 0; ; ++i) { this_thread::sleep_for(chrono::milliseconds(100)); // pn.sync(); if (!(i % 10)) - pn.pingAll(); + ph.pingAll(); } return 0;