20#include <xrpld/app/misc/HashRouter.h>
21#include <xrpld/app/misc/NetworkOPs.h>
22#include <xrpld/app/misc/ValidatorList.h>
23#include <xrpld/overlay/Overlay.h>
25#include <xrpl/basics/FileUtilities.h>
26#include <xrpl/basics/Slice.h>
27#include <xrpl/basics/StringUtilities.h>
28#include <xrpl/basics/base64.h>
29#include <xrpl/json/json_reader.h>
30#include <xrpl/protocol/PublicKey.h>
31#include <xrpl/protocol/STValidation.h>
32#include <xrpl/protocol/digest.h>
33#include <xrpl/protocol/jss.h>
34#include <xrpl/protocol/messages.h>
36#include <boost/regex.hpp>
54 return "same_sequence";
58 return "known_sequence";
60 return "unsupported_version";
81 : publisherKey(key), status(stat), sequence(seq)
90 : dispositions.begin()->first;
97 : dispositions.rbegin()->first;
106 dispositions[disp] +=
count;
114 : message(message_), hash(hash_), numVLs(num_)
132 ,
quorum_(minimumQuorum.value_or(1))
145 static boost::regex
const re(
160 <<
"Loading configured trusted validator list publisher keys";
163 for (
auto key : publisherKeys)
165 JLOG(
j_.
trace()) <<
"Processing '" << key <<
"'";
171 JLOG(
j_.
error()) <<
"Invalid validator list publisher key: " << key;
181 <<
"Configured validator list publisher key is revoked: "
189 <<
"Duplicate validator list publisher key: " << key;
203 "ripple::ValidatorList::load : list threshold inside range");
204 JLOG(
j_.
debug()) <<
"Validator list threshold set in configuration to "
213 JLOG(
j_.
debug()) <<
"Validator list threshold computed as "
227 auto const [_, inserted] =
231 JLOG(
j_.
debug()) <<
"Added own master key "
236 JLOG(
j_.
debug()) <<
"Loading configured validator keys";
239 for (
auto const& n : configKeys)
241 JLOG(
j_.
trace()) <<
"Processing '" << n <<
"'";
245 if (!boost::regex_match(n,
match, re))
247 JLOG(
j_.
error()) <<
"Malformed entry: '" << n <<
"'";
256 JLOG(
j_.
error()) <<
"Invalid node identity: " <<
match[1];
267 JLOG(
j_.
warn()) <<
"Duplicate node identity: " <<
match[1];
285boost::filesystem::path
315 "ripple::ValidatorList::buildFileData : valid publisher list input");
316 auto const effectiveVersion =
317 forceVersion ? *forceVersion : pubCollection.
rawVersion;
320 value[jss::version] = effectiveVersion;
321 value[jss::public_key] = pubKey;
323 switch (effectiveVersion)
327 value[jss::blob] =
current.rawBlob;
328 value[jss::signature] =
current.rawSignature;
333 value[jss::manifest] = *
current.rawManifest;
339 auto add = [&blobs, &outerManifest = pubCollection.
rawManifest](
342 blob[jss::blob] = pubList.rawBlob;
343 blob[jss::signature] = pubList.rawSignature;
344 if (pubList.rawManifest &&
345 *pubList.rawManifest != outerManifest)
346 blob[jss::manifest] = *pubList.rawManifest;
356 value[jss::blobs_v2] = std::move(blobs);
361 <<
"Invalid VL version provided: " << effectiveVersion;
378 boost::system::error_code ec;
386 value[jss::refresh_interval] = 24 * 60;
393 JLOG(
j_.
error()) <<
"Problem writing " << filename <<
" " << ec.value()
394 <<
": " << ec.message();
417 "ripple::ValidatorList::parseBlobs : single element result");
426 if (!body.
isMember(jss::blobs_v2) ||
427 !body[jss::blobs_v2].
isArray() ||
432 auto const& blobs = body[jss::blobs_v2];
434 for (
auto const& blobInfo : blobs)
436 if (!blobInfo.isObject() ||
437 !blobInfo.isMember(jss::signature) ||
438 !blobInfo[jss::signature].isString() ||
439 !blobInfo.isMember(jss::blob) ||
440 !blobInfo[jss::blob].isString())
443 info.
blob = blobInfo[jss::blob].asString();
444 info.
signature = blobInfo[jss::signature].asString();
445 if (blobInfo.isMember(jss::manifest))
447 if (!blobInfo[jss::manifest].isString())
449 info.
manifest = blobInfo[jss::manifest].asString();
453 result.
size() == blobs.size(),
454 "ripple::ValidatorList::parseBlobs(version, Jason::Value) : "
455 "result size matches");
465 return {{body.blob(), body.signature(), {}}};
475 result.
reserve(body.blobs_size());
476 for (
auto const& blob : body.blobs())
479 info.
blob = blob.blob();
481 if (blob.has_manifest())
487 result.
size() == body.blobs_size(),
488 "ripple::ValidatorList::parseBlobs(TMValidatorList) : result size "
496 protocol::TMValidatorListCollection
const& largeMsg,
504 protocol::TMValidatorListCollection
const& largeMsg,
509 if (begin == 0 && end == 0)
510 end = largeMsg.blobs_size();
511 XRPL_ASSERT(begin < end,
"ripple::splitMessage : valid inputs");
515 auto mid = (begin + end) / 2;
525 protocol::TMValidatorListCollection
const& largeMsg,
532 if (end - begin == 1)
534 protocol::TMValidatorList smallMsg;
535 smallMsg.set_version(1);
536 smallMsg.set_manifest(largeMsg.manifest());
538 auto const& blob = largeMsg.blobs(begin);
539 smallMsg.set_blob(blob.blob());
540 smallMsg.set_signature(blob.signature());
542 if (blob.has_manifest())
543 smallMsg.set_manifest(blob.manifest());
547 "ripple::splitMessageParts : maximum message size");
550 std::make_shared<Message>(smallMsg, protocol::mtVALIDATORLIST),
553 return messages.
back().numVLs;
559 smallMsg->set_version(largeMsg.version());
560 smallMsg->set_manifest(largeMsg.manifest());
564 *smallMsg->add_blobs() = largeMsg.blobs(i);
571 return splitMessage(messages, largeMsg, maxSize, begin, end);
576 std::make_shared<Message>(
577 *smallMsg, protocol::mtVALIDATORLISTCOLLECTION),
579 smallMsg->blobs_size());
580 return messages.
back().numVLs;
597 "ripple::buildValidatorListMessage(ValidatorBlobInfo) : empty messages "
599 protocol::TMValidatorList msg;
602 auto const version = 1;
604 msg.set_blob(currentBlob.
blob);
605 msg.set_signature(currentBlob.
signature);
607 msg.set_version(version);
611 "ripple::buildValidatorListMessage(ValidatorBlobInfo) : maximum "
614 std::make_shared<Message>(msg, protocol::mtVALIDATORLIST),
633 "ripple::buildValidatorListMessage(std::map<std::size_t, "
634 "ValidatorBlobInfo>) : empty messages input");
635 protocol::TMValidatorListCollection msg;
636 auto const version = rawVersion < 2 ? 2 : rawVersion;
637 msg.set_version(version);
638 msg.set_manifest(rawManifest);
640 for (
auto const& [sequence, blobInfo] : blobInfos)
642 if (sequence <= peerSequence)
644 protocol::ValidatorBlobInfo& blob = *msg.add_blobs();
645 blob.set_blob(blobInfo.blob);
646 blob.set_signature(blobInfo.signature);
647 if (blobInfo.manifest)
648 blob.set_manifest(*blobInfo.manifest);
651 msg.blobs_size() > 0,
652 "ripple::buildValidatorListMessage(std::map<std::size_t, "
653 "ValidatorBlobInfo>) : minimum message blobs");
662 std::make_shared<Message>(msg, protocol::mtVALIDATORLISTCOLLECTION),
665 return messages.
back().numVLs;
684 "ripple::ValidatorList::buildValidatorListMessages : empty messages "
686 auto const& [currentSeq, currentBlob] = *blobInfos.
begin();
692 return total + m.numVLs;
694 if (messageVersion == 2 && peerSequence < maxSequence)
697 if (messages.
empty())
706 if (messages.
empty())
713 return {maxSequence, numVLs};
715 else if (messageVersion == 1 && peerSequence < currentSeq)
718 if (messages.
empty())
723 currentBlob.manifest ? *currentBlob.manifest : rawManifest,
726 if (messages.
empty())
733 return {currentSeq, numVLs};
770 "ripple::ValidatorList::sendValidatorList : non-empty messages "
776 for (
auto const& message : messages)
780 peer.
send(message.message);
788 sent || messages.size() == 1,
789 "ripple::ValidatorList::sendValidatorList : sent or one message");
792 if (messageVersion > 1)
794 <<
"Sent " << messages.size()
795 <<
" validator list collection(s) containing " << numVLs
796 <<
" validator list(s) for " <<
strHex(publisherKey)
797 <<
" with sequence range " << peerSequence <<
", "
798 << newPeerSequence <<
" to "
805 "ripple::ValidatorList::sendValidatorList : one validator "
808 <<
"Sent validator list for " <<
strHex(publisherKey)
809 <<
" with sequence " << newPeerSequence <<
" to "
852 blobInfos[
current.sequence] = {
854 for (
auto const& [sequence, vl] : remaining)
856 blobInfos[sequence] = {vl.rawBlob, vl.rawSignature, vl.rawManifest};
904 "ripple::ValidatorList::broadcastBlobs : valid sequence");
909 if (toSkip->count(peer->id()) == 0)
911 auto const peerSequence =
912 peer->publisherListSequence(publisherKey).value_or(0);
913 if (peerSequence < maxSequence)
915 if (blobInfos.
empty())
917 auto const v2 = peer->supportsFeature(
927 v2 ? messages2[peerSequence] : messages1,
952 auto const disposition = result.bestDisposition();
979 result.publisherKey &&
985 *result.publisherKey,
987 *pubCollection.maxSequence,
1014 for (
auto const& blobInfo : blobs)
1030 stats.mergeDispositions(result);
1031 result = std::move(stats);
1043 auto& remaining = pubCollection.remaining;
1044 auto const&
current = pubCollection.current;
1045 for (
auto iter = remaining.begin(); iter != remaining.end();)
1049 next == remaining.end() || next->first > iter->first,
1050 "ripple::ValidatorList::applyLists : next is valid");
1051 if (iter->first <=
current.sequence ||
1052 (next != remaining.end() &&
1053 next->second.validFrom <= iter->second.validFrom))
1055 iter = remaining.erase(iter);
1065 pubCollection.fullHash =
sha512Half(pubCollection);
1067 result.
sequence = *pubCollection.maxSequence;
1083 auto iNew = publisherList.
begin();
1084 auto iOld = oldList.
begin();
1085 while (iNew != publisherList.
end() || iOld != oldList.
end())
1087 if (iOld == oldList.
end() ||
1088 (iNew != publisherList.
end() && *iNew < *iOld))
1095 iNew == publisherList.
end() ||
1096 (iOld != oldList.
end() && *iOld < *iNew))
1112 if (publisherList.
empty())
1114 JLOG(
j_.
warn()) <<
"No validator keys included in valid list";
1117 for (
auto const& valManifest : manifests)
1124 <<
" contained untrusted validator manifest";
1132 <<
" contained invalid validator manifest";
1148 using namespace std::string_literals;
1151 auto const&
manifest = localManifest ? *localManifest : globalManifest;
1152 auto [result, pubKeyOpt] =
verify(lock, list,
manifest, blob, signature);
1156 JLOG(
j_.
info()) <<
"ValidatorList::applyList unable to retrieve the "
1157 "master public key from the verify function\n";
1163 JLOG(
j_.
info()) <<
"ValidatorList::applyList Invalid Public Key type"
1164 " retrieved from the verify function\n ";
1174 if (pubCollection.maxSequence &&
1183 pubCollection.status,
1184 *pubCollection.maxSequence};
1192 auto const sequence = list[jss::sequence].
asUInt();
1201 pubCollection.rawManifest = globalManifest;
1202 if (!pubCollection.maxSequence || sequence > *pubCollection.maxSequence)
1203 pubCollection.maxSequence = sequence;
1205 Json::Value const& newList = list[jss::validators];
1207 if (
accepted && pubCollection.remaining.count(sequence) != 0)
1214 auto& publisher = pubCollection.current;
1216 oldList = std::move(pubCollection.current.list);
1218 publisher = std::move(pubCollection.remaining[sequence]);
1220 pubCollection.remaining.erase(sequence);
1223 publisher.sequence == sequence,
1224 "ripple::ValidatorList::applyList : publisher sequence match");
1228 auto& publisher =
accepted ? pubCollection.current
1229 : pubCollection.remaining[sequence];
1230 publisher.sequence = sequence;
1232 list.
isMember(jss::effective) ? list[jss::effective].
asUInt() : 0}};
1235 publisher.siteUri = std::move(siteUri);
1236 publisher.rawBlob = blob;
1237 publisher.rawSignature = signature;
1238 publisher.rawManifest = localManifest;
1240 publisher.hash = *hash;
1246 oldList = std::move(publisherList);
1248 publisherList.
clear();
1250 for (
auto const& val : newList)
1252 if (val.isObject() && val.isMember(jss::validation_public_key) &&
1253 val[jss::validation_public_key].isString())
1256 strUnHex(val[jss::validation_public_key].asString());
1261 <<
"Invalid node identity: "
1262 << val[jss::validation_public_key].asString();
1270 if (val.isMember(jss::manifest) &&
1271 val[jss::manifest].isString())
1272 manifests.
push_back(val[jss::manifest].asString());
1281 pubCollection.rawVersion =
std::max(pubCollection.rawVersion, version);
1282 if (!pubCollection.remaining.empty())
1286 pubCollection.rawVersion =
std::max(pubCollection.rawVersion, 2u);
1290 result, pubKey, pubCollection.status, *pubCollection.maxSequence};
1303 using namespace std::string_literals;
1304 using namespace boost::filesystem;
1305 using namespace boost::system::errc;
1313 boost::system::error_code ec;
1320 auto const fullPath{
canonical(filename, ec)};
1324 auto size = file_size(fullPath, ec);
1337 return fullPath.root_path() ==
"/"s ?
"file://" :
"file:///";
1369 auto const revoked = m->revoked();
1385 auto const sig =
strUnHex(signature);
1391 if (!r.
parse(data, list))
1394 if (list.
isMember(jss::sequence) && list[jss::sequence].
isInt() &&
1395 list.
isMember(jss::expiration) && list[jss::expiration].
isInt() &&
1396 (!list.
isMember(jss::effective) || list[jss::effective].
isInt()) &&
1399 auto const sequence = list[jss::sequence].
asUInt();
1401 list.
isMember(jss::effective) ? list[jss::effective].
asUInt() : 0}};
1406 if (validUntil <= validFrom)
1408 else if (sequence < listCollection.current.sequence)
1410 else if (sequence == listCollection.current.sequence)
1412 else if (validUntil <= now)
1414 else if (validFrom > now)
1425 return !listCollection.maxSequence ||
1426 sequence > *listCollection.maxSequence ||
1427 (listCollection.remaining.count(sequence) == 0 &&
1428 validFrom < listCollection.remaining
1429 .at(*listCollection.maxSequence)
1464 return trusted(read_lock, identity);
1475 return std::nullopt;
1486 return std::nullopt;
1521 "ripple::ValidatorList::removePublisherList : valid reason input");
1526 JLOG(
j_.
debug()) <<
"Removing validator list for publisher "
1529 for (
auto const& val : iList->second.current.list)
1535 if (iVal->second <= 1)
1541 iList->second.current.list.clear();
1542 iList->second.status = reason;
1557 return count(read_lock);
1567 auto const&
current = collection.current;
1570 return std::nullopt;
1576 auto chainedExpiration =
current.validUntil;
1577 for (
auto const& [sequence, check] : collection.remaining)
1580 if (check.validFrom <= chainedExpiration)
1581 chainedExpiration = check.validUntil;
1587 if (!res || chainedExpiration < *res)
1589 res = chainedExpiration;
1597 auto const&
current = collection;
1598 auto chainedExpiration =
current.validUntil;
1601 if (!res || chainedExpiration < *res)
1603 res = chainedExpiration;
1630 if (
auto when =
expires(read_lock))
1632 if (*when == TimeKeeper::time_point::max())
1634 x[jss::expiration] =
"never";
1635 x[jss::status] =
"active";
1642 x[jss::status] =
"active";
1644 x[jss::status] =
"expired";
1649 x[jss::status] =
"unknown";
1650 x[jss::expiration] =
"unknown";
1669 curr[jss::pubkey_publisher] =
strHex(publicKey);
1670 curr[jss::available] =
1675 target[jss::uri] = publisherList.
siteUri;
1685 for (
auto const& key : publisherList.
list)
1691 auto const&
current = pubCollection.current;
1695 curr[jss::version] = pubCollection.rawVersion;
1700 for (
auto const& [sequence, future] : pubCollection.remaining)
1702 using namespace std::chrono_literals;
1706 appendList(future, r);
1710 "ripple::ValidatorList::getJson : minimum valid from");
1712 if (remaining.
size())
1713 curr[jss::remaining] = std::move(remaining);
1719 for (
auto const& k : trustedMasterKeys_)
1726 validatorManifests_.for_each_manifest([&jSigningKeys,
1728 auto it = keyListings_.find(
manifest.masterKey);
1729 if (it != keyListings_.end() &&
manifest.signingKey)
1737 if (!negativeUNL_.empty())
1740 for (
auto const& k : negativeUNL_)
1750ValidatorList::for_each_listed(
1755 for (
auto const& v : keyListings_)
1756 func(v.first, trusted(read_lock, v.first));
1760ValidatorList::for_each_available(
1767 uint256 const& hash)> func)
const
1771 for (
auto const& [key, plCollection] : publisherLists_)
1773 if (plCollection.status != PublisherStatus::available)
1776 plCollection.maxSequence != 0,
1777 "ripple::ValidatorList::for_each_available : nonzero maxSequence");
1779 plCollection.rawManifest,
1780 plCollection.rawVersion,
1781 buildBlobInfos(plCollection),
1783 plCollection.maxSequence.value_or(0),
1784 plCollection.fullHash);
1789ValidatorList::getAvailable(
1799 JLOG(j_.
info()) <<
"Invalid requested validator list publisher key: "
1806 auto const iter = publisherLists_.find(
id);
1808 if (iter == publisherLists_.end() ||
1809 iter->second.status != PublisherStatus::available)
1813 buildFileData(
std::string{pubKey}, iter->second, forceVersion, j_);
1819ValidatorList::calculateQuorum(
1825 if (minimumQuorum_ > 0)
1827 JLOG(j_.
warn()) <<
"Using potentially unsafe quorum of "
1829 <<
" as specified on the command line";
1830 return *minimumQuorum_;
1833 if (!publisherLists_.empty())
1838 for (
auto const& list : publisherLists_)
1840 if (list.second.status != PublisherStatus::available)
1862 auto const errorThreshold =
std::min(
1864 publisherLists_.size() - listThreshold_ + 1);
1867 "ripple::ValidatorList::calculateQuorum : nonzero error threshold");
1911ValidatorList::updateTrusted(
1918 using namespace std::chrono_literals;
1919 if (timeKeeper_.now() > closeTime + 30s)
1920 closeTime = timeKeeper_.now();
1929 for (
auto& [pubKey, collection] : publisherLists_)
1932 auto& remaining = collection.remaining;
1933 auto const firstIter = remaining.begin();
1934 auto iter = firstIter;
1935 if (iter != remaining.end() && iter->second.validFrom <= closeTime)
1938 for (
auto next =
std::next(iter); next != remaining.end() &&
1939 next->second.validFrom <= closeTime;
1944 "ripple::ValidatorList::updateTrusted : sequential "
1948 iter != remaining.end(),
1949 "ripple::ValidatorList::updateTrusted : non-end of "
1953 auto sequence = iter->first;
1954 auto& candidate = iter->second;
1955 auto&
current = collection.current;
1957 candidate.validFrom <= closeTime,
1958 "ripple::ValidatorList::updateTrusted : maximum time");
1960 auto const oldList =
current.list;
1961 current = std::move(candidate);
1962 if (collection.status != PublisherStatus::available)
1963 collection.status = PublisherStatus::available;
1966 "ripple::ValidatorList::updateTrusted : sequence match");
1970 if (
current.validUntil <= closeTime)
1973 updatePublisherList(pubKey,
current, oldList, lock);
1990 remaining.erase(firstIter,
std::next(iter));
1996 if (collection.status == PublisherStatus::available &&
1997 collection.current.validUntil <= closeTime)
1999 removePublisherList(lock, pubKey, PublisherStatus::expired);
2002 if (collection.status != PublisherStatus::available)
2010 auto it = trustedMasterKeys_.cbegin();
2011 while (it != trustedMasterKeys_.cend())
2013 auto const kit = keyListings_.find(*it);
2014 if (kit == keyListings_.end() ||
2015 kit->second < listThreshold_ ||
2016 validatorManifests_.revoked(*it))
2019 it = trustedMasterKeys_.erase(it);
2024 kit->second >= listThreshold_,
2025 "ripple::ValidatorList::updateTrusted : count meets threshold");
2030 for (
auto const& val : keyListings_)
2032 if (val.second >= listThreshold_ &&
2033 !validatorManifests_.revoked(val.first) &&
2034 trustedMasterKeys_.emplace(val.first).second)
2040 if (!trustChanges.
added.empty() || !trustChanges.
removed.empty())
2042 trustedSigningKeys_.clear();
2046 for (
auto const& k : trustedMasterKeys_)
2049 validatorManifests_.getSigningKey(k);
2052 "ripple::ValidatorList::updateTrusted : found signing key");
2053 trustedSigningKeys_.insert(*signingKey);
2058 << trustedMasterKeys_.size() <<
" of " << keyListings_.size()
2059 <<
" listed validators eligible for inclusion in the trusted set";
2061 auto const unlSize = trustedMasterKeys_.size();
2062 auto effectiveUnlSize = unlSize;
2063 auto seenSize = seenValidators.
size();
2064 if (!negativeUNL_.empty())
2066 for (
auto const& k : trustedMasterKeys_)
2068 if (negativeUNL_.count(k))
2072 for (
auto const& k : negativeUNL_)
2076 for (
auto const& nid : seenValidators)
2078 if (negUnlNodeIDs.
count(nid))
2082 quorum_ = calculateQuorum(unlSize, effectiveUnlSize, seenSize);
2084 JLOG(j_.
debug()) <<
"Using quorum of " << quorum_ <<
" for new set of "
2085 << unlSize <<
" trusted validators ("
2086 << trustChanges.
added.size() <<
" added, "
2087 << trustChanges.
removed.size() <<
" removed)";
2089 if (unlSize < quorum_)
2091 JLOG(j_.
warn()) <<
"New quorum of " << quorum_
2092 <<
" exceeds the number of trusted validators ("
2096 if ((publisherLists_.size() || localPublisherList.list.size()) &&
2103 return trustChanges;
2107ValidatorList::getTrustedMasterKeys()
const
2110 return trustedMasterKeys_;
2114ValidatorList::getListThreshold()
const
2117 return listThreshold_;
2121ValidatorList::getNegativeUNL()
const
2124 return negativeUNL_;
2131 negativeUNL_ = negUnl;
2135ValidatorList::negativeUNLFilter(
2139 auto ret = std::move(validations);
2142 if (!negativeUNL_.empty())
2148 [&](
auto const& v) ->
bool {
2149 if (auto const masterKey =
2150 getTrustedKey(read_lock, v->getSignerPublic());
2153 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.
std::string to_string() const
Returns a string representing the endpoint.
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 beast::IP::Endpoint getRemoteAddress() 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
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.
Json::Value getJson() const
Return a JSON representation of the state of the validator list.
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_
boost::shared_mutex mutex_
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::pair< ListDisposition, std::optional< PublicKey > > verify(lock_guard const &, Json::Value &list, std::string const &manifest, std::string const &blob, std::string const &signature)
Check response for trusted valid published list.
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_
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