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_service& io_service,
44 , remote_endpoint_(remote_endpoint)
51 , socket_(stream_ptr_->next_layer().socket())
52 , stream_(*stream_ptr_)
68 if (!
strand_.running_in_this_thread())
81 stream_.next_layer().async_connect(
86 std::placeholders::_1)));
95 strand_.running_in_this_thread(),
96 "ripple::ConnectAttempt::close : strand in this thread");
147 if (ec == boost::asio::error::operation_aborted)
163 if (ec == boost::asio::error::operation_aborted)
167 local_endpoint =
socket_.local_endpoint(ec);
169 return fail(
"onConnect", ec);
175 stream_.set_verify_mode(boost::asio::ssl::verify_none);
177 boost::asio::ssl::stream_base::client,
181 std::placeholders::_1)));
190 if (ec == boost::asio::error::operation_aborted)
194 local_endpoint =
socket_.local_endpoint(ec);
196 return fail(
"onHandshake", ec);
201 return fail(
"Duplicate connection");
223 boost::beast::http::async_write(
229 std::placeholders::_1)));
238 if (ec == boost::asio::error::operation_aborted)
241 return fail(
"onWrite", ec);
242 boost::beast::http::async_read(
249 std::placeholders::_1)));
259 if (ec == boost::asio::error::operation_aborted)
261 if (ec == boost::asio::error::eof)
268 std::placeholders::_1)));
271 return fail(
"onRead", ec);
281 JLOG(
journal_.
error()) <<
"onShutdown: expected error condition";
284 if (ec != boost::asio::error::eof)
285 return fail(
"onShutdown", ec);
294 if (
response_.result() == boost::beast::http::status::service_unavailable)
300 for (
auto const buffer :
response_.body().data())
302 boost::asio::buffer_cast<char const*>(buffer),
303 boost::asio::buffer_size(buffer));
314 for (
auto const& v : ips)
333 <<
"Unable to upgrade to peer protocol: " <<
response_.result()
346 negotiatedProtocol = pvs[0];
348 if (!negotiatedProtocol)
350 "processResponse: Unable to negotiate protocol version");
371 <<
"Protocol: " <<
to_string(*negotiatedProtocol);
380 slot_, publicKey,
static_cast<bool>(member));
381 if (result != PeerFinder::Result::success)
382 return fail(
"Outbound slots full");
384 auto const peer = std::make_shared<PeerImp>(
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
boost::asio::io_service::strand strand_
boost::system::error_code error_code
std::unique_ptr< stream_type > stream_ptr_
std::shared_ptr< PeerFinder::Slot > slot_
ConnectAttempt(Application &app, boost::asio::io_service &io_service, 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)
Resource::Consumer usage_
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.