|
| 1 | +// Copyright (c) 2012-2016 The Bitcoin Core developers |
| 2 | +// Distributed under the MIT software license, see the accompanying |
| 3 | +// file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 4 | + |
| 5 | +#include "clientversion.h" |
| 6 | + |
| 7 | +#include "tinyformat.h" |
| 8 | + |
| 9 | +#include <string> |
| 10 | + |
| 11 | +/** |
| 12 | + * Name of client reported in the 'version' message. Report the same name |
| 13 | + * for both bitcoind and bitcoin-core, to make it harder for attackers to |
| 14 | + * target servers or GUI users specifically. |
| 15 | + */ |
| 16 | +const std::string CLIENT_NAME("ipchain"); |
| 17 | + |
| 18 | +const std::string IPCHAIN_VERSION("V0.1.2"); |
| 19 | + |
| 20 | +/** |
| 21 | + * Client version number |
| 22 | + */ |
| 23 | +#define CLIENT_VERSION_SUFFIX "" |
| 24 | + |
| 25 | + |
| 26 | +/** |
| 27 | + * The following part of the code determines the CLIENT_BUILD variable. |
| 28 | + * Several mechanisms are used for this: |
| 29 | + * * first, if HAVE_BUILD_INFO is defined, include build.h, a file that is |
| 30 | + * generated by the build environment, possibly containing the output |
| 31 | + * of git-describe in a macro called BUILD_DESC |
| 32 | + * * secondly, if this is an exported version of the code, GIT_ARCHIVE will |
| 33 | + * be defined (automatically using the export-subst git attribute), and |
| 34 | + * GIT_COMMIT will contain the commit id. |
| 35 | + * * then, three options exist for determining CLIENT_BUILD: |
| 36 | + * * if BUILD_DESC is defined, use that literally (output of git-describe) |
| 37 | + * * if not, but GIT_COMMIT is defined, use v[maj].[min].[rev].[build]-g[commit] |
| 38 | + * * otherwise, use v[maj].[min].[rev].[build]-unk |
| 39 | + * finally CLIENT_VERSION_SUFFIX is added |
| 40 | + */ |
| 41 | + |
| 42 | +//! First, include build.h if requested |
| 43 | +#ifdef HAVE_BUILD_INFO |
| 44 | +#include "build.h" |
| 45 | +#endif |
| 46 | + |
| 47 | +//! git will put "#define GIT_ARCHIVE 1" on the next line inside archives. |
| 48 | +#define GIT_ARCHIVE 1 |
| 49 | +#ifdef GIT_ARCHIVE |
| 50 | +#define GIT_COMMIT_ID "964a185cc83" |
| 51 | +#define GIT_COMMIT_DATE "Thu, 20 Apr 2017 11:28:25 +0200" |
| 52 | +#endif |
| 53 | + |
| 54 | +#define BUILD_DESC_WITH_SUFFIX(maj, min, rev, build, suffix) \ |
| 55 | + "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-" DO_STRINGIZE(suffix) |
| 56 | + |
| 57 | +#define BUILD_DESC_FROM_COMMIT(maj, min, rev, build, commit) \ |
| 58 | + "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-g" commit |
| 59 | + |
| 60 | +#define BUILD_DESC_FROM_UNKNOWN(maj, min, rev, build) \ |
| 61 | + "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-unk" |
| 62 | + |
| 63 | +#ifndef BUILD_DESC |
| 64 | +#ifdef BUILD_SUFFIX |
| 65 | +#define BUILD_DESC BUILD_DESC_WITH_SUFFIX(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, BUILD_SUFFIX) |
| 66 | +#elif defined(GIT_COMMIT_ID) |
| 67 | +#define BUILD_DESC BUILD_DESC_FROM_COMMIT(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, GIT_COMMIT_ID) |
| 68 | +#else |
| 69 | +#define BUILD_DESC BUILD_DESC_FROM_UNKNOWN(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD) |
| 70 | +#endif |
| 71 | +#endif |
| 72 | + |
| 73 | +const std::string CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX); |
| 74 | + |
| 75 | +static std::string FormatVersion(int nVersion) |
| 76 | +{ |
| 77 | + if (nVersion % 100 == 0) |
| 78 | + return strprintf("%d.%d.%d", nVersion / 1000000, (nVersion / 10000) % 100, (nVersion / 100) % 100); |
| 79 | + else |
| 80 | + return strprintf("%d.%d.%d.%d", nVersion / 1000000, (nVersion / 10000) % 100, (nVersion / 100) % 100, nVersion % 100); |
| 81 | +} |
| 82 | + |
| 83 | +std::string FormatFullVersion() |
| 84 | +{ |
| 85 | + return CLIENT_BUILD; |
| 86 | +} |
| 87 | + |
| 88 | +/** |
| 89 | + * Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip-0014.mediawiki) |
| 90 | + */ |
| 91 | +std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments) |
| 92 | +{ |
| 93 | + std::ostringstream ss; |
| 94 | + ss << "/"; |
| 95 | + ss << name << ":" << FormatVersion(nClientVersion); |
| 96 | + if (!comments.empty()) |
| 97 | + { |
| 98 | + std::vector<std::string>::const_iterator it(comments.begin()); |
| 99 | + ss << "(" << *it; |
| 100 | + for(++it; it != comments.end(); ++it) |
| 101 | + ss << "; " << *it; |
| 102 | + ss << ")"; |
| 103 | + } |
| 104 | + ss << "/"; |
| 105 | + return ss.str(); |
| 106 | +} |
0 commit comments