1#include <xrpld/app/misc/HashRouter.h>
2#include <xrpld/app/misc/NetworkOPs.h>
3#include <xrpld/app/misc/ValidatorList.h>
4#include <xrpld/overlay/Overlay.h>
6#include <xrpl/basics/FileUtilities.h>
7#include <xrpl/basics/Slice.h>
8#include <xrpl/basics/StringUtilities.h>
9#include <xrpl/basics/base64.h>
10#include <xrpl/json/json_reader.h>
11#include <xrpl/protocol/PublicKey.h>
12#include <xrpl/protocol/STValidation.h>
13#include <xrpl/protocol/digest.h>
14#include <xrpl/protocol/jss.h>
15#include <xrpl/protocol/messages.h>
17#include <boost/regex.hpp>
35 return "same_sequence";
39 return "known_sequence";
41 return "unsupported_version";
62 : publisherKey(key), status(stat), sequence(seq)
71 : dispositions.begin()->first;
78 : dispositions.rbegin()->first;
87 dispositions[disp] +=
count;
95 : message(message_), hash(hash_), numVLs(num_)
113 ,
quorum_(minimumQuorum.value_or(1))
126 static boost::regex
const re(
141 <<
"Loading configured trusted validator list publisher keys";
144 for (
auto key : publisherKeys)
146 JLOG(
j_.
trace()) <<
"Processing '" << key <<
"'";
152 JLOG(
j_.
error()) <<
"Invalid validator list publisher key: " << key;
162 <<
"Configured validator list publisher key is revoked: "
170 <<
"Duplicate validator list publisher key: " << key;
184 "ripple::ValidatorList::load : list threshold inside range");
185 JLOG(
j_.
debug()) <<
"Validator list threshold set in configuration to "
194 JLOG(
j_.
debug()) <<
"Validator list threshold computed as "
208 auto const [_, inserted] =
212 JLOG(
j_.
debug()) <<
"Added own master key "
217 JLOG(
j_.
debug()) <<
"Loading configured validator keys";
220 for (
auto const& n : configKeys)
222 JLOG(
j_.
trace()) <<
"Processing '" << n <<
"'";
226 if (!boost::regex_match(n,
match, re))
228 JLOG(
j_.
error()) <<
"Malformed entry: '" << n <<
"'";
237 JLOG(
j_.
error()) <<
"Invalid node identity: " <<
match[1];
248 JLOG(
j_.
warn()) <<
"Duplicate node identity: " <<
match[1];
266boost::filesystem::path
296 "ripple::ValidatorList::buildFileData : valid publisher list input");
297 auto const effectiveVersion =
298 forceVersion ? *forceVersion : pubCollection.
rawVersion;
301 value[jss::version] = effectiveVersion;
302 value[jss::public_key] = pubKey;
304 switch (effectiveVersion)
308 value[jss::blob] =
current.rawBlob;
309 value[jss::signature] =
current.rawSignature;
314 value[jss::manifest] = *
current.rawManifest;
320 auto add = [&blobs, &outerManifest = pubCollection.
rawManifest](
323 blob[jss::blob] = pubList.rawBlob;
324 blob[jss::signature] = pubList.rawSignature;
325 if (pubList.rawManifest &&
326 *pubList.rawManifest != outerManifest)
327 blob[jss::manifest] = *pubList.rawManifest;
337 value[jss::blobs_v2] = std::move(blobs);
342 <<
"Invalid VL version provided: " << effectiveVersion;
359 boost::system::error_code ec;
367 value[jss::refresh_interval] = 24 * 60;
374 JLOG(
j_.
error()) <<
"Problem writing " << filename <<
" " << ec.value()
375 <<
": " << ec.message();
398 "ripple::ValidatorList::parseBlobs : single element result");
407 if (!body.
isMember(jss::blobs_v2) ||
408 !body[jss::blobs_v2].
isArray() ||
413 auto const& blobs = body[jss::blobs_v2];
415 for (
auto const& blobInfo : blobs)
417 if (!blobInfo.isObject() ||
418 !blobInfo.isMember(jss::signature) ||
419 !blobInfo[jss::signature].isString() ||
420 !blobInfo.isMember(jss::blob) ||
421 !blobInfo[jss::blob].isString())
424 info.
blob = blobInfo[jss::blob].asString();
425 info.
signature = blobInfo[jss::signature].asString();
426 if (blobInfo.isMember(jss::manifest))
428 if (!blobInfo[jss::manifest].isString())
430 info.
manifest = blobInfo[jss::manifest].asString();
434 result.
size() == blobs.size(),
435 "ripple::ValidatorList::parseBlobs(version, Jason::Value) : "
436 "result size matches");
446 return {{body.blob(), body.signature(), {}}};
456 result.
reserve(body.blobs_size());
457 for (
auto const& blob : body.blobs())
460 info.
blob = blob.blob();
462 if (blob.has_manifest())
468 result.
size() == body.blobs_size(),
469 "ripple::ValidatorList::parseBlobs(TMValidatorList) : result size "
477 protocol::TMValidatorListCollection
const& largeMsg,
485 protocol::TMValidatorListCollection
const& largeMsg,
490 if (begin == 0 && end == 0)
491 end = largeMsg.blobs_size();
492 XRPL_ASSERT(begin < end,
"ripple::splitMessage : valid inputs");
496 auto mid = (begin + end) / 2;
506 protocol::TMValidatorListCollection
const& largeMsg,
513 if (end - begin == 1)
515 protocol::TMValidatorList smallMsg;
516 smallMsg.set_version(1);
517 smallMsg.set_manifest(largeMsg.manifest());
519 auto const& blob = largeMsg.blobs(begin);
520 smallMsg.set_blob(blob.blob());
521 smallMsg.set_signature(blob.signature());
523 if (blob.has_manifest())
524 smallMsg.set_manifest(blob.manifest());
528 "ripple::splitMessageParts : maximum message size");
534 return messages.
back().numVLs;
540 smallMsg->set_version(largeMsg.version());
541 smallMsg->set_manifest(largeMsg.manifest());
545 *smallMsg->add_blobs() = largeMsg.blobs(i);
552 return splitMessage(messages, largeMsg, maxSize, begin, end);
558 *smallMsg, protocol::mtVALIDATORLISTCOLLECTION),
560 smallMsg->blobs_size());
561 return messages.
back().numVLs;
578 "ripple::buildValidatorListMessage(ValidatorBlobInfo) : empty messages "
580 protocol::TMValidatorList msg;
583 auto const version = 1;
585 msg.set_blob(currentBlob.
blob);
586 msg.set_signature(currentBlob.
signature);
588 msg.set_version(version);
592 "ripple::buildValidatorListMessage(ValidatorBlobInfo) : maximum "
614 "ripple::buildValidatorListMessage(std::map<std::size_t, "
615 "ValidatorBlobInfo>) : empty messages input");
616 protocol::TMValidatorListCollection msg;
617 auto const version = rawVersion < 2 ? 2 : rawVersion;
618 msg.set_version(version);
619 msg.set_manifest(rawManifest);
621 for (
auto const& [sequence, blobInfo] : blobInfos)
623 if (sequence <= peerSequence)
625 protocol::ValidatorBlobInfo& blob = *msg.add_blobs();
626 blob.set_blob(blobInfo.blob);
627 blob.set_signature(blobInfo.signature);
628 if (blobInfo.manifest)
629 blob.set_manifest(*blobInfo.manifest);
632 msg.blobs_size() > 0,
633 "ripple::buildValidatorListMessage(std::map<std::size_t, "
634 "ValidatorBlobInfo>) : minimum message blobs");
646 return messages.
back().numVLs;
665 "ripple::ValidatorList::buildValidatorListMessages : empty messages "
667 auto const& [currentSeq, currentBlob] = *blobInfos.
begin();
673 return total + m.numVLs;
675 if (messageVersion == 2 && peerSequence < maxSequence)
678 if (messages.
empty())
687 if (messages.
empty())
694 return {maxSequence, numVLs};
696 else if (messageVersion == 1 && peerSequence < currentSeq)
699 if (messages.
empty())
704 currentBlob.manifest ? *currentBlob.manifest : rawManifest,
707 if (messages.
empty())
714 return {currentSeq, numVLs};
751 "ripple::ValidatorList::sendValidatorList : non-empty messages "
757 for (
auto const& message : messages)
761 peer.
send(message.message);
769 sent || messages.
size() == 1,
770 "ripple::ValidatorList::sendValidatorList : sent or one message");
773 if (messageVersion > 1)
775 <<
"Sent " << messages.
size()
776 <<
" validator list collection(s) containing " << numVLs
777 <<
" validator list(s) for " <<
strHex(publisherKey)
778 <<
" with sequence range " << peerSequence <<
", "
779 << newPeerSequence <<
" to " << peer.
fingerprint();
784 "ripple::ValidatorList::sendValidatorList : one validator "
787 <<
"Sent validator list for " <<
strHex(publisherKey)
788 <<
" with sequence " << newPeerSequence <<
" to "
830 blobInfos[
current.sequence] = {
832 for (
auto const& [sequence, vl] : remaining)
834 blobInfos[sequence] = {vl.rawBlob, vl.rawSignature, vl.rawManifest};
882 "ripple::ValidatorList::broadcastBlobs : valid sequence");
887 if (toSkip->count(peer->id()) == 0)
889 auto const peerSequence =
890 peer->publisherListSequence(publisherKey).value_or(0);
891 if (peerSequence < maxSequence)
893 if (blobInfos.
empty())
895 auto const v2 = peer->supportsFeature(
905 v2 ? messages2[peerSequence] : messages1,
910 hashRouter.addSuppressionPeer(hash, peer->id());
930 auto const disposition = result.bestDisposition();
957 result.publisherKey &&
963 *result.publisherKey,
965 *pubCollection.maxSequence,
992 for (
auto const& blobInfo : blobs)
1008 stats.mergeDispositions(result);
1009 result = std::move(stats);
1021 auto& remaining = pubCollection.remaining;
1022 auto const&
current = pubCollection.current;
1023 for (
auto iter = remaining.begin(); iter != remaining.end();)
1027 next == remaining.end() || next->first > iter->first,
1028 "ripple::ValidatorList::applyLists : next is valid");
1029 if (iter->first <=
current.sequence ||
1030 (next != remaining.end() &&
1031 next->second.validFrom <= iter->second.validFrom))
1033 iter = remaining.erase(iter);
1043 pubCollection.fullHash =
sha512Half(pubCollection);
1045 result.
sequence = *pubCollection.maxSequence;
1061 auto iNew = publisherList.
begin();
1062 auto iOld = oldList.
begin();
1063 while (iNew != publisherList.
end() || iOld != oldList.
end())
1065 if (iOld == oldList.
end() ||
1066 (iNew != publisherList.
end() && *iNew < *iOld))
1073 iNew == publisherList.
end() ||
1074 (iOld != oldList.
end() && *iOld < *iNew))
1090 if (publisherList.
empty())
1092 JLOG(
j_.
warn()) <<
"No validator keys included in valid list";
1095 for (
auto const& valManifest : manifests)
1102 <<
" contained untrusted validator manifest";
1110 <<
" contained invalid validator manifest";
1126 using namespace std::string_literals;
1129 auto const&
manifest = localManifest ? *localManifest : globalManifest;
1133 JLOG(
j_.
warn()) <<
"UNL manifest cannot be deserialized";
1137 auto [result, pubKeyOpt] =
1138 verify(lock, list, std::move(*m), blob, signature);
1143 <<
"UNL manifest is signed with an unrecognized master public key";
1155 "ripple::ValidatorList::applyList : invalid public key type");
1166 if (pubCollection.maxSequence &&
1175 pubCollection.status,
1176 *pubCollection.maxSequence};
1184 auto const sequence = list[jss::sequence].
asUInt();
1193 pubCollection.rawManifest = globalManifest;
1194 if (!pubCollection.maxSequence || sequence > *pubCollection.maxSequence)
1195 pubCollection.maxSequence = sequence;
1197 Json::Value const& newList = list[jss::validators];
1199 if (
accepted && pubCollection.remaining.count(sequence) != 0)
1206 auto& publisher = pubCollection.current;
1208 oldList = std::move(pubCollection.current.list);
1210 publisher = std::move(pubCollection.remaining[sequence]);
1212 pubCollection.remaining.erase(sequence);
1215 publisher.sequence == sequence,
1216 "ripple::ValidatorList::applyList : publisher sequence match");
1220 auto& publisher =
accepted ? pubCollection.current
1221 : pubCollection.remaining[sequence];
1222 publisher.sequence = sequence;
1224 list.
isMember(jss::effective) ? list[jss::effective].
asUInt() : 0}};
1227 publisher.siteUri = std::move(siteUri);
1228 publisher.rawBlob = blob;
1229 publisher.rawSignature = signature;
1230 publisher.rawManifest = localManifest;
1232 publisher.hash = *hash;
1238 oldList = std::move(publisherList);
1240 publisherList.
clear();
1242 for (
auto const& val : newList)
1244 if (val.isObject() && val.isMember(jss::validation_public_key) &&
1245 val[jss::validation_public_key].isString())
1248 strUnHex(val[jss::validation_public_key].asString());
1253 <<
"Invalid node identity: "
1254 << val[jss::validation_public_key].asString();
1262 if (val.isMember(jss::manifest) &&
1263 val[jss::manifest].isString())
1264 manifests.
push_back(val[jss::manifest].asString());
1273 pubCollection.rawVersion =
std::max(pubCollection.rawVersion, version);
1274 if (!pubCollection.remaining.empty())
1278 pubCollection.rawVersion =
std::max(pubCollection.rawVersion, 2u);
1282 result, pubKey, pubCollection.status, *pubCollection.maxSequence};
1295 using namespace std::string_literals;
1296 using namespace boost::filesystem;
1297 using namespace boost::system::errc;
1305 boost::system::error_code ec;
1312 auto const fullPath{
canonical(filename, ec)};
1316 auto size = file_size(fullPath, ec);
1329 return fullPath.root_path() ==
"/"s ?
"file://" :
"file:///";
1375 auto const sig =
strUnHex(signature);
1381 if (!r.
parse(data, list))
1384 if (list.
isMember(jss::sequence) && list[jss::sequence].
isInt() &&
1385 list.
isMember(jss::expiration) && list[jss::expiration].
isInt() &&
1386 (!list.
isMember(jss::effective) || list[jss::effective].
isInt()) &&
1389 auto const sequence = list[jss::sequence].
asUInt();
1391 list.
isMember(jss::effective) ? list[jss::effective].
asUInt() : 0}};
1396 if (validUntil <= validFrom)
1398 else if (sequence < listCollection.current.sequence)
1400 else if (sequence == listCollection.current.sequence)
1402 else if (validUntil <= now)
1404 else if (validFrom > now)
1415 return !listCollection.maxSequence ||
1416 sequence > *listCollection.maxSequence ||
1417 (listCollection.remaining.count(sequence) == 0 &&
1418 validFrom < listCollection.remaining
1419 .at(*listCollection.maxSequence)
1454 return trusted(read_lock, identity);
1511 "ripple::ValidatorList::removePublisherList : valid reason input");
1516 JLOG(
j_.
debug()) <<
"Removing validator list for publisher "
1519 for (
auto const& val : iList->second.current.list)
1525 if (iVal->second <= 1)
1531 iList->second.current.list.clear();
1532 iList->second.status = reason;
1547 return count(read_lock);
1557 auto const&
current = collection.current;
1566 auto chainedExpiration =
current.validUntil;
1567 for (
auto const& [sequence, check] : collection.remaining)
1570 if (check.validFrom <= chainedExpiration)
1571 chainedExpiration = check.validUntil;
1577 if (!res || chainedExpiration < *res)
1579 res = chainedExpiration;
1583 if (localPublisherList.list.size() > 0)
1585 PublisherList collection = localPublisherList;
1587 auto const&
current = collection;
1588 auto chainedExpiration =
current.validUntil;
1591 if (!res || chainedExpiration < *res)
1593 res = chainedExpiration;
1600ValidatorList::expires()
const
1603 return expires(read_lock);
1607ValidatorList::getJson()
const
1613 res[jss::validation_quorum] =
static_cast<Json::UInt>(quorum_);
1618 x[jss::count] =
static_cast<Json::UInt>(count(read_lock));
1620 if (
auto when = expires(read_lock))
1622 if (*when == TimeKeeper::time_point::max())
1624 x[jss::expiration] =
"never";
1625 x[jss::status] =
"active";
1629 x[jss::expiration] = to_string(*when);
1631 if (*when > timeKeeper_.now())
1632 x[jss::status] =
"active";
1634 x[jss::status] =
"expired";
1639 x[jss::status] =
"unknown";
1640 x[jss::expiration] =
"unknown";
1643 x[jss::validator_list_threshold] =
Json::UInt(listThreshold_);
1650 for (
auto const& key : localPublisherList.list)
1656 for (
auto const& [publicKey, pubCollection] : publisherLists_)
1659 curr[jss::pubkey_publisher] =
strHex(publicKey);
1660 curr[jss::available] =
1661 pubCollection.status == PublisherStatus::available;
1665 target[jss::uri] = publisherList.
siteUri;
1670 target[jss::expiration] = to_string(publisherList.
validUntil);
1673 target[jss::effective] = to_string(publisherList.
validFrom);
1675 for (
auto const& key : publisherList.
list)
1681 auto const&
current = pubCollection.current;
1685 curr[jss::version] = pubCollection.rawVersion;
1690 for (
auto const& [sequence, future] : pubCollection.remaining)
1692 using namespace std::chrono_literals;
1696 appendList(future, r);
1699 future.validFrom > timeKeeper_.now() + 600s,
1700 "ripple::ValidatorList::getJson : minimum valid from");
1702 if (remaining.
size())
1703 curr[jss::remaining] = std::move(remaining);
1709 for (
auto const& k : trustedMasterKeys_)
1716 validatorManifests_.for_each_manifest([&jSigningKeys,
1717 this](Manifest
const& manifest) {
1718 auto it = keyListings_.find(manifest.masterKey);
1719 if (it != keyListings_.end() && manifest.signingKey)
1721 jSigningKeys[toBase58(TokenType::NodePublic, manifest.masterKey)] =
1722 toBase58(TokenType::NodePublic, *manifest.signingKey);
1727 if (!negativeUNL_.empty())
1730 for (
auto const& k : negativeUNL_)
1740ValidatorList::for_each_listed(
1745 for (
auto const& v : keyListings_)
1746 func(v.first, trusted(read_lock, v.first));
1750ValidatorList::for_each_available(
1757 uint256 const& hash)> func)
const
1761 for (
auto const& [key, plCollection] : publisherLists_)
1763 if (plCollection.status != PublisherStatus::available)
1766 plCollection.maxSequence != 0,
1767 "ripple::ValidatorList::for_each_available : nonzero maxSequence");
1769 plCollection.rawManifest,
1770 plCollection.rawVersion,
1771 buildBlobInfos(plCollection),
1773 plCollection.maxSequence.value_or(0),
1774 plCollection.fullHash);
1779ValidatorList::getAvailable(
1789 JLOG(j_.
warn()) <<
"Invalid requested validator list publisher key: "
1796 auto const iter = publisherLists_.find(
id);
1798 if (iter == publisherLists_.end() ||
1799 iter->second.status != PublisherStatus::available)
1803 buildFileData(
std::string{pubKey}, iter->second, forceVersion, j_);
1809ValidatorList::calculateQuorum(
1815 if (minimumQuorum_ > 0)
1817 JLOG(j_.
warn()) <<
"Using potentially unsafe quorum of "
1819 <<
" as specified on the command line";
1820 return *minimumQuorum_;
1823 if (!publisherLists_.empty())
1828 for (
auto const& list : publisherLists_)
1830 if (list.second.status != PublisherStatus::available)
1852 auto const errorThreshold =
std::min(
1854 publisherLists_.size() - listThreshold_ + 1);
1857 "ripple::ValidatorList::calculateQuorum : nonzero error threshold");
1901ValidatorList::updateTrusted(
1908 using namespace std::chrono_literals;
1909 if (timeKeeper_.now() > closeTime + 30s)
1910 closeTime = timeKeeper_.now();
1919 for (
auto& [pubKey, collection] : publisherLists_)
1922 auto& remaining = collection.remaining;
1923 auto const firstIter = remaining.begin();
1924 auto iter = firstIter;
1925 if (iter != remaining.end() && iter->second.validFrom <= closeTime)
1928 for (
auto next =
std::next(iter); next != remaining.end() &&
1929 next->second.validFrom <= closeTime;
1934 "ripple::ValidatorList::updateTrusted : sequential "
1938 iter != remaining.end(),
1939 "ripple::ValidatorList::updateTrusted : non-end of "
1943 auto sequence = iter->first;
1944 auto& candidate = iter->second;
1945 auto&
current = collection.current;
1947 candidate.validFrom <= closeTime,
1948 "ripple::ValidatorList::updateTrusted : maximum time");
1950 auto const oldList =
current.list;
1951 current = std::move(candidate);
1952 if (collection.status != PublisherStatus::available)
1953 collection.status = PublisherStatus::available;
1956 "ripple::ValidatorList::updateTrusted : sequence match");
1960 if (
current.validUntil <= closeTime)
1963 updatePublisherList(pubKey,
current, oldList, lock);
1980 remaining.erase(firstIter,
std::next(iter));
1986 if (collection.status == PublisherStatus::available &&
1987 collection.current.validUntil <= closeTime)
1989 removePublisherList(lock, pubKey, PublisherStatus::expired);
1992 if (collection.status != PublisherStatus::available)
2000 auto it = trustedMasterKeys_.cbegin();
2001 while (it != trustedMasterKeys_.cend())
2003 auto const kit = keyListings_.find(*it);
2004 if (kit == keyListings_.end() ||
2005 kit->second < listThreshold_ ||
2006 validatorManifests_.revoked(*it))
2009 it = trustedMasterKeys_.erase(it);
2014 kit->second >= listThreshold_,
2015 "ripple::ValidatorList::updateTrusted : count meets threshold");
2020 for (
auto const& val : keyListings_)
2022 if (val.second >= listThreshold_ &&
2023 !validatorManifests_.revoked(val.first) &&
2024 trustedMasterKeys_.emplace(val.first).second)
2030 if (!trustChanges.
added.empty() || !trustChanges.
removed.empty())
2032 trustedSigningKeys_.clear();
2036 for (
auto const& k : trustedMasterKeys_)
2039 validatorManifests_.getSigningKey(k);
2042 "ripple::ValidatorList::updateTrusted : found signing key");
2043 trustedSigningKeys_.insert(*signingKey);
2048 << trustedMasterKeys_.size() <<
" of " << keyListings_.size()
2049 <<
" listed validators eligible for inclusion in the trusted set";
2051 auto const unlSize = trustedMasterKeys_.size();
2052 auto effectiveUnlSize = unlSize;
2053 auto seenSize = seenValidators.
size();
2054 if (!negativeUNL_.empty())
2056 for (
auto const& k : trustedMasterKeys_)
2058 if (negativeUNL_.count(k))
2062 for (
auto const& k : negativeUNL_)
2066 for (
auto const& nid : seenValidators)
2068 if (negUnlNodeIDs.
count(nid))
2072 quorum_ = calculateQuorum(unlSize, effectiveUnlSize, seenSize);
2074 JLOG(j_.
debug()) <<
"Using quorum of " << quorum_ <<
" for new set of "
2075 << unlSize <<
" trusted validators ("
2076 << trustChanges.
added.size() <<
" added, "
2077 << trustChanges.
removed.size() <<
" removed)";
2079 if (unlSize < quorum_)
2081 JLOG(j_.
warn()) <<
"New quorum of " << quorum_
2082 <<
" exceeds the number of trusted validators ("
2086 if ((publisherLists_.size() || localPublisherList.list.size()) &&
2093 return trustChanges;
2097ValidatorList::getTrustedMasterKeys()
const
2100 return trustedMasterKeys_;
2104ValidatorList::getListThreshold()
const
2107 return listThreshold_;
2111ValidatorList::getNegativeUNL()
const
2114 return negativeUNL_;
2121 negativeUNL_ = negUnl;
2125ValidatorList::negativeUNLFilter(
2129 auto ret = std::move(validations);
2132 if (!negativeUNL_.empty())
2138 [&](
auto const& v) ->
bool {
2139 if (auto const masterKey =
2140 getTrustedKey(read_lock, v->getSignerPublic());
2143 return negativeUNL_.count(*masterKey);
Unserialize a JSON document into a Value.
bool parse(std::string const &document, Value &root)
Read a Value from a JSON document.
Value & append(Value const &value)
Append value to array at the end.
UInt size() const
Number of values in array or object.
std::string toStyledString() const
std::string asString() const
Returns the unquoted string value.
bool isMember(char const *key) const
Return true if the object has a member named key.
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
typename Clock::time_point time_point
typename Clock::duration duration
Routing table for objects identified by hash.
std::optional< std::set< PeerShortID > > shouldRelay(uint256 const &key)
Determines whether the hashed item should be relayed.
bool addSuppressionPeer(uint256 const &key, PeerShortID peer)
Remembers manifests with the highest sequence number.
std::optional< PublicKey > getSigningKey(PublicKey const &pk) const
Returns master key's current signing key.
bool revoked(PublicKey const &pk) const
Returns true if master key has been revoked in a manifest.
ManifestDisposition applyManifest(Manifest m)
Add manifest to cache.
PublicKey getMasterKey(PublicKey const &pk) const
Returns ephemeral signing key's master public key.
static std::size_t totalSize(::google::protobuf::Message const &message)
Provides server functionality for clients.
virtual void setUNLBlocked()=0
virtual void clearUNLBlocked()=0
Manages the set of connected peers.
virtual PeerSequence getActivePeers() const =0
Returns a sequence representing the current list of peers.
Represents a peer connection in the overlay.
virtual bool supportsFeature(ProtocolFeature f) const =0
virtual std::string const & fingerprint() const =0
virtual void send(std::shared_ptr< Message > const &m)=0
virtual void setPublisherListSequence(PublicKey const &, std::size_t const)=0
virtual id_t id() const =0
std::size_t size() const noexcept
const_iterator end() const noexcept
An immutable linear range of bytes.
Manages various times used by the server.
time_point now() const override
Returns the current time, using the server's clock.
std::size_t count() const
Return the number of configured validator list sites.
std::optional< PublicKey > getTrustedKey(PublicKey const &identity) const
Returns master public key if public key is trusted.
static void sendValidatorList(Peer &peer, std::uint64_t peerSequence, PublicKey const &publisherKey, std::size_t maxSequence, std::uint32_t rawVersion, std::string const &rawManifest, std::map< std::size_t, ValidatorBlobInfo > const &blobInfos, HashRouter &hashRouter, beast::Journal j)
static void broadcastBlobs(PublicKey const &publisherKey, PublisherListCollection const &lists, std::size_t maxSequence, uint256 const &hash, Overlay &overlay, HashRouter &hashRouter, beast::Journal j)
boost::filesystem::path getCacheFileName(lock_guard const &, PublicKey const &pubKey) const
Get the filename used for caching UNLs.
std::vector< std::string > loadLists()
PublisherList localPublisherList
std::optional< PublicKey > localPublicKey() const
This function returns the local validator public key or a std::nullopt.
ManifestCache & validatorManifests_
std::atomic< std::size_t > quorum_
void updatePublisherList(PublicKey const &pubKey, PublisherList const ¤t, std::vector< PublicKey > const &oldList, lock_guard const &)
static Json::Value buildFileData(std::string const &pubKey, PublisherListCollection const &pubCollection, beast::Journal j)
Build a Json representation of the collection, suitable for writing to a cache file,...
static void buildBlobInfos(std::map< std::size_t, ValidatorBlobInfo > &blobInfos, PublisherListCollection const &lists)
hash_map< PublicKey, std::size_t > keyListings_
bool listed(PublicKey const &identity) const
Returns true if public key is included on any lists.
std::size_t listThreshold_
void cacheValidatorFile(lock_guard const &lock, PublicKey const &pubKey) const
Write a JSON UNL to a cache file.
hash_set< PublicKey > trustedMasterKeys_
PublisherListStats applyList(std::string const &globalManifest, std::optional< std::string > const &localManifest, std::string const &blob, std::string const &signature, std::uint32_t version, std::string siteUri, std::optional< uint256 > const &hash, lock_guard const &)
Apply published list of public keys.
std::optional< TimeKeeper::time_point > expires() const
Return the time when the validator list will expire.
PublisherListStats applyListsAndBroadcast(std::string const &manifest, std::uint32_t version, std::vector< ValidatorBlobInfo > const &blobs, std::string siteUri, uint256 const &hash, Overlay &overlay, HashRouter &hashRouter, NetworkOPs &networkOPs)
Apply multiple published lists of public keys, then broadcast it to all peers that have not seen it o...
bool trustedPublisher(PublicKey const &identity) const
Returns true if public key is a trusted publisher.
std::optional< PublicKey > getListedKey(PublicKey const &identity) const
Returns listed master public if public key is included on any lists.
boost::filesystem::path const dataPath_
bool removePublisherList(lock_guard const &, PublicKey const &publisherKey, PublisherStatus reason)
Stop trusting publisher's list of keys.
bool trusted(PublicKey const &identity) const
Returns true if public key is trusted.
static constexpr std::size_t maxSupportedBlobs
ValidatorList(ManifestCache &validatorManifests, ManifestCache &publisherManifests, TimeKeeper &timeKeeper, std::string const &databasePath, beast::Journal j, std::optional< std::size_t > minimumQuorum=std::nullopt)
std::optional< PublicKey > localPubKey_
bool load(std::optional< PublicKey > const &localSigningKey, std::vector< std::string > const &configKeys, std::vector< std::string > const &publisherKeys, std::optional< std::size_t > listThreshold={})
Load configured trusted keys.
std::optional< std::size_t > minimumQuorum_
std::pair< ListDisposition, std::optional< PublicKey > > verify(lock_guard const &, Json::Value &list, Manifest manifest, std::string const &blob, std::string const &signature)
Check response for trusted valid published list.
static std::vector< ValidatorBlobInfo > parseBlobs(std::uint32_t version, Json::Value const &body)
Pull the blob/signature/manifest information out of the appropriate Json body fields depending on the...
static std::string const filePrefix_
hash_map< PublicKey, PublisherListCollection > publisherLists_
PublisherListStats applyLists(std::string const &manifest, std::uint32_t version, std::vector< ValidatorBlobInfo > const &blobs, std::string siteUri, std::optional< uint256 > const &hash={})
Apply multiple published lists of public keys.
static std::pair< std::size_t, std::size_t > buildValidatorListMessages(std::size_t messageVersion, std::uint64_t peerSequence, std::size_t maxSequence, std::uint32_t rawVersion, std::string const &rawManifest, std::map< std::size_t, ValidatorBlobInfo > const &blobInfos, std::vector< MessageWithHash > &messages, std::size_t maxSize=maximiumMessageSize)
ManifestCache & publisherManifests_
static constexpr std::uint32_t supportedListVersions[]
T emplace_back(T... args)
@ arrayValue
array value (ordered list)
@ objectValue
object value (collection of name/value pairs).
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
std::optional< Manifest > deserializeManifest(Slice s, beast::Journal journal)
Constructs Manifest from serialized string.
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig, bool mustBeFullyCanonical=true) noexcept
Verify a signature on a message.
@ ValidatorListPropagation
@ ValidatorList2Propagation
std::string base64_decode(std::string_view data)
std::size_t splitMessage(std::vector< ValidatorList::MessageWithHash > &messages, protocol::TMValidatorListCollection const &largeMsg, std::size_t maxSize, std::size_t begin=0, std::size_t end=0)
std::size_t splitMessageParts(std::vector< ValidatorList::MessageWithHash > &messages, protocol::TMValidatorListCollection const &largeMsg, std::size_t maxSize, std::size_t begin, std::size_t end)
@ current
This was a new validation and was added.
@ unsupported_version
List version is not supported.
@ stale
Trusted publisher key, but seq is too old.
@ untrusted
List signed by untrusted publisher key.
@ same_sequence
Same sequence as current list.
@ pending
List will be valid in the future.
@ known_sequence
Future sequence already seen.
@ expired
List is expired, but has the largest non-pending sequence seen so far.
@ invalid
Invalid format or signature.
std::error_code make_error_code(ripple::TokenCodecErrc e)
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
std::string strHex(FwdIt begin, FwdIt end)
@ accepted
Manifest is valid.
@ invalid
Timely, but invalid signature.
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
NodeID calcNodeID(PublicKey const &)
Calculate the 160-bit node ID from a node public key.
std::optional< Blob > strViewUnHex(std::string_view strSrc)
std::string to_string(base_uint< Bits, Tag > const &a)
constexpr std::size_t maximiumMessageSize
void writeFileContents(boost::system::error_code &ec, boost::filesystem::path const &destPath, std::string const &contents)
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
std::size_t buildValidatorListMessage(std::vector< ValidatorList::MessageWithHash > &messages, std::uint32_t rawVersion, std::string const &rawManifest, ValidatorBlobInfo const ¤tBlob, std::size_t maxSize)
Changes in trusted nodes after updating validator list.
hash_set< NodeID > removed
Used to represent the information stored in the blobs_v2 Json array.
std::optional< std::string > manifest
MessageWithHash()=default
std::map< std::size_t, PublisherList > remaining
Describes the result of processing a Validator List (UNL), including some of the information from the...
void mergeDispositions(PublisherListStats const &src)
ListDisposition bestDisposition() const
PublisherListStats()=default
ListDisposition worstDisposition() const
std::map< ListDisposition, std::size_t > dispositions
std::optional< PublicKey > publisherKey
std::vector< PublicKey > list
TimeKeeper::time_point validUntil
TimeKeeper::time_point validFrom