rippled
Loading...
Searching...
No Matches
BuildInfo.cpp
1#include <xrpl/basics/contract.h>
2#include <xrpl/beast/core/LexicalCast.h>
3#include <xrpl/beast/core/SemanticVersion.h>
4#include <xrpl/protocol/BuildInfo.h>
5
6#include <boost/preprocessor/stringize.hpp>
7
8#include <algorithm>
9#include <cstdint>
10#include <string>
11#include <string_view>
12
13namespace xrpl {
14
15namespace BuildInfo {
16
17//--------------------------------------------------------------------------
18// The build version number. You must edit this for each release
19// and follow the format described at http://semver.org/
20//------------------------------------------------------------------------------
21// clang-format off
22char const* const versionString = "3.2.0-b0"
23// clang-format on
24
25#if defined(DEBUG) || defined(SANITIZERS)
26 "+"
27#ifdef GIT_COMMIT_HASH
28 GIT_COMMIT_HASH
29 "."
30#endif
31#ifdef DEBUG
32 "DEBUG"
33#ifdef SANITIZERS
34 "."
35#endif
36#endif
37
38#ifdef SANITIZERS
39 BOOST_PP_STRINGIZE(SANITIZERS) // cspell: disable-line
40#endif
41#endif
42
43 //--------------------------------------------------------------------------
44 ;
45
46//
47// Don't touch anything below this line
48//
49
50std::string const&
52{
53 static std::string const value = [] {
54 std::string const s = versionString;
56 if (!v.parse(s) || v.print() != s)
57 LogicError(s + ": Bad server version string");
58 return s;
59 }();
60 return value;
61}
62
63std::string const&
65{
66 static std::string const value = "rippled-" + getVersionString();
67 return value;
68}
69
70static constexpr std::uint64_t implementationVersionIdentifier = 0x183B'0000'0000'0000LLU;
71static constexpr std::uint64_t implementationVersionIdentifierMask = 0xFFFF'0000'0000'0000LLU;
72
74encodeSoftwareVersion(char const* const versionStr)
75{
77
79
80 if (v.parse(std::string(versionStr)))
81 {
82 if (v.majorVersion >= 0 && v.majorVersion <= 255)
83 c |= static_cast<std::uint64_t>(v.majorVersion) << 40;
84
85 if (v.minorVersion >= 0 && v.minorVersion <= 255)
86 c |= static_cast<std::uint64_t>(v.minorVersion) << 32;
87
88 if (v.patchVersion >= 0 && v.patchVersion <= 255)
89 c |= static_cast<std::uint64_t>(v.patchVersion) << 24;
90
91 if (!v.isPreRelease())
92 c |= static_cast<std::uint64_t>(0xC00000);
93
94 if (v.isPreRelease())
95 {
96 std::uint8_t x = 0;
97
98 for (auto id : v.preReleaseIdentifiers)
99 {
100 auto parsePreRelease = [](std::string_view identifier,
101 std::string_view prefix,
102 std::uint8_t key,
103 std::uint8_t lok,
104 std::uint8_t hik) -> std::uint8_t {
105 std::uint8_t ret = 0;
106
107 if (prefix != identifier.substr(0, prefix.length()))
108 return 0;
109
110 if (!beast::lexicalCastChecked(ret, std::string(identifier.substr(prefix.length()))))
111 return 0;
112
113 if (std::clamp(ret, lok, hik) != ret)
114 return 0;
115
116 return ret + key;
117 };
118
119 x = parsePreRelease(id, "rc", 0x80, 0, 63);
120
121 if (x == 0)
122 x = parsePreRelease(id, "b", 0x40, 0, 63);
123
124 if (x & 0xC0)
125 {
126 c |= static_cast<std::uint64_t>(x) << 16;
127 break;
128 }
129 }
130 }
131 }
132
133 return c;
134}
135
138{
139 static std::uint64_t const cookie = {encodeSoftwareVersion(versionString)};
140 return cookie;
141}
142
143bool
148
149bool
151{
152 if (isRippledVersion(version))
153 return version > getEncodedVersion();
154 return false;
155}
156
157} // namespace BuildInfo
158
159} // namespace xrpl
T clamp(T... args)
A Semantic Version number.
bool parse(std::string const &input)
Parse a semantic version string.
identifier_list preReleaseIdentifiers
bool isPreRelease() const noexcept
std::string print() const
Produce a string from semantic version components.
bool lexicalCastChecked(Out &out, In in)
Intelligently convert from one type to another.
std::string const & getFullVersionString()
Full server version string.
Definition BuildInfo.cpp:64
static constexpr std::uint64_t implementationVersionIdentifierMask
Definition BuildInfo.cpp:71
std::uint64_t getEncodedVersion()
Returns this server's version packed in a 64-bit integer.
bool isNewerVersion(std::uint64_t version)
Check if the version is newer than the local node's rippled software version.
static constexpr std::uint64_t implementationVersionIdentifier
Definition BuildInfo.cpp:70
bool isRippledVersion(std::uint64_t version)
Check if the encoded software version is a rippled software version.
std::uint64_t encodeSoftwareVersion(char const *const versionStr)
Encode an arbitrary server software version in a 64-bit integer.
Definition BuildInfo.cpp:74
std::string const & getVersionString()
Server version.
Definition BuildInfo.cpp:51
char const *const versionString
Definition BuildInfo.cpp:22
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
T substr(T... args)