You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

clientversion.cpp 3.7KB

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