diff --git a/src/Config.cpp b/src/Config.cpp index 41030c187b..6e4b67ce87 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -112,8 +112,6 @@ void Config::setup(const std::string& strConf) // Defaults // - VERSION = 1; - NETWORK_START_TIME = 1319844908; PEER_PORT = SYSTEM_PEER_PORT; diff --git a/src/Config.h b/src/Config.h index f7a443b96d..6a88d13cfe 100644 --- a/src/Config.h +++ b/src/Config.h @@ -43,10 +43,6 @@ const int SYSTEM_WEBSOCKET_PORT = 6562; class Config { public: - // Core software parameters - int VERSION; - std::string VERSION_STR; - // Configuration parameters boost::filesystem::path CONFIG_FILE; boost::filesystem::path CONFIG_DIR; diff --git a/src/Peer.cpp b/src/Peer.cpp index f4cbbcb0a9..eb9ad2099e 100644 --- a/src/Peer.cpp +++ b/src/Peer.cpp @@ -8,6 +8,7 @@ #include "../json/writer.h" +#include "Version.h" #include "Peer.h" #include "Config.h" #include "Application.h" @@ -565,15 +566,20 @@ void Peer::processReadBuffer() void Peer::recvHello(newcoin::TMHello& packet) { -#ifdef DEBUG - Log(lsINFO) << "Recv(Hello) v=" << packet.version() << ", index=" << packet.ledgerindex(); -#endif + Log(lsTRACE) << "Recv(Hello) v=" << packet.versionmajor() << "." << packet.versionminor(); bool bDetach = true; // Cancel verification timeout. (void) mVerifyTimer.cancel(); - if (!mNodePublic.setNodePublic(packet.nodepublic())) + if ((packet.minprotoversionmajor() > PROTO_VERSION_MAJ) || + ((packet.minprotoversionmajor() == PROTO_VERSION_MAJ) && (packet.minprotoversionminor() > PROTO_VERSION_MIN))) + { + Log(lsINFO) << "Recv(Hello): Server requires protocol version " << + packet.minprotoversionmajor() << "." << packet.minprotoversionminor() << " we run " << + PROTO_VERSION_MAJ << "." << PROTO_VERSION_MIN; + } + else if (!mNodePublic.setNodePublic(packet.nodepublic())) { Log(lsINFO) << "Recv(Hello): Disconnect: Bad node public key."; } @@ -585,6 +591,14 @@ void Peer::recvHello(newcoin::TMHello& packet) { // Successful connection. Log(lsINFO) << "Recv(Hello): Connect: " << mNodePublic.humanNodePublic(); + if ( (packet.versionmajor() != SERVER_VERSION_MAJ) || (packet.versionminor() != SERVER_VERSION_MIN)) + { + if (packet.has_fullversion()) + Log(lsINFO) << " Peer is running version " << packet.fullversion(); + else + Log(lsINFO) << " Peer is running version " << packet.versionmajor() << "." << packet.versionminor(); + } + if (mClientConnect) { // If we connected due to scan, no longer need to scan. @@ -1104,16 +1118,20 @@ void Peer::sendHello() newcoin::TMHello h; - h.set_version(theConfig.VERSION); - h.set_ledgerindex(theApp->getOPs().getCurrentLedgerID()); + h.set_versionmajor(SERVER_VERSION_MAJ); + h.set_versionminor(SERVER_VERSION_MIN); + h.set_protoversionmajor(PROTO_VERSION_MAJ); + h.set_protoversionminor(PROTO_VERSION_MIN); + h.set_minprotoversionminor(MIN_PROTO_MAJ); + h.set_minprotoversionmajor(MIN_PROTO_MIN); + h.set_fullversion(SERVER_VERSION); h.set_nettime(theApp->getOPs().getNetworkTimeNC()); h.set_nodepublic(theApp->getWallet().getNodePublic().humanNodePublic()); h.set_nodeproof(&vchSig[0], vchSig.size()); h.set_ipv4port(theConfig.PEER_PORT); Ledger::pointer closedLedger = theApp->getMasterLedger().getClosedLedger(); - assert(closedLedger && closedLedger->isClosed()); - if (closedLedger->isClosed()) + if (closedLedger && closedLedger->isClosed()) { uint256 hash = closedLedger->getHash(); h.set_closedledger(hash.begin(), hash.GetSerializeSize()); diff --git a/src/newcoin.proto b/src/newcoin.proto index 1b4e30f556..99d9b591fb 100644 --- a/src/newcoin.proto +++ b/src/newcoin.proto @@ -37,14 +37,20 @@ enum MessageType { message TMHello { - required uint32 version = 1; - optional uint32 ledgerIndex = 2; - optional uint64 netTime = 3; - optional bytes nodePublic = 4; // node may opt to remain anonymous - optional bytes nodeProof = 5; - optional uint32 ipv4Port = 6; - optional bytes closedLedger = 7; // our last closed ledger - optional bytes previousLedger = 8; // the ledger before the last closed ledger + required uint32 versionMinor = 1; + required uint32 versionMajor = 2; + required uint32 protoVersionMinor = 3; + required uint32 protoVersionMajor = 4; + required uint32 minProtoVersionMinor = 5; + required uint32 minProtoVersionMajor = 6; + required bytes nodePublic = 7; + required bytes nodeProof = 8; + optional string fullVersion = 9; + optional uint64 netTime = 10; + optional uint32 ipv4Port = 11; + optional uint32 ledgerIndex = 12; + optional bytes closedLedger = 13; // our last closed ledger + optional bytes previousLedger = 14; // the ledger before the last closed ledger } diff --git a/src/rpc.cpp b/src/rpc.cpp index 77a414cc4b..2a289197de 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -15,14 +15,11 @@ #include "BitcoinUtil.h" #include "Config.h" #include "Log.h" +#include "Version.h" using namespace boost; using namespace boost::asio; - - - - Json::Value JSONRPCError(int code, const std::string& message) { Json::Value error(Json::objectValue); @@ -116,7 +113,7 @@ std::string HTTPReply(int nStatus, const std::string& strMsg) rfc1123Time().c_str(), access.c_str(), strMsg.size(), - theConfig.VERSION_STR.c_str(), + SERVER_VERSION, strMsg.c_str()); }