From e9e0277b7c7579cc8b2a6f8b848d49e5839e3fac Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Mon, 25 Jan 2016 21:04:15 -0800 Subject: [PATCH] Improve manifest loading --- src/ripple/overlay/impl/Manifest.cpp | 70 +++++++++++++++++++------ src/ripple/overlay/impl/Manifest.h | 5 +- src/ripple/overlay/impl/OverlayImpl.cpp | 26 ++++----- 3 files changed, 68 insertions(+), 33 deletions(-) diff --git a/src/ripple/overlay/impl/Manifest.cpp b/src/ripple/overlay/impl/Manifest.cpp index 1536cbe53..5804ab9eb 100644 --- a/src/ripple/overlay/impl/Manifest.cpp +++ b/src/ripple/overlay/impl/Manifest.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include 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 ("[validator_keys] format is ` "); + JLOG (journal.debug) << + "Loading configured validator keys"; - auto const masterKey = parseBase58( - TokenType::TOKEN_NODE_PUBLIC, words[0]); + std::size_t count = 0; - if (!masterKey) - Throw ("Error decoding validator key"); + for (auto const& line : keys.lines()) + { + boost::smatch match; - if (publicKeyType(*masterKey) != KeyType::ed25519) - Throw ("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( + 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 diff --git a/src/ripple/overlay/impl/Manifest.h b/src/ripple/overlay/impl/Manifest.h index 6bf17bcdd..7335ff861 100644 --- a/src/ripple/overlay/impl/Manifest.h +++ b/src/ripple/overlay/impl/Manifest.h @@ -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); diff --git a/src/ripple/overlay/impl/OverlayImpl.cpp b/src/ripple/overlay/impl/OverlayImpl.cpp index c26de0b55..ab99bff62 100644 --- a/src/ripple/overlay/impl/OverlayImpl.cpp +++ b/src/ripple/overlay/impl/OverlayImpl.cpp @@ -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 ("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 (