diff --git a/libdevcore/Common.cpp b/libdevcore/Common.cpp index 551b7af87..8a8687bfa 100644 --- a/libdevcore/Common.cpp +++ b/libdevcore/Common.cpp @@ -27,7 +27,7 @@ using namespace dev; namespace dev { -char const* Version = "0.6.11"; +char const* Version = "0.7.0"; } diff --git a/libethcore/CommonEth.cpp b/libethcore/CommonEth.cpp index 44297e0ba..1526da1b0 100644 --- a/libethcore/CommonEth.cpp +++ b/libethcore/CommonEth.cpp @@ -34,7 +34,7 @@ namespace dev namespace eth { -const unsigned c_protocolVersion = 33; +const unsigned c_protocolVersion = 34; const unsigned c_databaseVersion = 2; static const vector> g_units = diff --git a/libethereum/EthereumPeer.h b/libethereum/EthereumPeer.h index 00788d019..bad12d3b7 100644 --- a/libethereum/EthereumPeer.h +++ b/libethereum/EthereumPeer.h @@ -58,6 +58,9 @@ public: /// What is our name? static std::string name() { return "eth"; } + /// What is our version? + static u256 version() { return c_protocolVersion; } + /// What is the ethereum subprotocol host object. EthereumHost* host() const; diff --git a/libp2p/Capability.h b/libp2p/Capability.h index bffd38c79..00cccaeef 100644 --- a/libp2p/Capability.h +++ b/libp2p/Capability.h @@ -39,6 +39,7 @@ public: /// Must return the capability name. static std::string name() { return ""; } + static u256 version() { return 0; } Session* session() const { return m_session; } HostCapabilityFace* hostCapability() const { return m_host; } diff --git a/libp2p/Common.h b/libp2p/Common.h index a5f7e5d84..bb1b1e2e0 100644 --- a/libp2p/Common.h +++ b/libp2p/Common.h @@ -24,6 +24,8 @@ #pragma once #include +#include +#include #include #include #include @@ -88,13 +90,17 @@ enum DisconnectReason /// @returns the string form of the given disconnection reason. std::string reasonOf(DisconnectReason _r); +typedef std::pair CapDesc; +typedef std::set CapDescSet; +typedef std::vector CapDescs; + struct PeerInfo { std::string clientVersion; std::string host; unsigned short port; std::chrono::steady_clock::duration lastPing; - std::set caps; + std::set caps; unsigned socket; std::map notes; }; diff --git a/libp2p/Host.cpp b/libp2p/Host.cpp index 43758f0f5..d13cbf4f9 100644 --- a/libp2p/Host.cpp +++ b/libp2p/Host.cpp @@ -38,6 +38,7 @@ #include #include #include "Session.h" +#include "Common.h" #include "Capability.h" #include "UPnP.h" using namespace std; @@ -145,7 +146,7 @@ unsigned Host::protocolVersion() const return 0; } -void Host::registerPeer(std::shared_ptr _s, vector const& _caps) +void Host::registerPeer(std::shared_ptr _s, CapDescs const& _caps) { { Guard l(x_peers); diff --git a/libp2p/Host.h b/libp2p/Host.h index f5f2f9e97..b4ba9c2d4 100644 --- a/libp2p/Host.h +++ b/libp2p/Host.h @@ -31,6 +31,7 @@ #include #include #include "HostCapability.h" +#include "Common.h" namespace ba = boost::asio; namespace bi = boost::asio::ip; @@ -75,11 +76,11 @@ public: unsigned protocolVersion() const; /// Register a peer-capability; all new peer connections will have this capability. - template std::shared_ptr registerCapability(T* _t) { _t->m_host = this; auto ret = std::shared_ptr(_t); m_capabilities[T::staticName()] = ret; return ret; } + template std::shared_ptr registerCapability(T* _t) { _t->m_host = this; auto ret = std::shared_ptr(_t); m_capabilities[std::make_pair(T::staticName(), T::staticVersion())] = ret; return ret; } - bool haveCapability(std::string const& _name) const { return m_capabilities.count(_name) != 0; } - 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; } } + bool haveCapability(CapDesc const& _name) const { return m_capabilities.count(_name) != 0; } + CapDescs caps() const { CapDescs 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(std::make_pair(T::staticName(), T::staticVersion()))); } catch (...) { return nullptr; } } /// Connect to a peer explicitly. static std::string pocHost(); @@ -118,7 +119,7 @@ public: h512 id() const { return m_id; } - void registerPeer(std::shared_ptr _s, std::vector const& _caps); + void registerPeer(std::shared_ptr _s, CapDescs const& _caps); private: /// Called when the session has provided us with a new peer we can connect to. @@ -166,7 +167,7 @@ private: std::vector m_addresses; std::vector m_peerAddresses; - std::map> m_capabilities; + std::map> m_capabilities; bool m_accepting = false; }; diff --git a/libp2p/HostCapability.cpp b/libp2p/HostCapability.cpp index a3a47cd5c..2f295afd0 100644 --- a/libp2p/HostCapability.cpp +++ b/libp2p/HostCapability.cpp @@ -38,7 +38,7 @@ std::vector > HostCapabilityFace::peers() const std::vector > ret; for (auto const& i: m_host->m_peers) if (std::shared_ptr p = i.second.lock()) - if (p->m_capabilities.count(name())) + if (p->m_capabilities.count(capDesc())) ret.push_back(p); return ret; } diff --git a/libp2p/HostCapability.h b/libp2p/HostCapability.h index 1c532788b..f07900034 100644 --- a/libp2p/HostCapability.h +++ b/libp2p/HostCapability.h @@ -47,6 +47,8 @@ public: protected: virtual std::string name() const = 0; + virtual u256 version() const = 0; + CapDesc capDesc() const { return std::make_pair(name(), version()); } virtual Capability* newPeerCapability(Session* _s) = 0; virtual void onStarting() {} @@ -66,9 +68,11 @@ public: virtual ~HostCapability() {} static std::string staticName() { return PeerCap::name(); } + static u256 staticVersion() { return PeerCap::version(); } protected: virtual std::string name() const { return PeerCap::name(); } + virtual u256 version() const { return PeerCap::version(); } virtual Capability* newPeerCapability(Session* _s) { return new PeerCap(_s, this); } }; diff --git a/libp2p/Session.cpp b/libp2p/Session.cpp index c50990476..71780ff6b 100644 --- a/libp2p/Session.cpp +++ b/libp2p/Session.cpp @@ -40,7 +40,7 @@ Session::Session(Host* _s, bi::tcp::socket _socket, bi::address _peerAddress, un { m_disconnect = std::chrono::steady_clock::time_point::max(); m_connect = std::chrono::steady_clock::now(); - m_info = PeerInfo({"?", _peerAddress.to_string(), m_listenPort, std::chrono::steady_clock::duration(0), set(), 0, map()}); + m_info = PeerInfo({"?", _peerAddress.to_string(), m_listenPort, std::chrono::steady_clock::duration(0), CapDescSet(), 0, map()}); } Session::~Session() @@ -78,7 +78,7 @@ bool Session::interpret(RLP const& _r) { m_protocolVersion = _r[1].toInt(); auto clientVersion = _r[2].toString(); - auto caps = _r[3].toVector(); + auto caps = _r[3].toVector(); m_listenPort = _r[4].toInt(); m_id = _r[5].toHash(); @@ -102,7 +102,7 @@ bool Session::interpret(RLP const& _r) return false; } try - { m_info = PeerInfo({clientVersion, m_socket.remote_endpoint().address().to_string(), m_listenPort, std::chrono::steady_clock::duration(), _r[3].toSet(), (unsigned)m_socket.native_handle(), map() }); } + { m_info = PeerInfo({clientVersion, m_socket.remote_endpoint().address().to_string(), m_listenPort, std::chrono::steady_clock::duration(), _r[3].toSet(), (unsigned)m_socket.native_handle(), map() }); } catch (...) { disconnect(BadProtocol); diff --git a/libp2p/Session.h b/libp2p/Session.h index 934e548d4..9b04154ee 100644 --- a/libp2p/Session.h +++ b/libp2p/Session.h @@ -62,7 +62,7 @@ public: bi::tcp::endpoint endpoint() const; ///< for other peers to connect to. template - std::shared_ptr cap() const { try { return std::static_pointer_cast(m_capabilities.at(PeerCap::name())); } catch (...) { return nullptr; } } + std::shared_ptr cap() const { try { return std::static_pointer_cast(m_capabilities.at(std::make_pair(PeerCap::name(), PeerCap::version()))); } catch (...) { return nullptr; } } static RLPStream& prep(RLPStream& _s); void sealAndSend(RLPStream& _s); @@ -108,7 +108,7 @@ private: unsigned m_rating; - std::map> m_capabilities; + std::map> m_capabilities; bool m_willBeDeleted = false; ///< True if we already posted a deleter on the strand. }; diff --git a/libwhisper/WhisperPeer.h b/libwhisper/WhisperPeer.h index b3fe2701b..ae20cae68 100644 --- a/libwhisper/WhisperPeer.h +++ b/libwhisper/WhisperPeer.h @@ -53,6 +53,7 @@ public: virtual ~WhisperPeer(); static std::string name() { return "shh"; } + static u256 version() { return 1; } WhisperHost* host() const;