mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Format first-party source according to .clang-format
This commit is contained in:
committed by
manojsdoshi
parent
65dfc5d19e
commit
50760c6935
@@ -22,8 +22,8 @@
|
||||
#include <ripple/app/misc/detail/WorkFile.h>
|
||||
#include <ripple/app/misc/detail/WorkPlain.h>
|
||||
#include <ripple/app/misc/detail/WorkSSL.h>
|
||||
#include <ripple/basics/base64.h>
|
||||
#include <ripple/basics/Slice.h>
|
||||
#include <ripple/basics/base64.h>
|
||||
#include <ripple/json/json_reader.h>
|
||||
#include <ripple/protocol/digest.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
@@ -33,17 +33,16 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
auto constexpr default_refresh_interval = std::chrono::minutes{5};
|
||||
auto constexpr error_retry_interval = std::chrono::seconds{30};
|
||||
unsigned short constexpr max_redirects = 3;
|
||||
auto constexpr default_refresh_interval = std::chrono::minutes{5};
|
||||
auto constexpr error_retry_interval = std::chrono::seconds{30};
|
||||
unsigned short constexpr max_redirects = 3;
|
||||
|
||||
ValidatorSite::Site::Resource::Resource (std::string uri_)
|
||||
: uri {std::move(uri_)}
|
||||
ValidatorSite::Site::Resource::Resource(std::string uri_) : uri{std::move(uri_)}
|
||||
{
|
||||
if (! parseUrl (pUrl, uri))
|
||||
if (!parseUrl(pUrl, uri))
|
||||
throw std::runtime_error("URI '" + uri + "' cannot be parsed");
|
||||
|
||||
if (pUrl.scheme == "file")
|
||||
if (pUrl.scheme == "file")
|
||||
{
|
||||
if (!pUrl.domain.empty())
|
||||
throw std::runtime_error("file URI cannot contain a hostname");
|
||||
@@ -74,29 +73,29 @@ ValidatorSite::Site::Resource::Resource (std::string uri_)
|
||||
pUrl.port = 443;
|
||||
}
|
||||
else
|
||||
throw std::runtime_error ("Unsupported scheme: '" + pUrl.scheme + "'");
|
||||
throw std::runtime_error("Unsupported scheme: '" + pUrl.scheme + "'");
|
||||
}
|
||||
|
||||
ValidatorSite::Site::Site (std::string uri)
|
||||
: loadedResource {std::make_shared<Resource>(std::move(uri))}
|
||||
, startingResource {loadedResource}
|
||||
, redirCount {0}
|
||||
, refreshInterval {default_refresh_interval}
|
||||
, nextRefresh {clock_type::now()}
|
||||
ValidatorSite::Site::Site(std::string uri)
|
||||
: loadedResource{std::make_shared<Resource>(std::move(uri))}
|
||||
, startingResource{loadedResource}
|
||||
, redirCount{0}
|
||||
, refreshInterval{default_refresh_interval}
|
||||
, nextRefresh{clock_type::now()}
|
||||
{
|
||||
}
|
||||
|
||||
ValidatorSite::ValidatorSite (
|
||||
ValidatorSite::ValidatorSite(
|
||||
Application& app,
|
||||
boost::optional<beast::Journal> j,
|
||||
std::chrono::seconds timeout)
|
||||
: app_ {app}
|
||||
, j_ {j ? *j : app_.logs().journal("ValidatorSite") }
|
||||
, timer_ {app_.getIOService()}
|
||||
, fetching_ {false}
|
||||
, pending_ {false}
|
||||
, stopping_ {false}
|
||||
, requestTimeout_ {timeout}
|
||||
: app_{app}
|
||||
, j_{j ? *j : app_.logs().journal("ValidatorSite")}
|
||||
, timer_{app_.getIOService()}
|
||||
, fetching_{false}
|
||||
, pending_{false}
|
||||
, stopping_{false}
|
||||
, requestTimeout_{timeout}
|
||||
{
|
||||
}
|
||||
|
||||
@@ -105,14 +104,14 @@ ValidatorSite::~ValidatorSite()
|
||||
std::unique_lock<std::mutex> lock{state_mutex_};
|
||||
if (timer_.expires_at() > clock_type::time_point{})
|
||||
{
|
||||
if (! stopping_)
|
||||
if (!stopping_)
|
||||
{
|
||||
lock.unlock();
|
||||
stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
cv_.wait(lock, [&]{ return ! fetching_; });
|
||||
cv_.wait(lock, [&] { return !fetching_; });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,8 +124,7 @@ ValidatorSite::missingSite()
|
||||
}
|
||||
|
||||
bool
|
||||
ValidatorSite::load (
|
||||
std::vector<std::string> const& siteURIs)
|
||||
ValidatorSite::load(std::vector<std::string> const& siteURIs)
|
||||
{
|
||||
// If no sites are provided, act as if a site failed to load.
|
||||
if (siteURIs.empty())
|
||||
@@ -134,8 +132,7 @@ ValidatorSite::load (
|
||||
return missingSite();
|
||||
}
|
||||
|
||||
JLOG (j_.debug()) <<
|
||||
"Loading configured validator list sites";
|
||||
JLOG(j_.debug()) << "Loading configured validator list sites";
|
||||
|
||||
std::lock_guard lock{sites_mutex_};
|
||||
|
||||
@@ -143,36 +140,34 @@ ValidatorSite::load (
|
||||
{
|
||||
try
|
||||
{
|
||||
sites_.emplace_back (uri);
|
||||
sites_.emplace_back(uri);
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
JLOG (j_.error()) <<
|
||||
"Invalid validator site uri: " << uri <<
|
||||
": " << e.what();
|
||||
JLOG(j_.error())
|
||||
<< "Invalid validator site uri: " << uri << ": " << e.what();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
JLOG (j_.debug()) <<
|
||||
"Loaded " << siteURIs.size() << " sites";
|
||||
JLOG(j_.debug()) << "Loaded " << siteURIs.size() << " sites";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
ValidatorSite::start ()
|
||||
ValidatorSite::start()
|
||||
{
|
||||
std::lock_guard lock{state_mutex_};
|
||||
if (timer_.expires_at() == clock_type::time_point{})
|
||||
setTimer (lock);
|
||||
setTimer(lock);
|
||||
}
|
||||
|
||||
void
|
||||
ValidatorSite::join ()
|
||||
ValidatorSite::join()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock{state_mutex_};
|
||||
cv_.wait(lock, [&]{ return ! pending_; });
|
||||
cv_.wait(lock, [&] { return !pending_; });
|
||||
}
|
||||
|
||||
void
|
||||
@@ -183,9 +178,9 @@ ValidatorSite::stop()
|
||||
// work::cancel() must be called before the
|
||||
// cv wait in order to kick any asio async operations
|
||||
// that might be pending.
|
||||
if(auto sp = work_.lock())
|
||||
if (auto sp = work_.lock())
|
||||
sp->cancel();
|
||||
cv_.wait(lock, [&]{ return ! fetching_; });
|
||||
cv_.wait(lock, [&] { return !fetching_; });
|
||||
|
||||
// docs indicate cancel() can throw, but this should be
|
||||
// reconsidered if it changes to noexcept
|
||||
@@ -202,31 +197,29 @@ ValidatorSite::stop()
|
||||
}
|
||||
|
||||
void
|
||||
ValidatorSite::setTimer (std::lock_guard<std::mutex>& state_lock)
|
||||
ValidatorSite::setTimer(std::lock_guard<std::mutex>& state_lock)
|
||||
{
|
||||
std::lock_guard lock{sites_mutex_};
|
||||
|
||||
auto next = std::min_element(sites_.begin(), sites_.end(),
|
||||
[](Site const& a, Site const& b)
|
||||
{
|
||||
auto next = std::min_element(
|
||||
sites_.begin(), sites_.end(), [](Site const& a, Site const& b) {
|
||||
return a.nextRefresh < b.nextRefresh;
|
||||
});
|
||||
|
||||
if (next != sites_.end ())
|
||||
if (next != sites_.end())
|
||||
{
|
||||
pending_ = next->nextRefresh <= clock_type::now();
|
||||
cv_.notify_all();
|
||||
timer_.expires_at (next->nextRefresh);
|
||||
auto idx = std::distance (sites_.begin (), next);
|
||||
timer_.async_wait ([this, idx] (boost::system::error_code const& ec)
|
||||
{
|
||||
this->onTimer (idx, ec);
|
||||
timer_.expires_at(next->nextRefresh);
|
||||
auto idx = std::distance(sites_.begin(), next);
|
||||
timer_.async_wait([this, idx](boost::system::error_code const& ec) {
|
||||
this->onTimer(idx, ec);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ValidatorSite::makeRequest (
|
||||
ValidatorSite::makeRequest(
|
||||
std::shared_ptr<Site::Resource> resource,
|
||||
std::size_t siteIdx,
|
||||
std::lock_guard<std::mutex>& sites_lock)
|
||||
@@ -234,37 +227,31 @@ ValidatorSite::makeRequest (
|
||||
fetching_ = true;
|
||||
sites_[siteIdx].activeResource = resource;
|
||||
std::shared_ptr<detail::Work> sp;
|
||||
auto timeoutCancel =
|
||||
[this] ()
|
||||
auto timeoutCancel = [this]() {
|
||||
std::lock_guard lock_state{state_mutex_};
|
||||
// docs indicate cancel_one() can throw, but this
|
||||
// should be reconsidered if it changes to noexcept
|
||||
try
|
||||
{
|
||||
std::lock_guard lock_state{state_mutex_};
|
||||
// docs indicate cancel_one() can throw, but this
|
||||
// should be reconsidered if it changes to noexcept
|
||||
try
|
||||
{
|
||||
timer_.cancel_one();
|
||||
}
|
||||
catch (boost::system::system_error const&)
|
||||
{
|
||||
}
|
||||
};
|
||||
auto onFetch =
|
||||
[this, siteIdx, timeoutCancel] (
|
||||
error_code const& err, detail::response_type&& resp)
|
||||
timer_.cancel_one();
|
||||
}
|
||||
catch (boost::system::system_error const&)
|
||||
{
|
||||
timeoutCancel ();
|
||||
onSiteFetch (err, std::move(resp), siteIdx);
|
||||
};
|
||||
}
|
||||
};
|
||||
auto onFetch = [this, siteIdx, timeoutCancel](
|
||||
error_code const& err, detail::response_type&& resp) {
|
||||
timeoutCancel();
|
||||
onSiteFetch(err, std::move(resp), siteIdx);
|
||||
};
|
||||
|
||||
auto onFetchFile =
|
||||
[this, siteIdx, timeoutCancel] (
|
||||
error_code const& err, std::string const& resp)
|
||||
{
|
||||
timeoutCancel ();
|
||||
onTextFetch (err, resp, siteIdx);
|
||||
};
|
||||
auto onFetchFile = [this, siteIdx, timeoutCancel](
|
||||
error_code const& err, std::string const& resp) {
|
||||
timeoutCancel();
|
||||
onTextFetch(err, resp, siteIdx);
|
||||
};
|
||||
|
||||
JLOG (j_.debug()) << "Starting request for " << resource->uri;
|
||||
JLOG(j_.debug()) << "Starting request for " << resource->uri;
|
||||
|
||||
if (resource->pUrl.scheme == "https")
|
||||
{
|
||||
@@ -278,7 +265,7 @@ ValidatorSite::makeRequest (
|
||||
app_.config(),
|
||||
onFetch);
|
||||
}
|
||||
else if(resource->pUrl.scheme == "http")
|
||||
else if (resource->pUrl.scheme == "http")
|
||||
{
|
||||
sp = std::make_shared<detail::WorkPlain>(
|
||||
resource->pUrl.domain,
|
||||
@@ -291,54 +278,46 @@ ValidatorSite::makeRequest (
|
||||
{
|
||||
BOOST_ASSERT(resource->pUrl.scheme == "file");
|
||||
sp = std::make_shared<detail::WorkFile>(
|
||||
resource->pUrl.path,
|
||||
app_.getIOService(),
|
||||
onFetchFile);
|
||||
resource->pUrl.path, app_.getIOService(), onFetchFile);
|
||||
}
|
||||
|
||||
work_ = sp;
|
||||
sp->run ();
|
||||
sp->run();
|
||||
// start a timer for the request, which shouldn't take more
|
||||
// than requestTimeout_ to complete
|
||||
std::lock_guard lock_state{state_mutex_};
|
||||
timer_.expires_after (requestTimeout_);
|
||||
timer_.async_wait ([this, siteIdx] (boost::system::error_code const& ec)
|
||||
{
|
||||
this->onRequestTimeout (siteIdx, ec);
|
||||
});
|
||||
timer_.expires_after(requestTimeout_);
|
||||
timer_.async_wait([this, siteIdx](boost::system::error_code const& ec) {
|
||||
this->onRequestTimeout(siteIdx, ec);
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
ValidatorSite::onRequestTimeout (
|
||||
std::size_t siteIdx,
|
||||
error_code const& ec)
|
||||
ValidatorSite::onRequestTimeout(std::size_t siteIdx, error_code const& ec)
|
||||
{
|
||||
if (ec)
|
||||
return;
|
||||
|
||||
{
|
||||
std::lock_guard lock_site{sites_mutex_};
|
||||
JLOG (j_.warn()) <<
|
||||
"Request for " << sites_[siteIdx].activeResource->uri <<
|
||||
" took too long";
|
||||
JLOG(j_.warn()) << "Request for " << sites_[siteIdx].activeResource->uri
|
||||
<< " took too long";
|
||||
}
|
||||
|
||||
std::lock_guard lock_state{state_mutex_};
|
||||
if(auto sp = work_.lock())
|
||||
if (auto sp = work_.lock())
|
||||
sp->cancel();
|
||||
}
|
||||
|
||||
void
|
||||
ValidatorSite::onTimer (
|
||||
std::size_t siteIdx,
|
||||
error_code const& ec)
|
||||
ValidatorSite::onTimer(std::size_t siteIdx, error_code const& ec)
|
||||
{
|
||||
if (ec)
|
||||
{
|
||||
// Restart the timer if any errors are encountered, unless the error
|
||||
// is from the wait operating being aborted due to a shutdown request.
|
||||
if (ec != boost::asio::error::operation_aborted)
|
||||
onSiteFetch(ec, detail::response_type {}, siteIdx);
|
||||
onSiteFetch(ec, detail::response_type{}, siteIdx);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -351,50 +330,48 @@ ValidatorSite::onTimer (
|
||||
// the WorkSSL client ctor can throw if SSL init fails
|
||||
makeRequest(sites_[siteIdx].startingResource, siteIdx, lock);
|
||||
}
|
||||
catch (std::exception &)
|
||||
catch (std::exception&)
|
||||
{
|
||||
onSiteFetch(
|
||||
boost::system::error_code {-1, boost::system::generic_category()},
|
||||
detail::response_type {},
|
||||
boost::system::error_code{-1, boost::system::generic_category()},
|
||||
detail::response_type{},
|
||||
siteIdx);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ValidatorSite::parseJsonResponse (
|
||||
ValidatorSite::parseJsonResponse(
|
||||
std::string const& res,
|
||||
std::size_t siteIdx,
|
||||
std::lock_guard<std::mutex>& sites_lock)
|
||||
{
|
||||
Json::Reader r;
|
||||
Json::Value body;
|
||||
if (! r.parse(res.data(), body))
|
||||
if (!r.parse(res.data(), body))
|
||||
{
|
||||
JLOG (j_.warn()) <<
|
||||
"Unable to parse JSON response from " <<
|
||||
sites_[siteIdx].activeResource->uri;
|
||||
JLOG(j_.warn()) << "Unable to parse JSON response from "
|
||||
<< sites_[siteIdx].activeResource->uri;
|
||||
throw std::runtime_error{"bad json"};
|
||||
}
|
||||
|
||||
if( ! body.isObject () ||
|
||||
! body.isMember("blob") || ! body["blob"].isString () ||
|
||||
! body.isMember("manifest") || ! body["manifest"].isString () ||
|
||||
! body.isMember("signature") || ! body["signature"].isString() ||
|
||||
! body.isMember("version") || ! body["version"].isInt())
|
||||
if (!body.isObject() || !body.isMember("blob") ||
|
||||
!body["blob"].isString() || !body.isMember("manifest") ||
|
||||
!body["manifest"].isString() || !body.isMember("signature") ||
|
||||
!body["signature"].isString() || !body.isMember("version") ||
|
||||
!body["version"].isInt())
|
||||
{
|
||||
JLOG (j_.warn()) <<
|
||||
"Missing fields in JSON response from " <<
|
||||
sites_[siteIdx].activeResource->uri;
|
||||
JLOG(j_.warn()) << "Missing fields in JSON response from "
|
||||
<< sites_[siteIdx].activeResource->uri;
|
||||
throw std::runtime_error{"missing fields"};
|
||||
}
|
||||
|
||||
auto const manifest = body["manifest"].asString ();
|
||||
auto const blob = body["blob"].asString ();
|
||||
auto const manifest = body["manifest"].asString();
|
||||
auto const blob = body["blob"].asString();
|
||||
auto const signature = body["signature"].asString();
|
||||
auto const version = body["version"].asUInt();
|
||||
auto const& uri = sites_[siteIdx].activeResource->uri;
|
||||
auto const hash = sha512Half(manifest, blob, signature, version);
|
||||
auto const applyResult = app_.validators().applyListAndBroadcast (
|
||||
auto const applyResult = app_.validators().applyListAndBroadcast(
|
||||
manifest,
|
||||
blob,
|
||||
signature,
|
||||
@@ -410,49 +387,36 @@ ValidatorSite::parseJsonResponse (
|
||||
|
||||
switch (disp)
|
||||
{
|
||||
case ListDisposition::accepted:
|
||||
JLOG (j_.debug()) <<
|
||||
"Applied new validator list from " <<
|
||||
uri;
|
||||
break;
|
||||
case ListDisposition::same_sequence:
|
||||
JLOG (j_.debug()) <<
|
||||
"Validator list with current sequence from " <<
|
||||
uri;
|
||||
break;
|
||||
case ListDisposition::stale:
|
||||
JLOG (j_.warn()) <<
|
||||
"Stale validator list from " <<
|
||||
uri;
|
||||
break;
|
||||
case ListDisposition::untrusted:
|
||||
JLOG (j_.warn()) <<
|
||||
"Untrusted validator list from " <<
|
||||
uri;
|
||||
break;
|
||||
case ListDisposition::invalid:
|
||||
JLOG (j_.warn()) <<
|
||||
"Invalid validator list from " <<
|
||||
uri;
|
||||
break;
|
||||
case ListDisposition::unsupported_version:
|
||||
JLOG (j_.warn()) <<
|
||||
"Unsupported version validator list from " <<
|
||||
uri;
|
||||
break;
|
||||
default:
|
||||
BOOST_ASSERT(false);
|
||||
case ListDisposition::accepted:
|
||||
JLOG(j_.debug()) << "Applied new validator list from " << uri;
|
||||
break;
|
||||
case ListDisposition::same_sequence:
|
||||
JLOG(j_.debug())
|
||||
<< "Validator list with current sequence from " << uri;
|
||||
break;
|
||||
case ListDisposition::stale:
|
||||
JLOG(j_.warn()) << "Stale validator list from " << uri;
|
||||
break;
|
||||
case ListDisposition::untrusted:
|
||||
JLOG(j_.warn()) << "Untrusted validator list from " << uri;
|
||||
break;
|
||||
case ListDisposition::invalid:
|
||||
JLOG(j_.warn()) << "Invalid validator list from " << uri;
|
||||
break;
|
||||
case ListDisposition::unsupported_version:
|
||||
JLOG(j_.warn())
|
||||
<< "Unsupported version validator list from " << uri;
|
||||
break;
|
||||
default:
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
|
||||
if (body.isMember ("refresh_interval") &&
|
||||
body["refresh_interval"].isNumeric ())
|
||||
if (body.isMember("refresh_interval") &&
|
||||
body["refresh_interval"].isNumeric())
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
std::chrono::minutes const refresh =
|
||||
boost::algorithm::clamp(
|
||||
std::chrono::minutes {body["refresh_interval"].asUInt ()},
|
||||
1min,
|
||||
24h);
|
||||
std::chrono::minutes const refresh = boost::algorithm::clamp(
|
||||
std::chrono::minutes{body["refresh_interval"].asUInt()}, 1min, 24h);
|
||||
sites_[siteIdx].refreshInterval = refresh;
|
||||
sites_[siteIdx].nextRefresh =
|
||||
clock_type::now() + sites_[siteIdx].refreshInterval;
|
||||
@@ -460,50 +424,46 @@ ValidatorSite::parseJsonResponse (
|
||||
}
|
||||
|
||||
std::shared_ptr<ValidatorSite::Site::Resource>
|
||||
ValidatorSite::processRedirect (
|
||||
ValidatorSite::processRedirect(
|
||||
detail::response_type& res,
|
||||
std::size_t siteIdx,
|
||||
std::lock_guard<std::mutex>& sites_lock)
|
||||
{
|
||||
using namespace boost::beast::http;
|
||||
std::shared_ptr<Site::Resource> newLocation;
|
||||
if (res.find(field::location) == res.end() ||
|
||||
res[field::location].empty())
|
||||
if (res.find(field::location) == res.end() || res[field::location].empty())
|
||||
{
|
||||
JLOG (j_.warn()) <<
|
||||
"Request for validator list at " <<
|
||||
sites_[siteIdx].activeResource->uri <<
|
||||
" returned a redirect with no Location.";
|
||||
JLOG(j_.warn()) << "Request for validator list at "
|
||||
<< sites_[siteIdx].activeResource->uri
|
||||
<< " returned a redirect with no Location.";
|
||||
throw std::runtime_error{"missing location"};
|
||||
}
|
||||
|
||||
if (sites_[siteIdx].redirCount == max_redirects)
|
||||
{
|
||||
JLOG (j_.warn()) <<
|
||||
"Exceeded max redirects for validator list at " <<
|
||||
sites_[siteIdx].loadedResource->uri ;
|
||||
JLOG(j_.warn()) << "Exceeded max redirects for validator list at "
|
||||
<< sites_[siteIdx].loadedResource->uri;
|
||||
throw std::runtime_error{"max redirects"};
|
||||
}
|
||||
|
||||
JLOG (j_.debug()) <<
|
||||
"Got redirect for validator list from " <<
|
||||
sites_[siteIdx].activeResource->uri <<
|
||||
" to new location " << res[field::location];
|
||||
JLOG(j_.debug()) << "Got redirect for validator list from "
|
||||
<< sites_[siteIdx].activeResource->uri
|
||||
<< " to new location " << res[field::location];
|
||||
|
||||
try
|
||||
{
|
||||
newLocation = std::make_shared<Site::Resource>(
|
||||
std::string(res[field::location]));
|
||||
newLocation =
|
||||
std::make_shared<Site::Resource>(std::string(res[field::location]));
|
||||
++sites_[siteIdx].redirCount;
|
||||
if (newLocation->pUrl.scheme != "http" &&
|
||||
newLocation->pUrl.scheme != "https")
|
||||
throw std::runtime_error("invalid scheme in redirect " +
|
||||
newLocation->pUrl.scheme);
|
||||
throw std::runtime_error(
|
||||
"invalid scheme in redirect " + newLocation->pUrl.scheme);
|
||||
}
|
||||
catch (std::exception &)
|
||||
catch (std::exception&)
|
||||
{
|
||||
JLOG (j_.error()) <<
|
||||
"Invalid redirect location: " << res[field::location];
|
||||
JLOG(j_.error()) << "Invalid redirect location: "
|
||||
<< res[field::location];
|
||||
throw;
|
||||
}
|
||||
return newLocation;
|
||||
@@ -517,17 +477,14 @@ ValidatorSite::onSiteFetch(
|
||||
{
|
||||
{
|
||||
std::lock_guard lock_sites{sites_mutex_};
|
||||
JLOG (j_.debug()) << "Got completion for "
|
||||
<< sites_[siteIdx].activeResource->uri;
|
||||
auto onError = [&](std::string const& errMsg, bool retry)
|
||||
{
|
||||
sites_[siteIdx].lastRefreshStatus.emplace(
|
||||
Site::Status{clock_type::now(),
|
||||
ListDisposition::invalid,
|
||||
errMsg});
|
||||
JLOG(j_.debug()) << "Got completion for "
|
||||
<< sites_[siteIdx].activeResource->uri;
|
||||
auto onError = [&](std::string const& errMsg, bool retry) {
|
||||
sites_[siteIdx].lastRefreshStatus.emplace(Site::Status{
|
||||
clock_type::now(), ListDisposition::invalid, errMsg});
|
||||
if (retry)
|
||||
sites_[siteIdx].nextRefresh =
|
||||
clock_type::now() + error_retry_interval;
|
||||
clock_type::now() + error_retry_interval;
|
||||
|
||||
// See if there's a copy saved locally from last time we
|
||||
// saw the list.
|
||||
@@ -535,13 +492,9 @@ ValidatorSite::onSiteFetch(
|
||||
};
|
||||
if (ec)
|
||||
{
|
||||
JLOG (j_.warn()) <<
|
||||
"Problem retrieving from " <<
|
||||
sites_[siteIdx].activeResource->uri <<
|
||||
" " <<
|
||||
ec.value() <<
|
||||
":" <<
|
||||
ec.message();
|
||||
JLOG(j_.warn()) << "Problem retrieving from "
|
||||
<< sites_[siteIdx].activeResource->uri << " "
|
||||
<< ec.value() << ":" << ec.message();
|
||||
onError("fetch error", true);
|
||||
}
|
||||
else
|
||||
@@ -551,36 +504,33 @@ ValidatorSite::onSiteFetch(
|
||||
using namespace boost::beast::http;
|
||||
switch (res.result())
|
||||
{
|
||||
case status::ok:
|
||||
parseJsonResponse(res.body(), siteIdx, lock_sites);
|
||||
break;
|
||||
case status::moved_permanently :
|
||||
case status::permanent_redirect :
|
||||
case status::found :
|
||||
case status::temporary_redirect :
|
||||
{
|
||||
auto newLocation =
|
||||
processRedirect (res, siteIdx, lock_sites);
|
||||
assert(newLocation);
|
||||
// for perm redirects, also update our starting URI
|
||||
if (res.result() == status::moved_permanently ||
|
||||
res.result() == status::permanent_redirect)
|
||||
{
|
||||
sites_[siteIdx].startingResource = newLocation;
|
||||
case status::ok:
|
||||
parseJsonResponse(res.body(), siteIdx, lock_sites);
|
||||
break;
|
||||
case status::moved_permanently:
|
||||
case status::permanent_redirect:
|
||||
case status::found:
|
||||
case status::temporary_redirect: {
|
||||
auto newLocation =
|
||||
processRedirect(res, siteIdx, lock_sites);
|
||||
assert(newLocation);
|
||||
// for perm redirects, also update our starting URI
|
||||
if (res.result() == status::moved_permanently ||
|
||||
res.result() == status::permanent_redirect)
|
||||
{
|
||||
sites_[siteIdx].startingResource = newLocation;
|
||||
}
|
||||
makeRequest(newLocation, siteIdx, lock_sites);
|
||||
return; // we are still fetching, so skip
|
||||
// state update/notify below
|
||||
}
|
||||
default: {
|
||||
JLOG(j_.warn())
|
||||
<< "Request for validator list at "
|
||||
<< sites_[siteIdx].activeResource->uri
|
||||
<< " returned bad status: " << res.result_int();
|
||||
onError("bad result code", true);
|
||||
}
|
||||
makeRequest(newLocation, siteIdx, lock_sites);
|
||||
return; // we are still fetching, so skip
|
||||
// state update/notify below
|
||||
}
|
||||
default:
|
||||
{
|
||||
JLOG (j_.warn()) <<
|
||||
"Request for validator list at " <<
|
||||
sites_[siteIdx].activeResource->uri <<
|
||||
" returned bad status: " <<
|
||||
res.result_int();
|
||||
onError("bad result code", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
@@ -593,8 +543,8 @@ ValidatorSite::onSiteFetch(
|
||||
|
||||
std::lock_guard lock_state{state_mutex_};
|
||||
fetching_ = false;
|
||||
if (! stopping_)
|
||||
setTimer (lock_state);
|
||||
if (!stopping_)
|
||||
setTimer(lock_state);
|
||||
cv_.notify_all();
|
||||
}
|
||||
|
||||
@@ -610,13 +560,9 @@ ValidatorSite::onTextFetch(
|
||||
{
|
||||
if (ec)
|
||||
{
|
||||
JLOG (j_.warn()) <<
|
||||
"Problem retrieving from " <<
|
||||
sites_[siteIdx].activeResource->uri <<
|
||||
" " <<
|
||||
ec.value() <<
|
||||
": " <<
|
||||
ec.message();
|
||||
JLOG(j_.warn()) << "Problem retrieving from "
|
||||
<< sites_[siteIdx].activeResource->uri << " "
|
||||
<< ec.value() << ": " << ec.message();
|
||||
throw std::runtime_error{"fetch error"};
|
||||
}
|
||||
|
||||
@@ -624,18 +570,16 @@ ValidatorSite::onTextFetch(
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
sites_[siteIdx].lastRefreshStatus.emplace(
|
||||
Site::Status{clock_type::now(),
|
||||
ListDisposition::invalid,
|
||||
ex.what()});
|
||||
sites_[siteIdx].lastRefreshStatus.emplace(Site::Status{
|
||||
clock_type::now(), ListDisposition::invalid, ex.what()});
|
||||
}
|
||||
sites_[siteIdx].activeResource.reset();
|
||||
}
|
||||
|
||||
std::lock_guard lock_state{state_mutex_};
|
||||
fetching_ = false;
|
||||
if (! stopping_)
|
||||
setTimer (lock_state);
|
||||
if (!stopping_)
|
||||
setTimer(lock_state);
|
||||
cv_.notify_all();
|
||||
}
|
||||
|
||||
@@ -664,7 +608,7 @@ ValidatorSite::getJson() const
|
||||
to_string(site.lastRefreshStatus->refreshed);
|
||||
v[jss::last_refresh_status] =
|
||||
to_string(site.lastRefreshStatus->disposition);
|
||||
if (! site.lastRefreshStatus->message.empty())
|
||||
if (!site.lastRefreshStatus->message.empty())
|
||||
v[jss::last_refresh_message] =
|
||||
site.lastRefreshStatus->message;
|
||||
}
|
||||
@@ -674,4 +618,4 @@ ValidatorSite::getJson() const
|
||||
}
|
||||
return jrr;
|
||||
}
|
||||
} // ripple
|
||||
} // namespace ripple
|
||||
|
||||
Reference in New Issue
Block a user