mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-22 03:55:53 +00:00
Report the server version in published validations:
Currently there is no mechanism for a validator to report the
version of the software it is currently running. Such reports
can be useful for those who are developing network monitoring
dashboards and server operators in general.
This commit, if merged, defines an encoding scheme to encode
a version string into a 64-bit unsigned integer and adds an
additional optional field to validations.
This commit piggybacks on "HardenedValidations" amendment to
determine whether version information should be propagated
or not.
The general encoding scheme is:
XXXXXXXX-XXXXXXXX-YYYYYYYY-YYYYYYYY-YYYYYYYY-YYYYYYYY-YYYYYYYY-YYYYYYYY
X: 16 bits identifying the particular implementation
Y: 48 bits of data specific to the implementation
The rippled-specific format (implementation ID is: 0x18 0x3B) is:
00011000-00111011-MMMMMMMM-mmmmmmmm-pppppppp-TTNNNNNN-00000000-00000000
M: 8-bit major version (0-255)
m: 8-bit minor version (0-255)
p: 8-bit patch version (0-255)
T: 11 if neither an RC nor a beta
10 if an RC
01 if a beta
N: 6-bit rc/beta number (1-63)
This commit is contained in:
@@ -18,10 +18,11 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/beast/core/LexicalCast.h>
|
||||
#include <ripple/beast/core/SemanticVersion.h>
|
||||
#include <ripple/protocol/BuildInfo.h>
|
||||
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -76,6 +77,77 @@ getFullVersionString()
|
||||
return value;
|
||||
}
|
||||
|
||||
std::uint64_t
|
||||
getEncodedVersion()
|
||||
{
|
||||
static std::uint64_t const cookie = []() {
|
||||
std::uint64_t c = 0x183B000000000000;
|
||||
|
||||
beast::SemanticVersion v;
|
||||
|
||||
if (v.parse(versionString))
|
||||
{
|
||||
if (v.majorVersion >= 0 && v.majorVersion <= 255)
|
||||
c |= static_cast<std::uint64_t>(v.majorVersion) << 40;
|
||||
|
||||
if (v.minorVersion >= 0 && v.minorVersion <= 255)
|
||||
c |= static_cast<std::uint64_t>(v.minorVersion) << 32;
|
||||
|
||||
if (v.patchVersion >= 0 && v.patchVersion <= 255)
|
||||
c |= static_cast<std::uint64_t>(v.patchVersion) << 24;
|
||||
|
||||
if (!v.isPreRelease())
|
||||
c |= static_cast<std::uint64_t>(0xC00000);
|
||||
|
||||
if (v.isPreRelease())
|
||||
{
|
||||
std::uint8_t x = 0;
|
||||
|
||||
for (auto id : v.preReleaseIdentifiers)
|
||||
{
|
||||
auto parsePreRelease =
|
||||
[](std::string_view identifier,
|
||||
std::string_view prefix,
|
||||
std::uint8_t key,
|
||||
std::uint8_t lok,
|
||||
std::uint8_t hik) -> std::uint8_t {
|
||||
std::uint8_t ret = 0;
|
||||
|
||||
if (prefix != identifier.substr(0, prefix.length()))
|
||||
return 0;
|
||||
|
||||
if (!beast::lexicalCastChecked(
|
||||
ret,
|
||||
std::string(
|
||||
identifier.substr(prefix.length()))))
|
||||
return 0;
|
||||
|
||||
if (std::clamp(ret, lok, hik) != ret)
|
||||
return 0;
|
||||
|
||||
return ret + key;
|
||||
};
|
||||
|
||||
x = parsePreRelease(id, "rc", 0x80, 0, 63);
|
||||
|
||||
if (x == 0)
|
||||
x = parsePreRelease(id, "b", 0x40, 0, 63);
|
||||
|
||||
if (x & 0xC0)
|
||||
{
|
||||
c |= static_cast<std::uint64_t>(x) << 16;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}();
|
||||
|
||||
return cookie;
|
||||
}
|
||||
|
||||
} // namespace BuildInfo
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
Reference in New Issue
Block a user