Skip to content

Commit

Permalink
Accept redirects from validator list sites:
Browse files Browse the repository at this point in the history
Honor location header/redirect from validator sites. Limit retries per
refresh interval to 3. Shorten refresh interval after HTTP/network errors.

Fixes: RIPD-1669
  • Loading branch information
mellery451 committed Oct 19, 2018
1 parent b36e11b commit 7fe1d4b
Show file tree
Hide file tree
Showing 5 changed files with 501 additions and 230 deletions.
51 changes: 49 additions & 2 deletions src/ripple/app/misc/ValidatorSite.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <ripple/json/json_value.h>
#include <boost/asio.hpp>
#include <mutex>
#include <memory>

namespace ripple {

Expand Down Expand Up @@ -73,10 +74,32 @@ class ValidatorSite
{
clock_type::time_point refreshed;
ListDisposition disposition;
std::string message;
};

std::string uri;
parsedURL pUrl;
struct Resource
{
explicit Resource(std::string uri_);
const std::string uri;
parsedURL pUrl;
};

explicit Site(std::string uri);

/// the original uri as loaded from config
std::shared_ptr<Resource> loadedResource;

/// the resource to request at <timer>
/// intervals. same as loadedResource
/// except in the case of a permanent redir.
std::shared_ptr<Resource> startingResource;

/// the active resource being requested.
/// same as startingResource except
/// when we've gotten a temp redirect
std::shared_ptr<Resource> activeResource;

unsigned short redirCount;
std::chrono::minutes refreshInterval;
clock_type::time_point nextRefresh;
boost::optional<Status> lastRefreshStatus;
Expand Down Expand Up @@ -176,6 +199,30 @@ class ValidatorSite
boost::system::error_code const& ec,
detail::response_type&& res,
std::size_t siteIdx);

/// Initiate request to given resource.
/// lock over sites_mutex_ required
void
makeRequest (
std::shared_ptr<Site::Resource> resource,
std::size_t siteIdx,
std::lock_guard<std::mutex>& lock);

/// Parse json response from validator list site.
/// lock over sites_mutex_ required
void
parseJsonResponse (
detail::response_type& res,
std::size_t siteIdx,
std::lock_guard<std::mutex>& lock);

/// Interpret a redirect response.
/// lock over sites_mutex_ required
std::shared_ptr<Site::Resource>
processRedirect (
detail::response_type& res,
std::size_t siteIdx,
std::lock_guard<std::mutex>& lock);
};

} // ripple
Expand Down
Loading

0 comments on commit 7fe1d4b

Please sign in to comment.