mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Improve manifest loading
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
#include <ripple/overlay/impl/Manifest.h>
|
||||
#include <ripple/protocol/PublicKey.h>
|
||||
#include <ripple/protocol/Sign.h>
|
||||
#include <beast/http/rfc2616.h>
|
||||
#include <boost/regex.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace ripple {
|
||||
@@ -127,28 +127,66 @@ Blob Manifest::getSignature () const
|
||||
return st.getFieldVL (sfSignature);
|
||||
}
|
||||
|
||||
void
|
||||
ManifestCache::configValidatorKey(
|
||||
std::string const& line, beast::Journal journal)
|
||||
bool
|
||||
ManifestCache::loadValidatorKeys(
|
||||
Section const& keys,
|
||||
beast::Journal journal)
|
||||
{
|
||||
auto const words = beast::rfc2616::split(line.begin(), line.end(), ' ');
|
||||
static boost::regex const re (
|
||||
"[[:space:]]*" // skip leading whitespace
|
||||
"([[:alnum:]]+)" // node identity
|
||||
"(?:" // begin optional comment block
|
||||
"[[:space:]]+" // (skip all leading whitespace)
|
||||
"(?:" // begin optional comment
|
||||
"(.*[^[:space:]]+)" // the comment
|
||||
"[[:space:]]*" // (skip all trailing whitespace)
|
||||
")?" // end optional comment
|
||||
")?" // end optional comment block
|
||||
);
|
||||
|
||||
if (words.size () != 2)
|
||||
Throw<std::runtime_error> ("[validator_keys] format is `<key> <comment>");
|
||||
JLOG (journal.debug) <<
|
||||
"Loading configured validator keys";
|
||||
|
||||
auto const masterKey = parseBase58<PublicKey>(
|
||||
TokenType::TOKEN_NODE_PUBLIC, words[0]);
|
||||
std::size_t count = 0;
|
||||
|
||||
if (!masterKey)
|
||||
Throw<std::runtime_error> ("Error decoding validator key");
|
||||
for (auto const& line : keys.lines())
|
||||
{
|
||||
boost::smatch match;
|
||||
|
||||
if (publicKeyType(*masterKey) != KeyType::ed25519)
|
||||
Throw<std::runtime_error> ("Validator key must use Ed25519");
|
||||
if (!boost::regex_match (line, match, re))
|
||||
{
|
||||
JLOG (journal.error) <<
|
||||
"Malformed entry: '" << line << "'";
|
||||
return false;
|
||||
}
|
||||
|
||||
JLOG (journal.debug) << "Loaded key: " <<
|
||||
toBase58(TokenType::TOKEN_NODE_PUBLIC, *masterKey);
|
||||
auto const key = parseBase58<PublicKey>(
|
||||
TokenType::TOKEN_NODE_PUBLIC, match[1]);
|
||||
|
||||
addTrustedKey (*masterKey, std::move(words[1]));
|
||||
if (!key)
|
||||
{
|
||||
JLOG (journal.error) <<
|
||||
"Error decoding validator key: " << match[1];
|
||||
return false;
|
||||
}
|
||||
|
||||
if (publicKeyType(*key) != KeyType::ed25519)
|
||||
{
|
||||
JLOG (journal.error) <<
|
||||
"Validator key not using Ed25519: " << match[1];
|
||||
return false;
|
||||
}
|
||||
|
||||
JLOG (journal.debug) << "Loaded key: " << match[1];
|
||||
|
||||
addTrustedKey (*key, match[2]);
|
||||
++count;
|
||||
}
|
||||
|
||||
JLOG (journal.debug) <<
|
||||
"Loaded " << count << " entries";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -162,7 +162,10 @@ public:
|
||||
ManifestCache& operator= (ManifestCache const&) = delete;
|
||||
~ManifestCache() = default;
|
||||
|
||||
void configValidatorKey(std::string const& line, beast::Journal journal);
|
||||
bool loadValidatorKeys(
|
||||
Section const& keys,
|
||||
beast::Journal journal);
|
||||
|
||||
void configManifest (Manifest m, ValidatorList& unl, beast::Journal journal);
|
||||
|
||||
void addTrustedKey (PublicKey const& pk, std::string comment);
|
||||
|
||||
@@ -437,21 +437,15 @@ void
|
||||
OverlayImpl::setupValidatorKeyManifests (BasicConfig const& config,
|
||||
DatabaseCon& db)
|
||||
{
|
||||
auto const validator_keys = config.section ("validator_keys");
|
||||
auto const validation_manifest = config.section ("validation_manifest");
|
||||
auto const loaded = manifestCache_.loadValidatorKeys (
|
||||
config.section ("validator_keys"),
|
||||
journal_);
|
||||
|
||||
if (! validator_keys.lines().empty())
|
||||
{
|
||||
for (auto const& line : validator_keys.lines())
|
||||
{
|
||||
manifestCache_.configValidatorKey (line, journal_);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (journal_.warning)
|
||||
journal_.warning << "[validator_keys] is empty";
|
||||
}
|
||||
if (!loaded)
|
||||
Throw<std::runtime_error> ("Unable to load validator keys");
|
||||
|
||||
auto const validation_manifest =
|
||||
config.section ("validation_manifest");
|
||||
|
||||
if (! validation_manifest.lines().empty())
|
||||
{
|
||||
@@ -473,8 +467,8 @@ OverlayImpl::setupValidatorKeyManifests (BasicConfig const& config,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (journal_.warning)
|
||||
journal_.warning << "No [validation_manifest] section in config";
|
||||
if (journal_.debug)
|
||||
journal_.debug << "No [validation_manifest] section in config";
|
||||
}
|
||||
|
||||
manifestCache_.load (
|
||||
|
||||
Reference in New Issue
Block a user