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 <algorithm>
7#include <cstdint>
8#include <string>
9#include <string_view>
10
11namespace ripple {
12
13namespace BuildInfo {
14
15//--------------------------------------------------------------------------
16// The build version number. You must edit this for each release
17// and follow the format described at http://semver.org/
18//------------------------------------------------------------------------------
19// clang-format off
20char const* const versionString = "3.1.0-b0"
21// clang-format on
22
23#if defined(DEBUG) || defined(SANITIZER)
24 "+"
25#ifdef GIT_COMMIT_HASH
26 GIT_COMMIT_HASH
27 "."
28#endif
29#ifdef DEBUG
30 "DEBUG"
31#ifdef SANITIZER
32 "."
33#endif
34#endif
35
36#ifdef SANITIZER
37 BOOST_PP_STRINGIZE(SANITIZER)
38#endif
39#endif
40
41 //--------------------------------------------------------------------------
42 ;
43
44//
45// Don't touch anything below this line
46//
47
48std::string const&
50{
51 static std::string const value = [] {
52 std::string const s = versionString;
54 if (!v.parse(s) || v.print() != s)
55 LogicError(s + ": Bad server version string");
56 return s;
57 }();
58 return value;
59}
60
61std::string const&
63{
64 static std::string const value = "rippled-" + getVersionString();
65 return value;
66}
67
69 0x183B'0000'0000'0000LLU;
71 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
111 ret,
112 std::string(identifier.substr(prefix.length()))))
113 return 0;
114
115 if (std::clamp(ret, lok, hik) != ret)
116 return 0;
117
118 return ret + key;
119 };
120
121 x = parsePreRelease(id, "rc", 0x80, 0, 63);
122
123 if (x == 0)
124 x = parsePreRelease(id, "b", 0x40, 0, 63);
125
126 if (x & 0xC0)
127 {
128 c |= static_cast<std::uint64_t>(x) << 16;
129 break;
130 }
131 }
132 }
133 }
134
135 return c;
136}
137
140{
141 static std::uint64_t const cookie = {encodeSoftwareVersion(versionString)};
142 return cookie;
143}
144
145bool
151
152bool
154{
155 if (isRippledVersion(version))
156 return version > getEncodedVersion();
157 return false;
158}
159
160} // namespace BuildInfo
161
162} // namespace ripple
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::uint64_t getEncodedVersion()
Returns this server's version packed in a 64-bit integer.
std::string const & getFullVersionString()
Full server version string.
Definition BuildInfo.cpp:62
std::uint64_t encodeSoftwareVersion(char const *const versionStr)
Encode an arbitrary server software version in a 64-bit integer.
Definition BuildInfo.cpp:74
static constexpr std::uint64_t implementationVersionIdentifier
Definition BuildInfo.cpp:68
bool isNewerVersion(std::uint64_t version)
Check if the version is newer than the local node's rippled software version.
bool isRippledVersion(std::uint64_t version)
Check if the encoded software version is a rippled software version.
static constexpr std::uint64_t implementationVersionIdentifierMask
Definition BuildInfo.cpp:70
std::string const & getVersionString()
Server version.
Definition BuildInfo.cpp:49
char const *const versionString
Definition BuildInfo.cpp:20
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)