rippled
Loading...
Searching...
No Matches
ValidatorSite.h
1#ifndef XRPL_APP_MISC_VALIDATORSITE_H_INCLUDED
2#define XRPL_APP_MISC_VALIDATORSITE_H_INCLUDED
3
4#include <xrpld/app/main/Application.h>
5#include <xrpld/app/misc/ValidatorList.h>
6#include <xrpld/app/misc/detail/Work.h>
7
8#include <xrpl/basics/Log.h>
9#include <xrpl/basics/StringUtilities.h>
10#include <xrpl/json/json_value.h>
11
12#include <boost/asio.hpp>
13
14#include <mutex>
15#include <optional>
16
17namespace ripple {
18
50{
51 friend class Work;
52
53private:
54 using error_code = boost::system::error_code;
56 using endpoint_type = boost::asio::ip::tcp::endpoint;
57
96
99
100 // If both mutex are to be locked at the same time, `sites_mutex_` must be
101 // locked before `state_mutex_` or we may deadlock.
104
107 boost::asio::basic_waitable_timer<clock_type> timer_;
108
109 // A list is currently being fetched from a site
111
112 // One or more lists are due to be fetched
115
116 // The configured list of URIs for fetching lists
118
119 // time to allow for requests to complete
121
122public:
124 Application& app,
128
139 bool
140 load(std::vector<std::string> const& siteURIs);
141
150 void
151 start();
152
159 void
160 join();
161
170 void
171 stop();
172
176 getJson() const;
177
178private:
180 bool
181 load(
182 std::vector<std::string> const& siteURIs,
184
187 void
188 setTimer(
191
193 void
194 onRequestTimeout(std::size_t siteIdx, error_code const& ec);
195
197 void
198 onTimer(std::size_t siteIdx, error_code const& ec);
199
201 void
203 boost::system::error_code const& ec,
204 endpoint_type const& endpoint,
206 std::size_t siteIdx);
207
209 void
211 boost::system::error_code const& ec,
212 std::string const& res,
213 std::size_t siteIdx);
214
217 void
220 std::size_t siteIdx,
222
225 void
227 std::string const& res,
228 std::size_t siteIdx,
230
236 std::size_t siteIdx,
238
241 bool
243};
244
245} // namespace ripple
246
247#endif
Represents a JSON value.
Definition json_value.h:130
A generic endpoint for log messages.
Definition Journal.h:41
void start()
Start fetching lists from sites.
std::condition_variable cv_
beast::Journal const j_
std::vector< Site > sites_
boost::asio::ip::tcp::endpoint endpoint_type
void stop()
Stop fetching lists from sites.
Json::Value getJson() const
Return JSON representation of configured validator sites.
bool load(std::vector< std::string > const &siteURIs)
Load configured site URIs.
void onTextFetch(boost::system::error_code const &ec, std::string const &res, std::size_t siteIdx)
Store latest list fetched from anywhere.
std::weak_ptr< detail::Work > work_
std::chrono::seconds const requestTimeout_
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.
std::atomic< bool > stopping_
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::shared_ptr< Site::Resource > processRedirect(detail::response_type &res, std::size_t siteIdx, std::lock_guard< std::mutex > const &)
Interpret a redirect response.
void parseJsonResponse(std::string const &res, std::size_t siteIdx, std::lock_guard< std::mutex > const &)
Parse json response from validator list site.
void makeRequest(std::shared_ptr< Site::Resource > resource, std::size_t siteIdx, std::lock_guard< std::mutex > const &)
Initiate request to given resource.
void onRequestTimeout(std::size_t siteIdx, error_code const &ec)
request took too long
std::atomic< bool > pending_
boost::system::error_code error_code
boost::asio::basic_waitable_timer< clock_type > timer_
void onTimer(std::size_t siteIdx, error_code const &ec)
Fetch site whose time has come.
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.
std::atomic< bool > fetching_
T is_same_v
boost::beast::http::response< boost::beast::http::string_body > response_type
Definition Work.h:12
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
clock_type::time_point refreshed
std::shared_ptr< Resource > loadedResource
the original uri as loaded from config
std::shared_ptr< Resource > startingResource
the resource to request at <timer> intervals.
endpoint_type lastRequestEndpoint
std::chrono::minutes refreshInterval
std::shared_ptr< Resource > activeResource
the active resource being requested.
std::optional< Status > lastRefreshStatus
clock_type::time_point nextRefresh