Skip to content

Commit

Permalink
Specify source type for stored UNLs
Browse files Browse the repository at this point in the history
  • Loading branch information
undertome committed Nov 17, 2021
1 parent 5d44998 commit 2e88564
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 20 deletions.
27 changes: 18 additions & 9 deletions src/ripple/app/misc/ValidatorList.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ class ValidatorList
std::size_t sequence;
TimeKeeper::time_point validFrom;
TimeKeeper::time_point validUntil;
std::string siteUri;
// the peer that provided the list, if applicable
std::string sourcePeer;
// the website or filesystem uri that provided the list, if applicable
std::string sourceUri;
// base-64 encoded JSON containing the validator list.
std::string rawBlob;
// hex-encoded signature of the blob using the publisher's signing key
Expand Down Expand Up @@ -382,7 +385,9 @@ class ValidatorList
@param blobs Vector of BlobInfos representing one or more encoded
validator lists and signatures (and optional manifests)
@param siteUri Uri of the site from which the list was validated
@param source The peer address, or site/file uri that provided the
lists. The formatting of this parameter is important as it is
used to determine the source type
@param hash Hash of the data parameters
Expand All @@ -406,7 +411,7 @@ class ValidatorList
std::string const& manifest,
std::uint32_t version,
std::vector<ValidatorBlobInfo> const& blobs,
std::string siteUri,
std::string source,
uint256 const& hash,
Overlay& overlay,
HashRouter& hashRouter,
Expand All @@ -419,14 +424,16 @@ class ValidatorList
@param version Version of published list format
@param blobs Vector of BlobInfos representing one or more encoded
validator lists and signatures (and optional manifests)
validator lists and signatures (and optional manifests)
@param siteUri Uri of the site from which the list was validated
@param source The peer address, or site/file uri that provided the
lists. The formatting of this parameter is important as it is
used to determine the source type
@param hash Optional hash of the data parameters
@return `ListDisposition::accepted`, plus some of the publisher
information, if list was successfully applied
information, if list was successfully applied
@par Thread Safety
Expand All @@ -437,7 +444,7 @@ class ValidatorList
std::string const& manifest,
std::uint32_t version,
std::vector<ValidatorBlobInfo> const& blobs,
std::string siteUri,
std::string source,
std::optional<uint256> const& hash = {});

/* Attempt to read previously stored list files. Expected to only be
Expand Down Expand Up @@ -743,7 +750,9 @@ class ValidatorList
@param version Version of published list format
@param siteUri Uri of the site from which the list was validated
@param source The peer address, or site/file uri that provided the
lists. The formatting of this parameter is important as it is
used to determine the source type
@param hash Optional hash of the data parameters.
Defaults to uninitialized
Expand All @@ -762,7 +771,7 @@ class ValidatorList
std::string const& blob,
std::string const& signature,
std::uint32_t version,
std::string siteUri,
std::string source,
std::optional<uint256> const& hash,
lock_guard const&);

Expand Down
36 changes: 29 additions & 7 deletions src/ripple/app/misc/impl/ValidatorList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@

namespace ripple {

bool
isSite(std::string const& source)
{
parsedURL parsed;
if (!parseUrl(parsed, source))
// Assume that the source is a peer address in the
// event that parsing fails.
return false;

const std::unordered_set<std::string> schemes{"file", "http", "https"};

if (schemes.find(parsed.scheme) != schemes.end())
return true;

return false;
}

std::string
to_string(ListDisposition disposition)
{
Expand Down Expand Up @@ -870,14 +887,14 @@ ValidatorList::applyListsAndBroadcast(
std::string const& manifest,
std::uint32_t version,
std::vector<ValidatorBlobInfo> const& blobs,
std::string siteUri,
std::string source,
uint256 const& hash,
Overlay& overlay,
HashRouter& hashRouter,
NetworkOPs& networkOPs)
{
auto const result =
applyLists(manifest, version, blobs, std::move(siteUri), hash);
applyLists(manifest, version, blobs, std::move(source), hash);
auto const disposition = result.bestDisposition();

if (disposition == ListDisposition::accepted)
Expand Down Expand Up @@ -923,7 +940,7 @@ ValidatorList::applyLists(
std::string const& manifest,
std::uint32_t version,
std::vector<ValidatorBlobInfo> const& blobs,
std::string siteUri,
std::string source,
std::optional<uint256> const& hash /* = {} */)
{
if (std::count(
Expand All @@ -943,7 +960,7 @@ ValidatorList::applyLists(
blobInfo.blob,
blobInfo.signature,
version,
siteUri,
source,
hash,
lock);

Expand Down Expand Up @@ -1063,7 +1080,7 @@ ValidatorList::applyList(
std::string const& blob,
std::string const& signature,
std::uint32_t version,
std::string siteUri,
std::string source,
std::optional<uint256> const& hash,
ValidatorList::lock_guard const& lock)
{
Expand Down Expand Up @@ -1137,7 +1154,9 @@ ValidatorList::applyList(
list.isMember(jss::effective) ? list[jss::effective].asUInt() : 0}};
publisher.validUntil = TimeKeeper::time_point{
TimeKeeper::duration{list[jss::expiration].asUInt()}};
publisher.siteUri = std::move(siteUri);
auto& sourceField =
isSite(source) ? publisher.sourceUri : publisher.sourcePeer;
sourceField = std::move(source);
publisher.rawBlob = blob;
publisher.rawSignature = signature;
publisher.rawManifest = localManifest;
Expand Down Expand Up @@ -1565,7 +1584,10 @@ ValidatorList::getJson() const

auto appendList = [](PublisherList const& publisherList,
Json::Value& target) {
target[jss::uri] = publisherList.siteUri;
if (!publisherList.sourceUri.empty())
target[jss::source_uri] = publisherList.sourceUri;
if (!publisherList.sourcePeer.empty())
target[jss::source_peer] = publisherList.sourcePeer;
if (publisherList.validUntil != TimeKeeper::time_point{})
{
target[jss::seq] =
Expand Down
2 changes: 2 additions & 0 deletions src/ripple/protocol/jss.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,9 @@ JSS(snapshot); // in: Subscribe
JSS(source_account); // in: PathRequest, RipplePathFind
JSS(source_amount); // in: PathRequest, RipplePathFind
JSS(source_currencies); // in: PathRequest, RipplePathFind
JSS(source_peer); // out: ValidatorSites
JSS(source_tag); // out: AccountChannels
JSS(source_uri); // out: ValidatorSites
JSS(stand_alone); // out: NetworkOPs
JSS(start); // in: TxHistory
JSS(started);
Expand Down
8 changes: 4 additions & 4 deletions src/test/app/ValidatorList_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ class ValidatorList_test : public beast::unit_test::suite
testcase("Apply list");
using namespace std::chrono_literals;

std::string const siteUri = "testApplyList.test";
std::string const siteUri = "http://testApplyList.test";

auto checkAvailable =
[this](
Expand Down Expand Up @@ -926,7 +926,7 @@ class ValidatorList_test : public beast::unit_test::suite
testcase("GetAvailable");
using namespace std::chrono_literals;

std::string const siteUri = "testApplyList.test";
std::string const siteUri = "http://testApplyList.test";

ManifestCache manifests;
jtx::Env env(*this);
Expand Down Expand Up @@ -1062,7 +1062,7 @@ class ValidatorList_test : public beast::unit_test::suite
{
testcase("Update trusted");

std::string const siteUri = "testUpdateTrusted.test";
std::string const siteUri = "http://testUpdateTrusted.test";

PublicKey emptyLocalKeyOuter;
ManifestCache manifestsOuter;
Expand Down Expand Up @@ -1615,7 +1615,7 @@ class ValidatorList_test : public beast::unit_test::suite
{
testcase("Expires");

std::string const siteUri = "testExpires.test";
std::string const siteUri = "http://testExpires.test";

jtx::Env env(*this);
auto& app = env.app();
Expand Down

0 comments on commit 2e88564

Please sign in to comment.