diff --git a/ValidatorSite_8cpp_source.html b/ValidatorSite_8cpp_source.html index fe3f63db3e..3b1181be52 100644 --- a/ValidatorSite_8cpp_source.html +++ b/ValidatorSite_8cpp_source.html @@ -180,7 +180,7 @@ $(function() {
102ValidatorSite::~ValidatorSite()
103{
104 std::unique_lock<std::mutex> lock{state_mutex_};
-
105 if (timer_.expires_at() > clock_type::time_point{})
+
105 if (timer_.expiry() > clock_type::time_point{})
106 {
107 if (!stopping_)
108 {
@@ -246,7 +246,7 @@ $(function() {
168{
169 std::lock_guard l0{sites_mutex_};
170 std::lock_guard l1{state_mutex_};
-
171 if (timer_.expires_at() == clock_type::time_point{})
+
171 if (timer_.expiry() == clock_type::time_point{})
172 setTimer(l0, l1);
173}
174
diff --git a/WorkBase_8h_source.html b/WorkBase_8h_source.html index 2d32411f0f..f87cf8bcd9 100644 --- a/WorkBase_8h_source.html +++ b/WorkBase_8h_source.html @@ -175,214 +175,197 @@ $(function() {
97 onResolve(error_code const& ec, results_type results);
98
99 void
-
100 onStart();
+
100 onConnect(error_code const& ec, endpoint_type const& endpoint);
101
102 void
-
103 onRequest(error_code const& ec);
+
103 onStart();
104
105 void
-
106 onResponse(error_code const& ec);
+
106 onRequest(error_code const& ec);
107
-
108private:
-
109 void
-
110 close();
-
111};
-
112
-
113//------------------------------------------------------------------------------
-
114
-
115template <class Impl>
-
116WorkBase<Impl>::WorkBase(
-
117 std::string const& host,
-
118 std::string const& path,
-
119 std::string const& port,
-
120 boost::asio::io_service& ios,
-
121 endpoint_type const& lastEndpoint,
-
122 bool lastStatus,
-
123 callback_type cb)
-
124 : host_(host)
-
125 , path_(path)
-
126 , port_(port)
-
127 , cb_(std::move(cb))
-
128 , ios_(ios)
-
129 , strand_(ios)
-
130 , resolver_(ios)
-
131 , socket_(ios)
-
132 , lastEndpoint_{lastEndpoint}
-
133 , lastStatus_(lastStatus)
-
134{
-
135}
-
136
-
137template <class Impl>
-
138WorkBase<Impl>::~WorkBase()
-
139{
-
140 if (cb_)
-
141 cb_(make_error_code(boost::system::errc::not_a_socket),
-
142 lastEndpoint_,
-
143 std::move(res_));
-
144 close();
-
145}
-
146
-
147template <class Impl>
-
148void
-
149WorkBase<Impl>::run()
-
150{
-
151 if (!strand_.running_in_this_thread())
-
152 return ios_.post(
-
153 strand_.wrap(std::bind(&WorkBase::run, impl().shared_from_this())));
-
154
-
155 resolver_.async_resolve(
-
156 host_,
-
157 port_,
-
158 strand_.wrap(std::bind(
-
159 &WorkBase::onResolve,
-
160 impl().shared_from_this(),
-
161 std::placeholders::_1,
-
162 std::placeholders::_2)));
-
163}
-
164
-
165template <class Impl>
-
166void
-
167WorkBase<Impl>::cancel()
-
168{
-
169 if (!strand_.running_in_this_thread())
-
170 {
-
171 return ios_.post(strand_.wrap(
-
172 std::bind(&WorkBase::cancel, impl().shared_from_this())));
-
173 }
-
174
-
175 error_code ec;
-
176 resolver_.cancel();
-
177 socket_.cancel(ec);
-
178}
-
179
-
180template <class Impl>
-
181void
-
182WorkBase<Impl>::fail(error_code const& ec)
-
183{
-
184 if (cb_)
-
185 {
-
186 cb_(ec, lastEndpoint_, std::move(res_));
-
187 cb_ = nullptr;
-
188 }
-
189}
-
190
-
191template <class Impl>
-
192void
-
193WorkBase<Impl>::onResolve(error_code const& ec, results_type results)
-
194{
-
195 if (ec)
-
196 return fail(ec);
-
197
-
198 // Use last endpoint if it is successfully connected
-
199 // and is in the list, otherwise pick a random endpoint
-
200 // from the list (excluding last endpoint). If there is
-
201 // only one endpoint and it is the last endpoint then
-
202 // use the last endpoint.
-
203 lastEndpoint_ = [&]() -> endpoint_type {
-
204 int foundIndex = 0;
-
205 auto const foundIt = std::find_if(
-
206 results.begin(), results.end(), [&](endpoint_type const& e) {
-
207 if (e == lastEndpoint_)
-
208 return true;
-
209 foundIndex++;
-
210 return false;
-
211 });
-
212 if (foundIt != results.end() && lastStatus_)
-
213 return lastEndpoint_;
-
214 else if (results.size() == 1)
-
215 return *results.begin();
-
216 else if (foundIt == results.end())
-
217 return *std::next(results.begin(), rand_int(results.size() - 1));
-
218
-
219 // lastEndpoint_ is part of the collection
-
220 // Pick a random number from the n-1 valid choices, if we use
-
221 // this as an index, note the last element will never be chosen
-
222 // and the `lastEndpoint_` index may be chosen. So when the
-
223 // `lastEndpoint_` index is chosen, that is treated as if the
-
224 // last element was chosen.
-
225 auto randIndex =
-
226 (results.size() > 2) ? rand_int(results.size() - 2) : 0;
-
227 if (randIndex == foundIndex)
-
228 randIndex = results.size() - 1;
-
229 return *std::next(results.begin(), randIndex);
-
230 }();
-
231
-
232 socket_.async_connect(
-
233 lastEndpoint_,
-
234 strand_.wrap(std::bind(
-
235 &Impl::onConnect,
-
236 impl().shared_from_this(),
-
237 std::placeholders::_1)));
-
238}
-
239
-
240template <class Impl>
-
241void
-
242WorkBase<Impl>::onStart()
-
243{
-
244 req_.method(boost::beast::http::verb::get);
-
245 req_.target(path_.empty() ? "/" : path_);
-
246 req_.version(11);
-
247 req_.set("Host", host_ + ":" + port_);
-
248 req_.set("User-Agent", BuildInfo::getFullVersionString());
-
249 req_.prepare_payload();
-
250 boost::beast::http::async_write(
-
251 impl().stream(),
-
252 req_,
+
108 void
+
109 onResponse(error_code const& ec);
+
110
+
111private:
+
112 void
+
113 close();
+
114};
+
115
+
116//------------------------------------------------------------------------------
+
117
+
118template <class Impl>
+
119WorkBase<Impl>::WorkBase(
+
120 std::string const& host,
+
121 std::string const& path,
+
122 std::string const& port,
+
123 boost::asio::io_service& ios,
+
124 endpoint_type const& lastEndpoint,
+
125 bool lastStatus,
+
126 callback_type cb)
+
127 : host_(host)
+
128 , path_(path)
+
129 , port_(port)
+
130 , cb_(std::move(cb))
+
131 , ios_(ios)
+
132 , strand_(ios)
+
133 , resolver_(ios)
+
134 , socket_(ios)
+
135 , lastEndpoint_{lastEndpoint}
+
136 , lastStatus_(lastStatus)
+
137{
+
138}
+
139
+
140template <class Impl>
+
141WorkBase<Impl>::~WorkBase()
+
142{
+
143 if (cb_)
+
144 cb_(make_error_code(boost::system::errc::not_a_socket),
+
145 lastEndpoint_,
+
146 std::move(res_));
+
147 close();
+
148}
+
149
+
150template <class Impl>
+
151void
+
152WorkBase<Impl>::run()
+
153{
+
154 if (!strand_.running_in_this_thread())
+
155 return ios_.post(
+
156 strand_.wrap(std::bind(&WorkBase::run, impl().shared_from_this())));
+
157
+
158 resolver_.async_resolve(
+
159 host_,
+
160 port_,
+
161 strand_.wrap(std::bind(
+
162 &WorkBase::onResolve,
+
163 impl().shared_from_this(),
+
164 std::placeholders::_1,
+
165 std::placeholders::_2)));
+
166}
+
167
+
168template <class Impl>
+
169void
+
170WorkBase<Impl>::cancel()
+
171{
+
172 if (!strand_.running_in_this_thread())
+
173 {
+
174 return ios_.post(strand_.wrap(
+
175 std::bind(&WorkBase::cancel, impl().shared_from_this())));
+
176 }
+
177
+
178 error_code ec;
+
179 resolver_.cancel();
+
180 socket_.cancel(ec);
+
181}
+
182
+
183template <class Impl>
+
184void
+
185WorkBase<Impl>::fail(error_code const& ec)
+
186{
+
187 if (cb_)
+
188 {
+
189 cb_(ec, lastEndpoint_, std::move(res_));
+
190 cb_ = nullptr;
+
191 }
+
192}
+
193
+
194template <class Impl>
+
195void
+
196WorkBase<Impl>::onResolve(error_code const& ec, results_type results)
+
197{
+
198 if (ec)
+
199 return fail(ec);
+
200
+
201 boost::asio::async_connect(
+
202 socket_,
+
203 results,
+
204 strand_.wrap(std::bind(
+
205 &WorkBase::onConnect,
+
206 impl().shared_from_this(),
+
207 std::placeholders::_1,
+
208 std::placeholders::_2)));
+
209}
+
210
+
211template <class Impl>
+
212void
+
213WorkBase<Impl>::onConnect(error_code const& ec, endpoint_type const& endpoint)
+
214{
+
215 lastEndpoint_ = endpoint;
+
216
+
217 if (ec)
+
218 return fail(ec);
+
219
+
220 impl().onConnect(ec);
+
221}
+
222
+
223template <class Impl>
+
224void
+
225WorkBase<Impl>::onStart()
+
226{
+
227 req_.method(boost::beast::http::verb::get);
+
228 req_.target(path_.empty() ? "/" : path_);
+
229 req_.version(11);
+
230 req_.set("Host", host_ + ":" + port_);
+
231 req_.set("User-Agent", BuildInfo::getFullVersionString());
+
232 req_.prepare_payload();
+
233 boost::beast::http::async_write(
+
234 impl().stream(),
+
235 req_,
+
236 strand_.wrap(std::bind(
+
237 &WorkBase::onRequest,
+
238 impl().shared_from_this(),
+
239 std::placeholders::_1)));
+
240}
+
241
+
242template <class Impl>
+
243void
+
244WorkBase<Impl>::onRequest(error_code const& ec)
+
245{
+
246 if (ec)
+
247 return fail(ec);
+
248
+
249 boost::beast::http::async_read(
+
250 impl().stream(),
+
251 readBuf_,
+
252 res_,
253 strand_.wrap(std::bind(
-
254 &WorkBase::onRequest,
+
254 &WorkBase::onResponse,
255 impl().shared_from_this(),
256 std::placeholders::_1)));
257}
258
259template <class Impl>
260void
-
261WorkBase<Impl>::onRequest(error_code const& ec)
+
261WorkBase<Impl>::onResponse(error_code const& ec)
262{
263 if (ec)
264 return fail(ec);
265
-
266 boost::beast::http::async_read(
-
267 impl().stream(),
-
268 readBuf_,
-
269 res_,
-
270 strand_.wrap(std::bind(
-
271 &WorkBase::onResponse,
-
272 impl().shared_from_this(),
-
273 std::placeholders::_1)));
-
274}
-
275
-
276template <class Impl>
-
277void
-
278WorkBase<Impl>::onResponse(error_code const& ec)
-
279{
-
280 if (ec)
-
281 return fail(ec);
-
282
-
283 close();
-
284 XRPL_ASSERT(cb_, "ripple::detail::WorkBase::onResponse : callback is set");
-
285 cb_(ec, lastEndpoint_, std::move(res_));
-
286 cb_ = nullptr;
-
287}
-
288
-
289template <class Impl>
-
290void
-
291WorkBase<Impl>::close()
-
292{
-
293 if (socket_.is_open())
-
294 {
-
295 error_code ec;
-
296 socket_.shutdown(boost::asio::socket_base::shutdown_send, ec);
-
297 if (ec)
-
298 return;
-
299 socket_.close(ec);
-
300 }
-
301}
-
302
-
303} // namespace detail
-
304
-
305} // namespace ripple
-
306
-
307#endif
+
266 close();
+
267 XRPL_ASSERT(cb_, "ripple::detail::WorkBase::onResponse : callback is set");
+
268 cb_(ec, lastEndpoint_, std::move(res_));
+
269 cb_ = nullptr;
+
270}
+
271
+
272template <class Impl>
+
273void
+
274WorkBase<Impl>::close()
+
275{
+
276 if (socket_.is_open())
+
277 {
+
278 error_code ec;
+
279 socket_.shutdown(boost::asio::socket_base::shutdown_send, ec);
+
280 if (ec)
+
281 return;
+
282 socket_.close(ec);
+
283 }
+
284}
+
285
+
286} // namespace detail
+
287
+
288} // namespace ripple
+
289
+
290#endif
std::string
std::bind
T bind(T... args)
ripple::detail::WorkBase
Definition: WorkBase.h:40
@@ -393,39 +376,37 @@ $(function() {
ripple::detail::WorkBase::results_type
boost::asio::ip::tcp::resolver::results_type results_type
Definition: WorkBase.h:52
ripple::detail::WorkBase::res_
response_type res_
Definition: WorkBase.h:65
ripple::detail::WorkBase::request_type
boost::beast::http::request< boost::beast::http::empty_body > request_type
Definition: WorkBase.h:54
-
ripple::detail::WorkBase::onResolve
void onResolve(error_code const &ec, results_type results)
Definition: WorkBase.h:193
-
ripple::detail::WorkBase::onRequest
void onRequest(error_code const &ec)
Definition: WorkBase.h:261
+
ripple::detail::WorkBase::onResolve
void onResolve(error_code const &ec, results_type results)
Definition: WorkBase.h:196
+
ripple::detail::WorkBase::onRequest
void onRequest(error_code const &ec)
Definition: WorkBase.h:244
ripple::detail::WorkBase::socket_type
boost::asio::ip::tcp::socket socket_type
Definition: WorkBase.h:50
ripple::detail::WorkBase::strand_
boost::asio::io_service::strand strand_
Definition: WorkBase.h:61
ripple::detail::WorkBase::socket_
socket_type socket_
Definition: WorkBase.h:63
-
ripple::detail::WorkBase::~WorkBase
~WorkBase()
Definition: WorkBase.h:138
+
ripple::detail::WorkBase::~WorkBase
~WorkBase()
Definition: WorkBase.h:141
ripple::detail::WorkBase::path_
std::string path_
Definition: WorkBase.h:57
-
ripple::detail::WorkBase::cancel
void cancel() override
Definition: WorkBase.h:167
+
ripple::detail::WorkBase::cancel
void cancel() override
Definition: WorkBase.h:170
ripple::detail::WorkBase::req_
request_type req_
Definition: WorkBase.h:64
-
ripple::detail::WorkBase::onResponse
void onResponse(error_code const &ec)
Definition: WorkBase.h:278
+
ripple::detail::WorkBase::onResponse
void onResponse(error_code const &ec)
Definition: WorkBase.h:261
ripple::detail::WorkBase::endpoint_type
boost::asio::ip::tcp::endpoint endpoint_type
Definition: WorkBase.h:43
-
ripple::detail::WorkBase::close
void close()
Definition: WorkBase.h:291
-
ripple::detail::WorkBase::onStart
void onStart()
Definition: WorkBase.h:242
+
ripple::detail::WorkBase::close
void close()
Definition: WorkBase.h:274
+
ripple::detail::WorkBase::onStart
void onStart()
Definition: WorkBase.h:225
ripple::detail::WorkBase::port_
std::string port_
Definition: WorkBase.h:58
ripple::detail::WorkBase::resolver_type
boost::asio::ip::tcp::resolver resolver_type
Definition: WorkBase.h:51
ripple::detail::WorkBase::error_code
boost::system::error_code error_code
Definition: WorkBase.h:42
ripple::detail::WorkBase::readBuf_
boost::beast::multi_buffer readBuf_
Definition: WorkBase.h:66
-
ripple::detail::WorkBase::WorkBase
WorkBase(std::string const &host, std::string const &path, std::string const &port, boost::asio::io_service &ios, endpoint_type const &lastEndpoint, bool lastStatus, callback_type cb)
Definition: WorkBase.h:116
-
ripple::detail::WorkBase::fail
void fail(error_code const &ec)
Definition: WorkBase.h:182
+
ripple::detail::WorkBase::onConnect
void onConnect(error_code const &ec, endpoint_type const &endpoint)
Definition: WorkBase.h:213
+
ripple::detail::WorkBase::WorkBase
WorkBase(std::string const &host, std::string const &path, std::string const &port, boost::asio::io_service &ios, endpoint_type const &lastEndpoint, bool lastStatus, callback_type cb)
Definition: WorkBase.h:119
+
ripple::detail::WorkBase::fail
void fail(error_code const &ec)
Definition: WorkBase.h:185
ripple::detail::WorkBase::host_
std::string host_
Definition: WorkBase.h:56
-
ripple::detail::WorkBase::run
void run() override
Definition: WorkBase.h:149
+
ripple::detail::WorkBase::run
void run() override
Definition: WorkBase.h:152
ripple::detail::WorkBase::resolver_
resolver_type resolver_
Definition: WorkBase.h:62
ripple::detail::WorkBase::lastStatus_
bool lastStatus_
Definition: WorkBase.h:68
ripple::detail::Work
Definition: Work.h:34
-
std::find_if
T find_if(T... args)
std::function
ripple::BuildInfo::getFullVersionString
std::string const & getFullVersionString()
Full server version string.
Definition: BuildInfo.cpp:81
ripple::detail::response_type
boost::beast::http::response< boost::beast::http::string_body > response_type
Definition: Work.h:31
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
-
ripple::rand_int
std::enable_if_t< std::is_integral< Integral >::value, Integral > rand_int()
Definition: include/xrpl/basics/random.h:159
ripple::make_error_code
std::error_code make_error_code(ripple::TokenCodecErrc e)
Definition: token_errors.h:97
std
STL namespace.
-
std::next
T next(T... args)