rippled
BuildInfo.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/basics/contract.h>
21 #include <ripple/beast/core/LexicalCast.h>
22 #include <ripple/beast/core/SemanticVersion.h>
23 #include <ripple/protocol/BuildInfo.h>
24 #include <boost/preprocessor/stringize.hpp>
25 #include <algorithm>
26 
27 namespace ripple {
28 
29 namespace BuildInfo {
30 
31 //--------------------------------------------------------------------------
32 // The build version number. You must edit this for each release
33 // and follow the format described at http://semver.org/
34 //------------------------------------------------------------------------------
35 // clang-format off
36 char const* const versionString = "1.6.0-b5"
37 // clang-format on
38 
39 #if defined(DEBUG) || defined(SANITIZER)
40  "+"
41 #ifdef DEBUG
42  "DEBUG"
43 #ifdef SANITIZER
44  "."
45 #endif
46 #endif
47 
48 #ifdef SANITIZER
49  BOOST_PP_STRINGIZE(SANITIZER)
50 #endif
51 #endif
52 
53  //--------------------------------------------------------------------------
54  ;
55 
56 //
57 // Don't touch anything below this line
58 //
59 
60 std::string const&
62 {
63  static std::string const value = [] {
64  std::string const s = versionString;
66  if (!v.parse(s) || v.print() != s)
67  LogicError(s + ": Bad server version string");
68  return s;
69  }();
70  return value;
71 }
72 
73 std::string const&
75 {
76  static std::string const value = "rippled-" + getVersionString();
77  return value;
78 }
79 
82 {
83  static std::uint64_t const cookie = []() {
84  std::uint64_t c = 0x183B000000000000;
85 
87 
88  if (v.parse(versionString))
89  {
90  if (v.majorVersion >= 0 && v.majorVersion <= 255)
91  c |= static_cast<std::uint64_t>(v.majorVersion) << 40;
92 
93  if (v.minorVersion >= 0 && v.minorVersion <= 255)
94  c |= static_cast<std::uint64_t>(v.minorVersion) << 32;
95 
96  if (v.patchVersion >= 0 && v.patchVersion <= 255)
97  c |= static_cast<std::uint64_t>(v.patchVersion) << 24;
98 
99  if (!v.isPreRelease())
100  c |= static_cast<std::uint64_t>(0xC00000);
101 
102  if (v.isPreRelease())
103  {
104  std::uint8_t x = 0;
105 
106  for (auto id : v.preReleaseIdentifiers)
107  {
108  auto parsePreRelease =
109  [](std::string_view identifier,
110  std::string_view prefix,
111  std::uint8_t key,
112  std::uint8_t lok,
113  std::uint8_t hik) -> std::uint8_t {
114  std::uint8_t ret = 0;
115 
116  if (prefix != identifier.substr(0, prefix.length()))
117  return 0;
118 
120  ret,
121  std::string(
122  identifier.substr(prefix.length()))))
123  return 0;
124 
125  if (std::clamp(ret, lok, hik) != ret)
126  return 0;
127 
128  return ret + key;
129  };
130 
131  x = parsePreRelease(id, "rc", 0x80, 0, 63);
132 
133  if (x == 0)
134  x = parsePreRelease(id, "b", 0x40, 0, 63);
135 
136  if (x & 0xC0)
137  {
138  c |= static_cast<std::uint64_t>(x) << 16;
139  break;
140  }
141  }
142  }
143  }
144 
145  return c;
146  }();
147 
148  return cookie;
149 }
150 
151 } // namespace BuildInfo
152 
153 } // namespace ripple
std::string
STL class.
std::string_view
STL class.
ripple::BuildInfo::getEncodedVersion
std::uint64_t getEncodedVersion()
Returns the server version packed in a 64-bit integer.
Definition: BuildInfo.cpp:81
beast::SemanticVersion::print
std::string print() const
Produce a string from semantic version components.
Definition: SemanticVersion.cpp:236
beast::SemanticVersion::isPreRelease
bool isPreRelease() const noexcept
Definition: SemanticVersion.h:68
beast::SemanticVersion
A Semantic Version number.
Definition: SemanticVersion.h:35
algorithm
beast::SemanticVersion::minorVersion
int minorVersion
Definition: SemanticVersion.h:41
beast::SemanticVersion::preReleaseIdentifiers
identifier_list preReleaseIdentifiers
Definition: SemanticVersion.h:44
ripple::BuildInfo::getVersionString
std::string const & getVersionString()
Server version.
Definition: BuildInfo.cpp:61
std::uint64_t
beast::SemanticVersion::majorVersion
int majorVersion
Definition: SemanticVersion.h:40
std::string_view::substr
T substr(T... args)
ripple::BuildInfo::getFullVersionString
std::string const & getFullVersionString()
Full server version string.
Definition: BuildInfo.cpp:74
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
beast::SemanticVersion::parse
bool parse(std::string const &input)
Parse a semantic version string.
Definition: SemanticVersion.cpp:168
std::clamp
T clamp(T... args)
ripple::BuildInfo::versionString
char const *const versionString
Definition: BuildInfo.cpp:36
beast::lexicalCastChecked
bool lexicalCastChecked(Out &out, In in)
Intelligently convert from one type to another.
Definition: LexicalCast.h:266
ripple::LogicError
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
Definition: contract.cpp:48
beast::SemanticVersion::patchVersion
int patchVersion
Definition: SemanticVersion.h:42