rippled
Loading...
Searching...
No Matches
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 <xrpl/basics/contract.h>
21#include <xrpl/beast/core/LexicalCast.h>
22#include <xrpl/beast/core/SemanticVersion.h>
23#include <xrpl/protocol/BuildInfo.h>
24
25#include <algorithm>
26#include <cstdint>
27#include <string>
28#include <string_view>
29
30namespace ripple {
31
32namespace BuildInfo {
33
34//--------------------------------------------------------------------------
35// The build version number. You must edit this for each release
36// and follow the format described at http://semver.org/
37//------------------------------------------------------------------------------
38// clang-format off
39char const* const versionString = "3.0.0-b1"
40// clang-format on
41
42#if defined(DEBUG) || defined(SANITIZER)
43 "+"
44#ifdef GIT_COMMIT_HASH
45 GIT_COMMIT_HASH
46 "."
47#endif
48#ifdef DEBUG
49 "DEBUG"
50#ifdef SANITIZER
51 "."
52#endif
53#endif
54
55#ifdef SANITIZER
56 BOOST_PP_STRINGIZE(SANITIZER)
57#endif
58#endif
59
60 //--------------------------------------------------------------------------
61 ;
62
63//
64// Don't touch anything below this line
65//
66
67std::string const&
69{
70 static std::string const value = [] {
71 std::string const s = versionString;
73 if (!v.parse(s) || v.print() != s)
74 LogicError(s + ": Bad server version string");
75 return s;
76 }();
77 return value;
78}
79
80std::string const&
82{
83 static std::string const value = "rippled-" + getVersionString();
84 return value;
85}
86
88 0x183B'0000'0000'0000LLU;
90 0xFFFF'0000'0000'0000LLU;
91
93encodeSoftwareVersion(char const* const versionStr)
94{
96
98
99 if (v.parse(std::string(versionStr)))
100 {
101 if (v.majorVersion >= 0 && v.majorVersion <= 255)
102 c |= static_cast<std::uint64_t>(v.majorVersion) << 40;
103
104 if (v.minorVersion >= 0 && v.minorVersion <= 255)
105 c |= static_cast<std::uint64_t>(v.minorVersion) << 32;
106
107 if (v.patchVersion >= 0 && v.patchVersion <= 255)
108 c |= static_cast<std::uint64_t>(v.patchVersion) << 24;
109
110 if (!v.isPreRelease())
111 c |= static_cast<std::uint64_t>(0xC00000);
112
113 if (v.isPreRelease())
114 {
115 std::uint8_t x = 0;
116
117 for (auto id : v.preReleaseIdentifiers)
118 {
119 auto parsePreRelease = [](std::string_view identifier,
120 std::string_view prefix,
121 std::uint8_t key,
122 std::uint8_t lok,
123 std::uint8_t hik) -> std::uint8_t {
124 std::uint8_t ret = 0;
125
126 if (prefix != identifier.substr(0, prefix.length()))
127 return 0;
128
130 ret,
131 std::string(identifier.substr(prefix.length()))))
132 return 0;
133
134 if (std::clamp(ret, lok, hik) != ret)
135 return 0;
136
137 return ret + key;
138 };
139
140 x = parsePreRelease(id, "rc", 0x80, 0, 63);
141
142 if (x == 0)
143 x = parsePreRelease(id, "b", 0x40, 0, 63);
144
145 if (x & 0xC0)
146 {
147 c |= static_cast<std::uint64_t>(x) << 16;
148 break;
149 }
150 }
151 }
152 }
153
154 return c;
155}
156
159{
160 static std::uint64_t const cookie = {encodeSoftwareVersion(versionString)};
161 return cookie;
162}
163
164bool
170
171bool
173{
174 if (isRippledVersion(version))
175 return version > getEncodedVersion();
176 return false;
177}
178
179} // namespace BuildInfo
180
181} // 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:81
std::uint64_t encodeSoftwareVersion(char const *const versionStr)
Encode an arbitrary server software version in a 64-bit integer.
Definition BuildInfo.cpp:93
static constexpr std::uint64_t implementationVersionIdentifier
Definition BuildInfo.cpp:87
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:89
std::string const & getVersionString()
Server version.
Definition BuildInfo.cpp:68
char const *const versionString
Definition BuildInfo.cpp:39
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
void LogicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
T substr(T... args)