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>
24#include <xrpl/basics/FileUtilities.h>
25#include <xrpl/basics/Slice.h>
26#include <xrpl/basics/StringUtilities.h>
27#include <xrpl/basics/base64.h>
28#include <xrpl/json/json_reader.h>
29#include <xrpl/protocol/PublicKey.h>
30#include <xrpl/protocol/STValidation.h>
31#include <xrpl/protocol/digest.h>
32#include <xrpl/protocol/jss.h>
33#include <xrpl/protocol/messages.h>
34#include <boost/regex.hpp>
52 return "same_sequence";
56 return "known_sequence";
58 return "unsupported_version";
79 : publisherKey(key), status(stat), sequence(seq)
88 : dispositions.begin()->first;
95 : dispositions.rbegin()->first;
104 dispositions[disp] +=
count;
112 : message(message_), hash(hash_), numVLs(num_)
130 ,
quorum_(minimumQuorum.value_or(1))
143 static boost::regex
const re(
158 <<
"Loading configured trusted validator list publisher keys";
161 for (
auto key : publisherKeys)
163 JLOG(
j_.
trace()) <<
"Processing '" << key <<
"'";
169 JLOG(
j_.
error()) <<
"Invalid validator list publisher key: " << key;
179 <<
"Configured validator list publisher key is revoked: "
187 <<
"Duplicate validator list publisher key: " << key;
201 "ripple::ValidatorList::load : list threshold inside range");
202 JLOG(
j_.
debug()) <<
"Validator list threshold set in configuration to "
211 JLOG(
j_.
debug()) <<
"Validator list threshold computed as "
225 auto const [_, inserted] =
229 JLOG(
j_.
debug()) <<
"Added own master key "
234 JLOG(
j_.
debug()) <<
"Loading configured validator keys";
237 for (
auto const& n : configKeys)
239 JLOG(
j_.
trace()) <<
"Processing '" << n <<
"'";
243 if (!boost::regex_match(n,
match, re))
245 JLOG(
j_.
error()) <<
"Malformed entry: '" << n <<
"'";
254 JLOG(
j_.
error()) <<
"Invalid node identity: " <<
match[1];
265 JLOG(
j_.
warn()) <<
"Duplicate node identity: " <<
match[1];
283boost::filesystem::path
313 "ripple::ValidatorList::buildFileData : valid publisher list input");
314 auto const effectiveVersion =
315 forceVersion ? *forceVersion : pubCollection.
rawVersion;
318 value[jss::version] = effectiveVersion;
319 value[jss::public_key] = pubKey;
321 switch (effectiveVersion)
325 value[jss::blob] =
current.rawBlob;
326 value[jss::signature] =
current.rawSignature;
331 value[jss::manifest] = *
current.rawManifest;
337 auto add = [&blobs, &outerManifest = pubCollection.
rawManifest](
340 blob[jss::blob] = pubList.rawBlob;
341 blob[jss::signature] = pubList.rawSignature;
342 if (pubList.rawManifest &&
343 *pubList.rawManifest != outerManifest)
344 blob[jss::manifest] = *pubList.rawManifest;
354 value[jss::blobs_v2] = std::move(blobs);
359 <<
"Invalid VL version provided: " << effectiveVersion;
376 boost::system::error_code ec;
384 value[jss::refresh_interval] = 24 * 60;
391 JLOG(
j_.
error()) <<
"Problem writing " << filename <<
" " << ec.value()
392 <<
": " << ec.message();
415 "ripple::ValidatorList::parseBlobs : single element result");
424 if (!body.
isMember(jss::blobs_v2) ||
425 !body[jss::blobs_v2].
isArray() ||
430 auto const& blobs = body[jss::blobs_v2];
432 for (
auto const& blobInfo : blobs)
434 if (!blobInfo.isObject() ||
435 !blobInfo.isMember(jss::signature) ||
436 !blobInfo[jss::signature].isString() ||
437 !blobInfo.isMember(jss::blob) ||
438 !blobInfo[jss::blob].isString())
441 info.
blob = blobInfo[jss::blob].asString();
442 info.
signature = blobInfo[jss::signature].asString();
443 if (blobInfo.isMember(jss::manifest))
445 if (!blobInfo[jss::manifest].isString())
447 info.
manifest = blobInfo[jss::manifest].asString();
451 result.
size() == blobs.size(),
452 "ripple::ValidatorList::parseBlobs(version, Jason::Value) : "
453 "result size matches");
463 return {{body.blob(), body.signature(), {}}};
473 result.
reserve(body.blobs_size());
474 for (
auto const& blob : body.blobs())
477 info.
blob = blob.blob();
479 if (blob.has_manifest())
485 result.
size() == body.blobs_size(),
486 "ripple::ValidatorList::parseBlobs(TMValidatorList) : result size "
494 protocol::TMValidatorListCollection
const& largeMsg,
502 protocol::TMValidatorListCollection
const& largeMsg,
507 if (begin == 0 && end == 0)
508 end = largeMsg.blobs_size();
509 XRPL_ASSERT(begin < end,
"ripple::splitMessage : valid inputs");
513 auto mid = (begin + end) / 2;
523 protocol::TMValidatorListCollection
const& largeMsg,
530 if (end - begin == 1)
532 protocol::TMValidatorList smallMsg;
533 smallMsg.set_version(1);
534 smallMsg.set_manifest(largeMsg.manifest());
536 auto const& blob = largeMsg.blobs(begin);
537 smallMsg.set_blob(blob.blob());
538 smallMsg.set_signature(blob.signature());
540 if (blob.has_manifest())
541 smallMsg.set_manifest(blob.manifest());
545 "ripple::splitMessageParts : maximum message size");
548 std::make_shared<Message>(smallMsg, protocol::mtVALIDATORLIST),
551 return messages.
back().numVLs;
557 smallMsg->set_version(largeMsg.version());
558 smallMsg->set_manifest(largeMsg.manifest());
562 *smallMsg->add_blobs() = largeMsg.blobs(i);
569 return splitMessage(messages, largeMsg, maxSize, begin, end);
574 std::make_shared<Message>(
575 *smallMsg, protocol::mtVALIDATORLISTCOLLECTION),
577 smallMsg->blobs_size());
578 return messages.
back().numVLs;
595 "ripple::buildValidatorListMessage(ValidatorBlobInfo) : empty messages "
597 protocol::TMValidatorList msg;
600 auto const version = 1;
602 msg.set_blob(currentBlob.
blob);
603 msg.set_signature(currentBlob.
signature);
605 msg.set_version(version);
609 "ripple::buildValidatorListMessage(ValidatorBlobInfo) : maximum "
612 std::make_shared<Message>(msg, protocol::mtVALIDATORLIST),
631 "ripple::buildValidatorListMessage(std::map<std::size_t, "
632 "ValidatorBlobInfo>) : empty messages input");
633 protocol::TMValidatorListCollection msg;
634 auto const version = rawVersion < 2 ? 2 : rawVersion;
635 msg.set_version(version);
636 msg.set_manifest(rawManifest);
638 for (
auto const& [sequence, blobInfo] : blobInfos)
640 if (sequence <= peerSequence)
642 protocol::ValidatorBlobInfo& blob = *msg.add_blobs();
643 blob.set_blob(blobInfo.blob);
644 blob.set_signature(blobInfo.signature);
645 if (blobInfo.manifest)
646 blob.set_manifest(*blobInfo.manifest);
649 msg.blobs_size() > 0,
650 "ripple::buildValidatorListMessage(std::map<std::size_t, "
651 "ValidatorBlobInfo>) : minimum message blobs");
660 std::make_shared<Message>(msg, protocol::mtVALIDATORLISTCOLLECTION),
663 return messages.
back().numVLs;
682 "ripple::ValidatorList::buildValidatorListMessages : empty messages "
684 auto const& [currentSeq, currentBlob] = *blobInfos.
begin();
690 return total + m.numVLs;
692 if (messageVersion == 2 && peerSequence < maxSequence)
695 if (messages.
empty())
704 if (messages.
empty())
711 return {maxSequence, numVLs};
713 else if (messageVersion == 1 && peerSequence < currentSeq)
716 if (messages.
empty())
721 currentBlob.manifest ? *currentBlob.manifest : rawManifest,
724 if (messages.
empty())
731 return {currentSeq, numVLs};
768 "ripple::ValidatorList::sendValidatorList : non-empty messages "
774 for (
auto const& message : messages)
778 peer.
send(message.message);
786 sent || messages.size() == 1,
787 "ripple::ValidatorList::sendValidatorList : sent or one message");
790 if (messageVersion > 1)
792 <<
"Sent " << messages.size()
793 <<
" validator list collection(s) containing " << numVLs
794 <<
" validator list(s) for " <<
strHex(publisherKey)
795 <<
" with sequence range " << peerSequence <<
", "
796 << newPeerSequence <<
" to "
803 "ripple::ValidatorList::sendValidatorList : one validator "
806 <<
"Sent validator list for " <<
strHex(publisherKey)
807 <<
" with sequence " << newPeerSequence <<
" to "
850 blobInfos[
current.sequence] = {
852 for (
auto const& [sequence, vl] : remaining)
854 blobInfos[sequence] = {vl.rawBlob, vl.rawSignature, vl.rawManifest};
902 "ripple::ValidatorList::broadcastBlobs : valid sequence");
907 if (toSkip->count(peer->id()) == 0)
909 auto const peerSequence =
910 peer->publisherListSequence(publisherKey).value_or(0);
911 if (peerSequence < maxSequence)
913 if (blobInfos.
empty())
915 auto const v2 = peer->supportsFeature(
925 v2 ? messages2[peerSequence] : messages1,
950 auto const disposition = result.bestDisposition();
977 result.publisherKey &&
983 *result.publisherKey,
985 *pubCollection.maxSequence,
1012 for (
auto const& blobInfo : blobs)
1028 stats.mergeDispositions(result);
1029 result = std::move(stats);
1041 auto& remaining = pubCollection.remaining;
1042 auto const&
current = pubCollection.current;
1043 for (
auto iter = remaining.begin(); iter != remaining.end();)
1047 next == remaining.end() || next->first > iter->first,
1048 "ripple::ValidatorList::applyLists : next is valid");
1049 if (iter->first <=
current.sequence ||
1050 (next != remaining.end() &&
1051 next->second.validFrom <= iter->second.validFrom))
1053 iter = remaining.erase(iter);
1063 pubCollection.fullHash =
sha512Half(pubCollection);
1065 result.
sequence = *pubCollection.maxSequence;
1081 auto iNew = publisherList.
begin();
1082 auto iOld = oldList.
begin();
1083 while (iNew != publisherList.
end() || iOld != oldList.
end())
1085 if (iOld == oldList.
end() ||
1086 (iNew != publisherList.
end() && *iNew < *iOld))
1093 iNew == publisherList.
end() ||
1094 (iOld != oldList.
end() && *iOld < *iNew))
1110 if (publisherList.
empty())
1112 JLOG(
j_.
warn()) <<
"No validator keys included in valid list";
1115 for (
auto const& valManifest : manifests)
1122 <<
" contained untrusted validator manifest";
1130 <<
" contained invalid validator manifest";
1146 using namespace std::string_literals;
1149 auto const&
manifest = localManifest ? *localManifest : globalManifest;
1150 auto [result, pubKeyOpt] =
verify(lock, list,
manifest, blob, signature);
1154 JLOG(
j_.
info()) <<
"ValidatorList::applyList unable to retrieve the "
1155 "master public key from the verify function\n";
1161 JLOG(
j_.
info()) <<
"ValidatorList::applyList Invalid Public Key type"
1162 " retrieved from the verify function\n ";
1172 if (pubCollection.maxSequence &&
1181 pubCollection.status,
1182 *pubCollection.maxSequence};
1190 auto const sequence = list[jss::sequence].
asUInt();
1199 pubCollection.rawManifest = globalManifest;
1200 if (!pubCollection.maxSequence || sequence > *pubCollection.maxSequence)
1201 pubCollection.maxSequence = sequence;
1203 Json::Value const& newList = list[jss::validators];
1205 if (
accepted && pubCollection.remaining.count(sequence) != 0)
1212 auto& publisher = pubCollection.current;
1214 oldList = std::move(pubCollection.current.list);
1216 publisher = std::move(pubCollection.remaining[sequence]);
1218 pubCollection.remaining.erase(sequence);
1221 publisher.sequence == sequence,
1222 "ripple::ValidatorList::applyList : publisher sequence match");
1226 auto& publisher =
accepted ? pubCollection.current
1227 : pubCollection.remaining[sequence];
1228 publisher.sequence = sequence;
1230 list.
isMember(jss::effective) ? list[jss::effective].
asUInt() : 0}};
1233 publisher.siteUri = std::move(siteUri);
1234 publisher.rawBlob = blob;
1235 publisher.rawSignature = signature;
1236 publisher.rawManifest = localManifest;
1238 publisher.hash = *hash;
1244 oldList = std::move(publisherList);
1246 publisherList.
clear();
1248 for (
auto const& val : newList)
1250 if (val.isObject() && val.isMember(jss::validation_public_key) &&
1251 val[jss::validation_public_key].isString())
1254 strUnHex(val[jss::validation_public_key].asString());
1259 <<
"Invalid node identity: "
1260 << val[jss::validation_public_key].asString();
1268 if (val.isMember(jss::manifest) &&
1269 val[jss::manifest].isString())
1270 manifests.
push_back(val[jss::manifest].asString());
1279 pubCollection.rawVersion =
std::max(pubCollection.rawVersion, version);
1280 if (!pubCollection.remaining.empty())
1284 pubCollection.rawVersion =
std::max(pubCollection.rawVersion, 2u);
1288 result, pubKey, pubCollection.status, *pubCollection.maxSequence};
1301 using namespace std::string_literals;
1302 using namespace boost::filesystem;
1303 using namespace boost::system::errc;
1311 boost::system::error_code ec;
1318 auto const fullPath{
canonical(filename, ec)};
1322 auto size = file_size(fullPath, ec);
1335 return fullPath.root_path() ==
"/"s ?
"file://" :
"file:///";
1367 auto const revoked = m->revoked();
1383 auto const sig =
strUnHex(signature);
1389 if (!r.
parse(data, list))
1392 if (list.
isMember(jss::sequence) && list[jss::sequence].
isInt() &&
1393 list.
isMember(jss::expiration) && list[jss::expiration].
isInt() &&
1394 (!list.
isMember(jss::effective) || list[jss::effective].
isInt()) &&
1397 auto const sequence = list[jss::sequence].
asUInt();
1399 list.
isMember(jss::effective) ? list[jss::effective].
asUInt() : 0}};
1404 if (validUntil <= validFrom)
1406 else if (sequence < listCollection.current.sequence)
1408 else if (sequence == listCollection.current.sequence)
1410 else if (validUntil <= now)
1412 else if (validFrom > now)
1423 return !listCollection.maxSequence ||
1424 sequence > *listCollection.maxSequence ||
1425 (listCollection.remaining.count(sequence) == 0 &&
1426 validFrom < listCollection.remaining
1427 .at(*listCollection.maxSequence)
1462 return trusted(read_lock, identity);
1473 return std::nullopt;
1484 return std::nullopt;
1519 "ripple::ValidatorList::removePublisherList : valid reason input");
1524 JLOG(
j_.
debug()) <<
"Removing validator list for publisher "
1527 for (
auto const& val : iList->second.current.list)
1533 if (iVal->second <= 1)
1539 iList->second.current.list.clear();
1540 iList->second.status = reason;
1555 return count(read_lock);
1565 auto const&
current = collection.current;
1568 return std::nullopt;
1574 auto chainedExpiration =
current.validUntil;
1575 for (
auto const& [sequence, check] : collection.remaining)
1578 if (check.validFrom <= chainedExpiration)
1579 chainedExpiration = check.validUntil;
1585 if (!res || chainedExpiration < *res)
1587 res = chainedExpiration;
1595 auto const&
current = collection;
1596 auto chainedExpiration =
current.validUntil;
1599 if (!res || chainedExpiration < *res)
1601 res = chainedExpiration;
1628 if (
auto when =
expires(read_lock))
1630 if (*when == TimeKeeper::time_point::max())
1632 x[jss::expiration] =
"never";
1633 x[jss::status] =
"active";
1640 x[jss::status] =
"active";
1642 x[jss::status] =
"expired";
1647 x[jss::status] =
"unknown";
1648 x[jss::expiration] =
"unknown";
1667 curr[jss::pubkey_publisher] =
strHex(publicKey);
1668 curr[jss::available] =
1673 target[jss::uri] = publisherList.
siteUri;
1683 for (
auto const& key : publisherList.
list)
1689 auto const&
current = pubCollection.current;
1693 curr[jss::version] = pubCollection.rawVersion;
1698 for (
auto const& [sequence, future] : pubCollection.remaining)
1700 using namespace std::chrono_literals;
1704 appendList(future, r);
1708 "ripple::ValidatorList::getJson : minimum valid from");
1710 if (remaining.
size())
1711 curr[jss::remaining] = std::move(remaining);
1717 for (
auto const& k : trustedMasterKeys_)
1724 validatorManifests_.for_each_manifest([&jSigningKeys,
1726 auto it = keyListings_.find(
manifest.masterKey);
1727 if (it != keyListings_.end() &&
manifest.signingKey)
1735 if (!negativeUNL_.empty())
1738 for (
auto const& k : negativeUNL_)
1748ValidatorList::for_each_listed(
1753 for (
auto const& v : keyListings_)
1754 func(v.first, trusted(read_lock, v.first));
1758ValidatorList::for_each_available(
1765 uint256 const& hash)> func)
const
1769 for (
auto const& [key, plCollection] : publisherLists_)
1771 if (plCollection.status != PublisherStatus::available)
1774 plCollection.maxSequence != 0,
1775 "ripple::ValidatorList::for_each_available : nonzero maxSequence");
1777 plCollection.rawManifest,
1778 plCollection.rawVersion,
1779 buildBlobInfos(plCollection),
1781 plCollection.maxSequence.value_or(0),
1782 plCollection.fullHash);
1787ValidatorList::getAvailable(
1797 JLOG(j_.
info()) <<
"Invalid requested validator list publisher key: "
1804 auto const iter = publisherLists_.find(
id);
1806 if (iter == publisherLists_.end() ||
1807 iter->second.status != PublisherStatus::available)
1811 buildFileData(
std::string{pubKey}, iter->second, forceVersion, j_);
1817ValidatorList::calculateQuorum(
1823 if (minimumQuorum_ > 0)
1825 JLOG(j_.
warn()) <<
"Using potentially unsafe quorum of "
1827 <<
" as specified on the command line";
1828 return *minimumQuorum_;
1831 if (!publisherLists_.empty())
1836 for (
auto const& list : publisherLists_)
1838 if (list.second.status != PublisherStatus::available)
1860 auto const errorThreshold =
std::min(
1862 publisherLists_.size() - listThreshold_ + 1);
1865 "ripple::ValidatorList::calculateQuorum : nonzero error threshold");
1909ValidatorList::updateTrusted(
1916 using namespace std::chrono_literals;
1917 if (timeKeeper_.now() > closeTime + 30s)
1918 closeTime = timeKeeper_.now();
1927 for (
auto& [pubKey, collection] : publisherLists_)
1930 auto& remaining = collection.remaining;
1931 auto const firstIter = remaining.begin();
1932 auto iter = firstIter;
1933 if (iter != remaining.end() && iter->second.validFrom <= closeTime)
1936 for (
auto next =
std::next(iter); next != remaining.end() &&
1937 next->second.validFrom <= closeTime;
1942 "ripple::ValidatorList::updateTrusted : sequential "
1946 iter != remaining.end(),
1947 "ripple::ValidatorList::updateTrusted : non-end of "
1951 auto sequence = iter->first;
1952 auto& candidate = iter->second;
1953 auto&
current = collection.current;
1955 candidate.validFrom <= closeTime,
1956 "ripple::ValidatorList::updateTrusted : maximum time");
1958 auto const oldList =
current.list;
1959 current = std::move(candidate);
1960 if (collection.status != PublisherStatus::available)
1961 collection.status = PublisherStatus::available;
1964 "ripple::ValidatorList::updateTrusted : sequence match");
1968 if (
current.validUntil <= closeTime)
1971 updatePublisherList(pubKey,
current, oldList, lock);
1988 remaining.erase(firstIter,
std::next(iter));
1994 if (collection.status == PublisherStatus::available &&
1995 collection.current.validUntil <= closeTime)
1997 removePublisherList(lock, pubKey, PublisherStatus::expired);
2000 if (collection.status != PublisherStatus::available)
2008 auto it = trustedMasterKeys_.cbegin();
2009 while (it != trustedMasterKeys_.cend())
2011 auto const kit = keyListings_.find(*it);
2012 if (kit == keyListings_.end() ||
2013 kit->second < listThreshold_ ||
2014 validatorManifests_.revoked(*it))
2017 it = trustedMasterKeys_.erase(it);
2022 kit->second >= listThreshold_,
2023 "ripple::ValidatorList::updateTrusted : count meets threshold");
2028 for (
auto const& val : keyListings_)
2030 if (val.second >= listThreshold_ &&
2031 !validatorManifests_.revoked(val.first) &&
2032 trustedMasterKeys_.emplace(val.first).second)
2038 if (!trustChanges.
added.empty() || !trustChanges.
removed.empty())
2040 trustedSigningKeys_.clear();
2044 for (
auto const& k : trustedMasterKeys_)
2047 validatorManifests_.getSigningKey(k);
2050 "ripple::ValidatorList::updateTrusted : found signing key");
2051 trustedSigningKeys_.insert(*signingKey);
2056 << trustedMasterKeys_.size() <<
" of " << keyListings_.size()
2057 <<
" listed validators eligible for inclusion in the trusted set";
2059 auto const unlSize = trustedMasterKeys_.size();
2060 auto effectiveUnlSize = unlSize;
2061 auto seenSize = seenValidators.
size();
2062 if (!negativeUNL_.empty())
2064 for (
auto const& k : trustedMasterKeys_)
2066 if (negativeUNL_.count(k))
2070 for (
auto const& k : negativeUNL_)
2074 for (
auto const& nid : seenValidators)
2076 if (negUnlNodeIDs.
count(nid))
2080 quorum_ = calculateQuorum(unlSize, effectiveUnlSize, seenSize);
2082 JLOG(j_.
debug()) <<
"Using quorum of " << quorum_ <<
" for new set of "
2083 << unlSize <<
" trusted validators ("
2084 << trustChanges.
added.size() <<
" added, "
2085 << trustChanges.
removed.size() <<
" removed)";
2087 if (unlSize < quorum_)
2089 JLOG(j_.
warn()) <<
"New quorum of " << quorum_
2090 <<
" exceeds the number of trusted validators ("
2094 if ((publisherLists_.size() || localPublisherList.list.size()) &&
2101 return trustChanges;
2105ValidatorList::getTrustedMasterKeys()
const
2108 return trustedMasterKeys_;
2112ValidatorList::getListThreshold()
const
2115 return listThreshold_;
2119ValidatorList::getNegativeUNL()
const
2122 return negativeUNL_;
2129 negativeUNL_ = negUnl;
2133ValidatorList::negativeUNLFilter(
2137 auto ret = std::move(validations);
2140 if (!negativeUNL_.empty())
2146 [&](
auto const& v) ->
bool {
2147 if (auto const masterKey =
2148 getTrustedKey(read_lock, v->getSignerPublic());
2151 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.
UInt size() const
Number of values in array or object.
std::string toStyledString() const
Value & append(const Value &value)
Append value to array at the end.
std::string asString() const
Returns the unquoted string value.
bool isMember(const char *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...
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)
static const std::string filePrefix_
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