20#include <xrpld/overlay/Cluster.h>
21#include <xrpld/overlay/detail/ConnectAttempt.h>
22#include <xrpld/overlay/detail/PeerImp.h>
23#include <xrpld/overlay/detail/ProtocolVersion.h>
25#include <xrpl/json/json_reader.h>
31 boost::asio::io_context& io_context,
44 , remote_endpoint_(remote_endpoint)
46 , strand_(
boost::asio::make_strand(io_context))
51 , socket_(stream_ptr_->next_layer().socket())
52 , stream_(*stream_ptr_)
68 if (!
strand_.running_in_this_thread())
69 return boost::asio::post(
81 stream_.next_layer().async_connect(
83 boost::asio::bind_executor(
88 std::placeholders::_1)));
97 strand_.running_in_this_thread(),
98 "ripple::ConnectAttempt::close : strand in this thread");
106 catch (boost::system::system_error
const&)
136 catch (boost::system::system_error
const& e)
142 timer_.async_wait(boost::asio::bind_executor(
147 std::placeholders::_1)));
157 catch (boost::system::system_error
const&)
168 if (ec == boost::asio::error::operation_aborted)
184 if (ec == boost::asio::error::operation_aborted)
188 local_endpoint =
socket_.local_endpoint(ec);
190 return fail(
"onConnect", ec);
196 stream_.set_verify_mode(boost::asio::ssl::verify_none);
198 boost::asio::ssl::stream_base::client,
199 boost::asio::bind_executor(
204 std::placeholders::_1)));
213 if (ec == boost::asio::error::operation_aborted)
217 local_endpoint =
socket_.local_endpoint(ec);
219 return fail(
"onHandshake", ec);
224 return fail(
"Duplicate connection");
246 boost::beast::http::async_write(
249 boost::asio::bind_executor(
254 std::placeholders::_1)));
263 if (ec == boost::asio::error::operation_aborted)
266 return fail(
"onWrite", ec);
267 boost::beast::http::async_read(
271 boost::asio::bind_executor(
276 std::placeholders::_1)));
286 if (ec == boost::asio::error::operation_aborted)
288 if (ec == boost::asio::error::eof)
292 return stream_.async_shutdown(boost::asio::bind_executor(
297 std::placeholders::_1)));
300 return fail(
"onRead", ec);
310 JLOG(
journal_.
error()) <<
"onShutdown: expected error condition";
313 if (ec != boost::asio::error::eof)
314 return fail(
"onShutdown", ec);
323 if (
response_.result() == boost::beast::http::status::service_unavailable)
329 for (
auto const buffer :
response_.body().data())
331 static_cast<char const*
>(buffer.data()),
332 boost::asio::buffer_size(buffer));
343 for (
auto const& v : ips)
362 <<
"Unable to upgrade to peer protocol: " <<
response_.result()
375 negotiatedProtocol = pvs[0];
377 if (!negotiatedProtocol)
379 "processResponse: Unable to negotiate protocol version");
400 <<
"Protocol: " <<
to_string(*negotiatedProtocol);
409 slot_, publicKey,
static_cast<bool>(member));
410 if (result != PeerFinder::Result::success)
Unserialize a JSON document into a Value.
bool parse(std::string const &document, Value &root)
Read a Value from a JSON document.
UInt size() const
Number of values in array or object.
bool isMember(char const *key) const
Return true if the object has a member named key.
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
virtual Config & config()=0
virtual Cluster & cluster()=0
std::optional< std::string > member(PublicKey const &node) const
Determines whether a node belongs in the cluster.
bool VP_REDUCE_RELAY_BASE_SQUELCH_ENABLE
bool TX_REDUCE_RELAY_ENABLE
boost::asio::ip::tcp::socket socket_type
ConnectAttempt(Application &app, boost::asio::io_context &io_context, endpoint_type const &remote_endpoint, Resource::Consumer usage, shared_context const &context, std::uint32_t id, std::shared_ptr< PeerFinder::Slot > const &slot, beast::Journal journal, OverlayImpl &overlay)
boost::system::error_code error_code
std::unique_ptr< stream_type > stream_ptr_
std::shared_ptr< PeerFinder::Slot > slot_
Resource::Consumer usage_
boost::asio::strand< boost::asio::io_context::executor_type > strand_
void onHandshake(error_code ec)
boost::asio::ip::tcp::endpoint endpoint_type
void onWrite(error_code ec)
void onTimer(error_code ec)
void onShutdown(error_code ec)
boost::beast::ssl_stream< middle_type > stream_type
boost::beast::multi_buffer read_buf_
void onConnect(error_code ec)
void fail(std::string const &reason)
void onRead(error_code ec)
static boost::asio::ip::tcp::endpoint parse_endpoint(std::string const &s, boost::system::error_code &ec)
beast::Journal const journal_
boost::asio::basic_waitable_timer< std::chrono::steady_clock > timer_
endpoint_type remote_endpoint_
PeerFinder::Manager & peerFinder()
void add_active(std::shared_ptr< PeerImp > const &peer)
static bool isPeerUpgrade(http_request_type const &request)
Setup const & setup() const
virtual bool onConnected(std::shared_ptr< Slot > const &slot, beast::IP::Endpoint const &local_endpoint)=0
Called when an outbound connection attempt succeeds.
virtual Config config()=0
Returns the configuration for the manager.
virtual void on_closed(std::shared_ptr< Slot > const &slot)=0
Called when the slot is closed.
virtual void onRedirects(boost::asio::ip::tcp::endpoint const &remote_address, std::vector< boost::asio::ip::tcp::endpoint > const &eps)=0
Called when we received redirect IPs from a busy peer.
virtual Result activate(std::shared_ptr< Slot > const &slot, PublicKey const &key, bool reserved)=0
Request an active slot type.
An endpoint that consumes resources.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
std::vector< ProtocolVersion > parseProtocolVersions(boost::beast::string_view const &value)
Parse a set of protocol versions.
void buildHandshake(boost::beast::http::fields &h, ripple::uint256 const &sharedValue, std::optional< std::uint32_t > networkID, beast::IP::Address public_ip, beast::IP::Address remote_ip, Application &app)
Insert fields headers necessary for upgrading the link to the peer protocol.
std::optional< uint256 > makeSharedValue(stream_type &ssl, beast::Journal journal)
Computes a shared value based on the SSL connection state.
std::string to_string(base_uint< Bits, Tag > const &a)
auto makeRequest(bool crawlPublic, bool comprEnabled, bool ledgerReplayEnabled, bool txReduceRelayEnabled, bool vpReduceRelayEnabled) -> request_type
Make outbound http request.
bool isProtocolSupported(ProtocolVersion const &v)
Determine whether we support a specific protocol version.
PublicKey verifyHandshake(boost::beast::http::fields const &headers, ripple::uint256 const &sharedValue, std::optional< std::uint32_t > networkID, beast::IP::Address public_ip, beast::IP::Address remote, Application &app)
Validate header fields necessary for upgrading the link to the peer protocol.
T shared_from_this(T... args)
static IP::Endpoint from_asio(boost::asio::ip::address const &address)
beast::IP::Address public_ip
std::optional< std::uint32_t > networkID
bool peerPrivate
true if we want our IP address kept private.