rippled
Loading...
Searching...
No Matches
ValidatorSite.h
1#pragma once
2
3#include <xrpld/app/main/Application.h>
4#include <xrpld/app/misc/ValidatorList.h>
5#include <xrpld/app/misc/detail/Work.h>
6
7#include <xrpl/basics/Log.h>
8#include <xrpl/basics/StringUtilities.h>
9#include <xrpl/json/json_value.h>
10
11#include <boost/asio.hpp>
12
13#include <mutex>
14#include <optional>
15
16namespace xrpl {
17
49{
50 friend class Work;
51
52private:
53 using error_code = boost::system::error_code;
55 using endpoint_type = boost::asio::ip::tcp::endpoint;
56
95
98
99 // If both mutex are to be locked at the same time, `sites_mutex_` must be
100 // locked before `state_mutex_` or we may deadlock.
103
106 boost::asio::basic_waitable_timer<clock_type> timer_;
107
108 // A list is currently being fetched from a site
110
111 // One or more lists are due to be fetched
114
115 // The configured list of URIs for fetching lists
117
118 // time to allow for requests to complete
120
121public:
123 Application& app,
127
138 bool
139 load(std::vector<std::string> const& siteURIs);
140
149 void
150 start();
151
158 void
159 join();
160
169 void
170 stop();
171
175 getJson() const;
176
177private:
179 bool
181
184 void
186
188 void
189 onRequestTimeout(std::size_t siteIdx, error_code const& ec);
190
192 void
193 onTimer(std::size_t siteIdx, error_code const& ec);
194
196 void
198 boost::system::error_code const& ec,
199 endpoint_type const& endpoint,
201 std::size_t siteIdx);
202
204 void
205 onTextFetch(boost::system::error_code const& ec, std::string const& res, std::size_t siteIdx);
206
209 void
211
214 void
216
221
224 bool
226};
227
228} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
A generic endpoint for log messages.
Definition Journal.h:40
void onRequestTimeout(std::size_t siteIdx, error_code const &ec)
request took too long
void setTimer(std::lock_guard< std::mutex > const &, std::lock_guard< std::mutex > const &)
Queue next site to be fetched lock over site_mutex_ and state_mutex_ required.
bool load(std::vector< std::string > const &siteURIs)
Load configured site URIs.
void join()
Wait for current fetches from sites to complete.
bool missingSite(std::lock_guard< std::mutex > const &)
If no sites are provided, or a site fails to load, get a list of local cache files from the Validator...
std::atomic< bool > pending_
std::atomic< bool > fetching_
void start()
Start fetching lists from sites.
std::chrono::seconds const requestTimeout_
boost::asio::basic_waitable_timer< clock_type > timer_
boost::asio::ip::tcp::endpoint endpoint_type
void makeRequest(std::shared_ptr< Site::Resource > resource, std::size_t siteIdx, std::lock_guard< std::mutex > const &)
Initiate request to given resource.
void onSiteFetch(boost::system::error_code const &ec, endpoint_type const &endpoint, detail::response_type &&res, std::size_t siteIdx)
Store latest list fetched from site.
Json::Value getJson() const
Return JSON representation of configured validator sites.
std::condition_variable cv_
void parseJsonResponse(std::string const &res, std::size_t siteIdx, std::lock_guard< std::mutex > const &)
Parse json response from validator list site.
beast::Journal const j_
std::atomic< bool > stopping_
boost::system::error_code error_code
std::weak_ptr< detail::Work > work_
Application & app_
std::shared_ptr< Site::Resource > processRedirect(detail::response_type &res, std::size_t siteIdx, std::lock_guard< std::mutex > const &)
Interpret a redirect response.
void onTextFetch(boost::system::error_code const &ec, std::string const &res, std::size_t siteIdx)
Store latest list fetched from anywhere.
void onTimer(std::size_t siteIdx, error_code const &ec)
Fetch site whose time has come.
void stop()
Stop fetching lists from sites.
std::vector< Site > sites_
T is_same_v
boost::beast::http::response< boost::beast::http::string_body > response_type
Definition Work.h:10
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
ListDisposition
clock_type::time_point refreshed
std::shared_ptr< Resource > startingResource
the resource to request at <timer> intervals.
endpoint_type lastRequestEndpoint
clock_type::time_point nextRefresh
std::shared_ptr< Resource > activeResource
the active resource being requested.
std::chrono::minutes refreshInterval
std::shared_ptr< Resource > loadedResource
the original uri as loaded from config
std::optional< Status > lastRefreshStatus