diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bignum.h | 6 | ||||
-rw-r--r-- | src/bitcoinrpc.cpp | 3 | ||||
-rw-r--r-- | src/db.cpp | 10 | ||||
-rw-r--r-- | src/main.cpp | 11 | ||||
-rw-r--r-- | src/main.h | 7 | ||||
-rw-r--r-- | src/net.cpp | 17 | ||||
-rw-r--r-- | src/net.h | 12 | ||||
-rw-r--r-- | src/qt/bitcoingui.cpp | 8 | ||||
-rw-r--r-- | src/qt/bitcoingui.h | 1 | ||||
-rw-r--r-- | src/serialize.h | 76 | ||||
-rw-r--r-- | src/uint256.h | 6 | ||||
-rw-r--r-- | src/util.cpp | 14 | ||||
-rw-r--r-- | src/util.h | 4 |
13 files changed, 105 insertions, 70 deletions
diff --git a/src/bignum.h b/src/bignum.h index 1a2406b935..f5d545f07e 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -338,19 +338,19 @@ public: return ToString(16); } - unsigned int GetSerializeSize(int nType=0, int nVersion=VERSION) const + unsigned int GetSerializeSize(int nType=0, int nVersion=PROTOCOL_VERSION) const { return ::GetSerializeSize(getvch(), nType, nVersion); } template<typename Stream> - void Serialize(Stream& s, int nType=0, int nVersion=VERSION) const + void Serialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION) const { ::Serialize(s, getvch(), nType, nVersion); } template<typename Stream> - void Unserialize(Stream& s, int nType=0, int nVersion=VERSION) + void Unserialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION) { std::vector<unsigned char> vch; ::Unserialize(s, vch, nType, nVersion); diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index e3378782c0..1f05fa8628 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -308,7 +308,8 @@ Value getinfo(const Array& params, bool fHelp) "Returns an object containing various state info."); Object obj; - obj.push_back(Pair("version", (int)VERSION)); + obj.push_back(Pair("version", (int)CLIENT_VERSION)); + obj.push_back(Pair("protocolversion",(int)PROTOCOL_VERSION)); obj.push_back(Pair("balance", ValueFromAmount(pwalletMain->GetBalance()))); obj.push_back(Pair("blocks", (int)nBestHeight)); obj.push_back(Pair("connections", (int)vNodes.size())); diff --git a/src/db.cpp b/src/db.cpp index 9b29e799e0..7195e065ea 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -131,7 +131,7 @@ CDB::CDB(const char* pszFile, const char* pszMode) : pdb(NULL) { bool fTmp = fReadOnly; fReadOnly = false; - WriteVersion(VERSION); + WriteVersion(CLIENT_VERSION); fReadOnly = fTmp; } @@ -236,7 +236,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip) { // Update version: ssValue.clear(); - ssValue << VERSION; + ssValue << CLIENT_VERSION; } Dbt datKey(&ssKey[0], ssKey.size()); Dbt datValue(&ssValue[0], ssValue.size()); @@ -931,7 +931,7 @@ int CWalletDB::LoadWallet(CWallet* pwallet) { int nMinVersion = 0; ssValue >> nMinVersion; - if (nMinVersion > VERSION) + if (nMinVersion > CLIENT_VERSION) return DB_TOO_NEW; } } @@ -956,13 +956,13 @@ int CWalletDB::LoadWallet(CWallet* pwallet) if (fIsEncrypted && (nFileVersion == 40000 || nFileVersion == 50000)) return DB_NEED_REWRITE; - if (nFileVersion < VERSION) // Update + if (nFileVersion < CLIENT_VERSION) // Update { // Get rid of old debug.log file in current directory if (nFileVersion <= 105 && !pszSetDataDir[0]) unlink("debug.log"); - WriteVersion(VERSION); + WriteVersion(CLIENT_VERSION); } return DB_LOAD_OK; diff --git a/src/main.cpp b/src/main.cpp index 3a4e86512c..052701e5fc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,11 @@ using namespace boost; // Global state // +// Name of client reported in the 'version' message. Report the same name +// for both bitcoind and bitcoin-qt, to make it harder for attackers to +// target servers or GUI users specifically. +const std::string CLIENT_NAME("bitcoin-qt"); + CCriticalSection cs_setpwalletRegistered; set<CWallet*> setpwalletRegistered; @@ -1847,9 +1852,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) // Change version if (pfrom->nVersion >= 209) pfrom->PushMessage("verack"); - pfrom->vSend.SetVersion(min(pfrom->nVersion, VERSION)); + pfrom->vSend.SetVersion(min(pfrom->nVersion, PROTOCOL_VERSION)); if (pfrom->nVersion < 209) - pfrom->vRecv.SetVersion(min(pfrom->nVersion, VERSION)); + pfrom->vRecv.SetVersion(min(pfrom->nVersion, PROTOCOL_VERSION)); if (!pfrom->fInbound) { @@ -1902,7 +1907,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) else if (strCommand == "verack") { - pfrom->vRecv.SetVersion(min(pfrom->nVersion, VERSION)); + pfrom->vRecv.SetVersion(min(pfrom->nVersion, PROTOCOL_VERSION)); } diff --git a/src/main.h b/src/main.h index 93528cdb2b..7f8da4e898 100644 --- a/src/main.h +++ b/src/main.h @@ -27,6 +27,10 @@ class CRequestTracker; class CNode; class CBlockIndex; +static const int CLIENT_VERSION = 59900; +static const bool VERSION_IS_BETA = true; +extern const std::string CLIENT_NAME; + static const unsigned int MAX_BLOCK_SIZE = 1000000; static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/2; static const int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50; @@ -1527,6 +1531,7 @@ public: bool AppliesTo(int nVersion, std::string strSubVerIn) const { + // TODO: rework for client-version-embedded-in-strSubVer ? return (IsInEffect() && nMinVer <= nVersion && nVersion <= nMaxVer && (setSubVer.empty() || setSubVer.count(strSubVerIn))); @@ -1534,7 +1539,7 @@ public: bool AppliesToMe() const { - return AppliesTo(VERSION, ::pszSubVer); + return AppliesTo(PROTOCOL_VERSION, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<std::string>())); } bool RelayTo(CNode* pnode) const diff --git a/src/net.cpp b/src/net.cpp index e0ac2abef0..7d2f18b2d0 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -727,6 +727,21 @@ void CNode::Cleanup() } +void CNode::PushVersion() +{ + /// when NTP implemented, change to just nTime = GetAdjustedTime() + int64 nTime = (fInbound ? GetAdjustedTime() : GetTime()); + CAddress addrYou = (fUseProxy ? CAddress("0.0.0.0") : addr); + CAddress addrMe = (fUseProxy ? CAddress("0.0.0.0") : addrLocalHost); + RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce)); + PushMessage("version", PROTOCOL_VERSION, nLocalServices, nTime, addrYou, addrMe, + nLocalHostNonce, FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<string>()), nBestHeight); +} + + + + + std::map<unsigned int, int64> CNode::setBanned; CCriticalSection CNode::cs_setBanned; @@ -1225,6 +1240,8 @@ void MapPort(bool /* unused fMapPort */) static const char *strDNSSeed[] = { "bitseed.xf2.org", "dnsseed.bluematt.me", + "seed.bitcoin.sipa.be", + "dnsseed.bitcoin.dashjr.org", }; void ThreadDNSAddressSeed(void* parg) @@ -355,18 +355,8 @@ public: - void PushVersion() - { - /// when NTP implemented, change to just nTime = GetAdjustedTime() - int64 nTime = (fInbound ? GetAdjustedTime() : GetTime()); - CAddress addrYou = (fUseProxy ? CAddress("0.0.0.0") : addr); - CAddress addrMe = (fUseProxy ? CAddress("0.0.0.0") : addrLocalHost); - RAND_bytes((unsigned char*)&nLocalHostNonce, sizeof(nLocalHostNonce)); - PushMessage("version", VERSION, nLocalServices, nTime, addrYou, addrMe, - nLocalHostNonce, std::string(pszSubVer), nBestHeight); - } - + void PushVersion(); void PushMessage(const char* pszCommand) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 60c75286a7..1c49683364 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -57,6 +57,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): walletModel(0), encryptWalletAction(0), changePassphraseAction(0), + aboutQtAction(0), trayIcon(0), notificator(0) { @@ -209,7 +210,10 @@ void BitcoinGUI::createActions() quitAction->setMenuRole(QAction::QuitRole); aboutAction = new QAction(QIcon(":/icons/bitcoin"), tr("&About %1").arg(qApp->applicationName()), this); aboutAction->setToolTip(tr("Show information about Bitcoin")); - aboutAction->setMenuRole(QAction::AboutQtRole); + aboutAction->setMenuRole(QAction::AboutRole); + aboutQtAction = new QAction(tr("About &Qt"), this); + aboutQtAction->setToolTip(tr("Show information about Qt")); + aboutQtAction->setMenuRole(QAction::AboutQtRole); optionsAction = new QAction(QIcon(":/icons/options"), tr("&Options..."), this); optionsAction->setToolTip(tr("Modify configuration options for bitcoin")); optionsAction->setMenuRole(QAction::PreferencesRole); @@ -226,6 +230,7 @@ void BitcoinGUI::createActions() connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(optionsAction, SIGNAL(triggered()), this, SLOT(optionsClicked())); connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutClicked())); + connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); connect(openBitcoinAction, SIGNAL(triggered()), this, SLOT(showNormal())); connect(encryptWalletAction, SIGNAL(triggered(bool)), this, SLOT(encryptWallet(bool))); connect(changePassphraseAction, SIGNAL(triggered()), this, SLOT(changePassphrase())); @@ -253,6 +258,7 @@ void BitcoinGUI::createMenuBar() QMenu *help = appMenuBar->addMenu(tr("&Help")); help->addAction(aboutAction); + help->addAction(aboutQtAction); } void BitcoinGUI::createToolBars() diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index ecb356dc35..a0905e44ad 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -82,6 +82,7 @@ private: QAction *exportAction; QAction *encryptWalletAction; QAction *changePassphraseAction; + QAction *aboutQtAction; QSystemTrayIcon *trayIcon; Notificator *notificator; diff --git a/src/serialize.h b/src/serialize.h index efa59808f5..d3f6b7d703 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -60,9 +60,7 @@ class CDataStream; class CAutoFile; static const unsigned int MAX_SIZE = 0x02000000; -static const int VERSION = 59900; -static const char* pszSubVer = ""; -static const bool VERSION_IS_BETA = true; +static const int PROTOCOL_VERSION = 60000; // Used to bypass the rule against non-const reference to temporary // where it makes sense with wrappers such as CFlatData or CTxDB @@ -91,7 +89,7 @@ enum }; #define IMPLEMENT_SERIALIZE(statements) \ - unsigned int GetSerializeSize(int nType=0, int nVersion=VERSION) const \ + unsigned int GetSerializeSize(int nType=0, int nVersion=PROTOCOL_VERSION) const \ { \ CSerActionGetSerializeSize ser_action; \ const bool fGetSize = true; \ @@ -105,7 +103,7 @@ enum return nSerSize; \ } \ template<typename Stream> \ - void Serialize(Stream& s, int nType=0, int nVersion=VERSION) const \ + void Serialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION) const \ { \ CSerActionSerialize ser_action; \ const bool fGetSize = false; \ @@ -115,7 +113,7 @@ enum {statements} \ } \ template<typename Stream> \ - void Unserialize(Stream& s, int nType=0, int nVersion=VERSION) \ + void Unserialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION) \ { \ CSerActionUnserialize ser_action; \ const bool fGetSize = false; \ @@ -362,43 +360,43 @@ template<typename Stream, typename C> void Unserialize(Stream& is, std::basic_st // vector template<typename T, typename A> unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&); template<typename T, typename A> unsigned int GetSerializeSize_impl(const std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&); -template<typename T, typename A> inline unsigned int GetSerializeSize(const std::vector<T, A>& v, int nType, int nVersion=VERSION); +template<typename T, typename A> inline unsigned int GetSerializeSize(const std::vector<T, A>& v, int nType, int nVersion=PROTOCOL_VERSION); template<typename Stream, typename T, typename A> void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&); template<typename Stream, typename T, typename A> void Serialize_impl(Stream& os, const std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&); -template<typename Stream, typename T, typename A> inline void Serialize(Stream& os, const std::vector<T, A>& v, int nType, int nVersion=VERSION); +template<typename Stream, typename T, typename A> inline void Serialize(Stream& os, const std::vector<T, A>& v, int nType, int nVersion=PROTOCOL_VERSION); template<typename Stream, typename T, typename A> void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const boost::true_type&); template<typename Stream, typename T, typename A> void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion, const boost::false_type&); -template<typename Stream, typename T, typename A> inline void Unserialize(Stream& is, std::vector<T, A>& v, int nType, int nVersion=VERSION); +template<typename Stream, typename T, typename A> inline void Unserialize(Stream& is, std::vector<T, A>& v, int nType, int nVersion=PROTOCOL_VERSION); // others derived from vector -extern inline unsigned int GetSerializeSize(const CScript& v, int nType, int nVersion=VERSION); -template<typename Stream> void Serialize(Stream& os, const CScript& v, int nType, int nVersion=VERSION); -template<typename Stream> void Unserialize(Stream& is, CScript& v, int nType, int nVersion=VERSION); +extern inline unsigned int GetSerializeSize(const CScript& v, int nType, int nVersion=PROTOCOL_VERSION); +template<typename Stream> void Serialize(Stream& os, const CScript& v, int nType, int nVersion=PROTOCOL_VERSION); +template<typename Stream> void Unserialize(Stream& is, CScript& v, int nType, int nVersion=PROTOCOL_VERSION); // pair -template<typename K, typename T> unsigned int GetSerializeSize(const std::pair<K, T>& item, int nType, int nVersion=VERSION); -template<typename Stream, typename K, typename T> void Serialize(Stream& os, const std::pair<K, T>& item, int nType, int nVersion=VERSION); -template<typename Stream, typename K, typename T> void Unserialize(Stream& is, std::pair<K, T>& item, int nType, int nVersion=VERSION); +template<typename K, typename T> unsigned int GetSerializeSize(const std::pair<K, T>& item, int nType, int nVersion=PROTOCOL_VERSION); +template<typename Stream, typename K, typename T> void Serialize(Stream& os, const std::pair<K, T>& item, int nType, int nVersion=PROTOCOL_VERSION); +template<typename Stream, typename K, typename T> void Unserialize(Stream& is, std::pair<K, T>& item, int nType, int nVersion=PROTOCOL_VERSION); // 3 tuple -template<typename T0, typename T1, typename T2> unsigned int GetSerializeSize(const boost::tuple<T0, T1, T2>& item, int nType, int nVersion=VERSION); -template<typename Stream, typename T0, typename T1, typename T2> void Serialize(Stream& os, const boost::tuple<T0, T1, T2>& item, int nType, int nVersion=VERSION); -template<typename Stream, typename T0, typename T1, typename T2> void Unserialize(Stream& is, boost::tuple<T0, T1, T2>& item, int nType, int nVersion=VERSION); +template<typename T0, typename T1, typename T2> unsigned int GetSerializeSize(const boost::tuple<T0, T1, T2>& item, int nType, int nVersion=PROTOCOL_VERSION); +template<typename Stream, typename T0, typename T1, typename T2> void Serialize(Stream& os, const boost::tuple<T0, T1, T2>& item, int nType, int nVersion=PROTOCOL_VERSION); +template<typename Stream, typename T0, typename T1, typename T2> void Unserialize(Stream& is, boost::tuple<T0, T1, T2>& item, int nType, int nVersion=PROTOCOL_VERSION); // 4 tuple -template<typename T0, typename T1, typename T2, typename T3> unsigned int GetSerializeSize(const boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion=VERSION); -template<typename Stream, typename T0, typename T1, typename T2, typename T3> void Serialize(Stream& os, const boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion=VERSION); -template<typename Stream, typename T0, typename T1, typename T2, typename T3> void Unserialize(Stream& is, boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion=VERSION); +template<typename T0, typename T1, typename T2, typename T3> unsigned int GetSerializeSize(const boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion=PROTOCOL_VERSION); +template<typename Stream, typename T0, typename T1, typename T2, typename T3> void Serialize(Stream& os, const boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion=PROTOCOL_VERSION); +template<typename Stream, typename T0, typename T1, typename T2, typename T3> void Unserialize(Stream& is, boost::tuple<T0, T1, T2, T3>& item, int nType, int nVersion=PROTOCOL_VERSION); // map -template<typename K, typename T, typename Pred, typename A> unsigned int GetSerializeSize(const std::map<K, T, Pred, A>& m, int nType, int nVersion=VERSION); -template<typename Stream, typename K, typename T, typename Pred, typename A> void Serialize(Stream& os, const std::map<K, T, Pred, A>& m, int nType, int nVersion=VERSION); -template<typename Stream, typename K, typename T, typename Pred, typename A> void Unserialize(Stream& is, std::map<K, T, Pred, A>& m, int nType, int nVersion=VERSION); +template<typename K, typename T, typename Pred, typename A> unsigned int GetSerializeSize(const std::map<K, T, Pred, A>& m, int nType, int nVersion=PROTOCOL_VERSION); +template<typename Stream, typename K, typename T, typename Pred, typename A> void Serialize(Stream& os, const std::map<K, T, Pred, A>& m, int nType, int nVersion=PROTOCOL_VERSION); +template<typename Stream, typename K, typename T, typename Pred, typename A> void Unserialize(Stream& is, std::map<K, T, Pred, A>& m, int nType, int nVersion=PROTOCOL_VERSION); // set -template<typename K, typename Pred, typename A> unsigned int GetSerializeSize(const std::set<K, Pred, A>& m, int nType, int nVersion=VERSION); -template<typename Stream, typename K, typename Pred, typename A> void Serialize(Stream& os, const std::set<K, Pred, A>& m, int nType, int nVersion=VERSION); -template<typename Stream, typename K, typename Pred, typename A> void Unserialize(Stream& is, std::set<K, Pred, A>& m, int nType, int nVersion=VERSION); +template<typename K, typename Pred, typename A> unsigned int GetSerializeSize(const std::set<K, Pred, A>& m, int nType, int nVersion=PROTOCOL_VERSION); +template<typename Stream, typename K, typename Pred, typename A> void Serialize(Stream& os, const std::set<K, Pred, A>& m, int nType, int nVersion=PROTOCOL_VERSION); +template<typename Stream, typename K, typename Pred, typename A> void Unserialize(Stream& is, std::set<K, Pred, A>& m, int nType, int nVersion=PROTOCOL_VERSION); @@ -411,19 +409,19 @@ template<typename Stream, typename K, typename Pred, typename A> void Unserializ // Thanks to Boost serialization for this idea. // template<typename T> -inline unsigned int GetSerializeSize(const T& a, long nType, int nVersion=VERSION) +inline unsigned int GetSerializeSize(const T& a, long nType, int nVersion=PROTOCOL_VERSION) { return a.GetSerializeSize((int)nType, nVersion); } template<typename Stream, typename T> -inline void Serialize(Stream& os, const T& a, long nType, int nVersion=VERSION) +inline void Serialize(Stream& os, const T& a, long nType, int nVersion=PROTOCOL_VERSION) { a.Serialize(os, (int)nType, nVersion); } template<typename Stream, typename T> -inline void Unserialize(Stream& is, T& a, long nType, int nVersion=VERSION) +inline void Unserialize(Stream& is, T& a, long nType, int nVersion=PROTOCOL_VERSION) { a.Unserialize(is, (int)nType, nVersion); } @@ -857,39 +855,39 @@ public: typedef vector_type::const_iterator const_iterator; typedef vector_type::reverse_iterator reverse_iterator; - explicit CDataStream(int nTypeIn=SER_NETWORK, int nVersionIn=VERSION) + explicit CDataStream(int nTypeIn=SER_NETWORK, int nVersionIn=PROTOCOL_VERSION) { Init(nTypeIn, nVersionIn); } - CDataStream(const_iterator pbegin, const_iterator pend, int nTypeIn=SER_NETWORK, int nVersionIn=VERSION) : vch(pbegin, pend) + CDataStream(const_iterator pbegin, const_iterator pend, int nTypeIn=SER_NETWORK, int nVersionIn=PROTOCOL_VERSION) : vch(pbegin, pend) { Init(nTypeIn, nVersionIn); } #if !defined(_MSC_VER) || _MSC_VER >= 1300 - CDataStream(const char* pbegin, const char* pend, int nTypeIn=SER_NETWORK, int nVersionIn=VERSION) : vch(pbegin, pend) + CDataStream(const char* pbegin, const char* pend, int nTypeIn=SER_NETWORK, int nVersionIn=PROTOCOL_VERSION) : vch(pbegin, pend) { Init(nTypeIn, nVersionIn); } #endif - CDataStream(const vector_type& vchIn, int nTypeIn=SER_NETWORK, int nVersionIn=VERSION) : vch(vchIn.begin(), vchIn.end()) + CDataStream(const vector_type& vchIn, int nTypeIn=SER_NETWORK, int nVersionIn=PROTOCOL_VERSION) : vch(vchIn.begin(), vchIn.end()) { Init(nTypeIn, nVersionIn); } - CDataStream(const std::vector<char>& vchIn, int nTypeIn=SER_NETWORK, int nVersionIn=VERSION) : vch(vchIn.begin(), vchIn.end()) + CDataStream(const std::vector<char>& vchIn, int nTypeIn=SER_NETWORK, int nVersionIn=PROTOCOL_VERSION) : vch(vchIn.begin(), vchIn.end()) { Init(nTypeIn, nVersionIn); } - CDataStream(const std::vector<unsigned char>& vchIn, int nTypeIn=SER_NETWORK, int nVersionIn=VERSION) : vch((char*)&vchIn.begin()[0], (char*)&vchIn.end()[0]) + CDataStream(const std::vector<unsigned char>& vchIn, int nTypeIn=SER_NETWORK, int nVersionIn=PROTOCOL_VERSION) : vch((char*)&vchIn.begin()[0], (char*)&vchIn.end()[0]) { Init(nTypeIn, nVersionIn); } - void Init(int nTypeIn=SER_NETWORK, int nVersionIn=VERSION) + void Init(int nTypeIn=SER_NETWORK, int nVersionIn=PROTOCOL_VERSION) { nReadPos = 0; nType = nTypeIn; @@ -1103,7 +1101,7 @@ public: } template<typename Stream> - void Serialize(Stream& s, int nType=0, int nVersion=VERSION) const + void Serialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION) const { // Special case: stream << stream concatenates like stream += stream if (!vch.empty()) @@ -1212,7 +1210,7 @@ public: typedef FILE element_type; - CAutoFile(FILE* filenew=NULL, int nTypeIn=SER_DISK, int nVersionIn=VERSION) + CAutoFile(FILE* filenew=NULL, int nTypeIn=SER_DISK, int nVersionIn=PROTOCOL_VERSION) { file = filenew; nType = nTypeIn; diff --git a/src/uint256.h b/src/uint256.h index 3e20201387..b6132822c5 100644 --- a/src/uint256.h +++ b/src/uint256.h @@ -364,19 +364,19 @@ public: } - unsigned int GetSerializeSize(int nType=0, int nVersion=VERSION) const + unsigned int GetSerializeSize(int nType=0, int nVersion=PROTOCOL_VERSION) const { return sizeof(pn); } template<typename Stream> - void Serialize(Stream& s, int nType=0, int nVersion=VERSION) const + void Serialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION) const { s.write((char*)pn, sizeof(pn)); } template<typename Stream> - void Unserialize(Stream& s, int nType=0, int nVersion=VERSION) + void Unserialize(Stream& s, int nType=0, int nVersion=PROTOCOL_VERSION) { s.read((char*)pn, sizeof(pn)); } diff --git a/src/util.cpp b/src/util.cpp index 236c7f7c44..ef276e5103 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -4,6 +4,7 @@ // file license.txt or http://www.opensource.org/licenses/mit-license.php. #include "headers.h" #include "strlcpy.h" +#include <boost/algorithm/string/join.hpp> #include <boost/program_options/detail/config_file.hpp> #include <boost/program_options/parsers.hpp> #include <boost/filesystem.hpp> @@ -1001,7 +1002,7 @@ string FormatVersion(int nVersion) string FormatFullVersion() { - string s = FormatVersion(VERSION) + pszSubVer; + string s = FormatVersion(CLIENT_VERSION); if (VERSION_IS_BETA) { s += "-"; s += _("beta"); @@ -1009,6 +1010,17 @@ string FormatFullVersion() return s; } +// Format the subversion field according to BIP 14 spec (https://en.bitcoin.it/wiki/BIP_0014) +std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments) +{ + std::ostringstream ss; + ss << "/"; + ss << name << ":" << FormatVersion(nClientVersion); + if (!comments.empty()) + ss << "(" << boost::algorithm::join(comments, "; ") << ")"; + ss << "/"; + return ss.str(); +} diff --git a/src/util.h b/src/util.h index 7b7eaf6dbb..d9a0841a61 100644 --- a/src/util.h +++ b/src/util.h @@ -204,7 +204,7 @@ void SetMockTime(int64 nMockTimeIn); int64 GetAdjustedTime(); void AddTimeData(unsigned int ip, int64 nTime); std::string FormatFullVersion(); - +std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments); @@ -558,7 +558,7 @@ inline uint256 Hash(const T1 p1begin, const T1 p1end, } template<typename T> -uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=VERSION) +uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION) { // Most of the time is spent allocating and deallocating CDataStream's // buffer. If this ever needs to be optimized further, make a CStaticStream |