20 #include <ripple/json/json_reader.h>
21 #include <ripple/overlay/Cluster.h>
22 #include <ripple/overlay/impl/ConnectAttempt.h>
23 #include <ripple/overlay/impl/PeerImp.h>
24 #include <ripple/overlay/impl/ProtocolVersion.h>
30 boost::asio::io_service& io_service,
43 , remote_endpoint_(remote_endpoint)
50 , socket_(stream_ptr_->next_layer().socket())
51 , stream_(*stream_ptr_)
67 if (!
strand_.running_in_this_thread())
80 stream_.next_layer().async_connect(
85 std::placeholders::_1)));
93 assert(
strand_.running_in_this_thread());
144 if (ec == boost::asio::error::operation_aborted)
160 if (ec == boost::asio::error::operation_aborted)
164 local_endpoint =
socket_.local_endpoint(ec);
166 return fail(
"onConnect", ec);
172 stream_.set_verify_mode(boost::asio::ssl::verify_none);
174 boost::asio::ssl::stream_base::client,
178 std::placeholders::_1)));
187 if (ec == boost::asio::error::operation_aborted)
191 local_endpoint =
socket_.local_endpoint(ec);
193 return fail(
"onHandshake", ec);
198 return fail(
"Duplicate connection");
220 boost::beast::http::async_write(
226 std::placeholders::_1)));
235 if (ec == boost::asio::error::operation_aborted)
238 return fail(
"onWrite", ec);
239 boost::beast::http::async_read(
246 std::placeholders::_1)));
256 if (ec == boost::asio::error::operation_aborted)
258 if (ec == boost::asio::error::eof)
265 std::placeholders::_1)));
268 return fail(
"onRead", ec);
278 JLOG(
journal_.
error()) <<
"onShutdown: expected error condition";
281 if (ec != boost::asio::error::eof)
282 return fail(
"onShutdown", ec);
291 if (
response_.result() == boost::beast::http::status::service_unavailable)
297 for (
auto const buffer :
response_.body().data())
299 boost::asio::buffer_cast<char const*>(buffer),
300 boost::asio::buffer_size(buffer));
301 auto const success = r.
parse(s, json);
311 for (
auto const& v : ips)
330 <<
"Unable to upgrade to peer protocol: " <<
response_.result()
343 negotiatedProtocol = pvs[0];
345 if (!negotiatedProtocol)
347 "processResponse: Unable to negotiate protocol version");
368 <<
"Protocol: " <<
to_string(*negotiatedProtocol);
377 slot_, publicKey,
static_cast<bool>(member));
379 return fail(
"Outbound slots full");
381 auto const peer = std::make_shared<PeerImp>(
void onHandshake(error_code ec)
endpoint_type remote_endpoint_
virtual Cluster & cluster()=0
boost::asio::io_service::strand strand_
Stream trace() const
Severity stream access functions.
const beast::Journal journal_
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.
std::optional< uint256 > makeSharedValue(stream_type &ssl, beast::Journal journal)
Computes a shared value based on the SSL connection state.
std::optional< std::string > member(PublicKey const &node) const
Determines whether a node belongs in the cluster.
Unserialize a JSON document into a Value.
Setup const & setup() const
boost::asio::ip::tcp::socket socket_type
bool peerPrivate
true if we want our IP address kept private.
void onRead(error_code ec)
std::shared_ptr< PeerFinder::Slot > slot_
virtual Result activate(std::shared_ptr< Slot > const &slot, PublicKey const &key, bool reserved)=0
Request an active slot type.
static IP::Endpoint from_asio(boost::asio::ip::address const &address)
virtual void on_closed(std::shared_ptr< Slot > const &slot)=0
Called when the slot is closed.
PeerFinder::Manager & peerFinder()
boost::system::error_code error_code
T shared_from_this(T... args)
virtual Config & config()=0
void onShutdown(error_code ec)
UInt size() const
Number of values in array or object.
Resource::Consumer usage_
bool isMember(const char *key) const
Return true if the object has a member named key.
A generic endpoint for log messages.
boost::asio::ip::tcp::endpoint endpoint_type
void fail(std::string const &reason)
bool VP_REDUCE_RELAY_ENABLE
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
virtual bool onConnected(std::shared_ptr< Slot > const &slot, beast::IP::Endpoint const &local_endpoint)=0
Called when an outbound connection attempt succeeds.
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.
boost::beast::ssl_stream< middle_type > stream_type
virtual Config config()=0
Returns the configuration for the manager.
std::unique_ptr< stream_type > stream_ptr_
bool parse(std::string const &document, Value &root)
Read a Value from a JSON document.
An endpoint that consumes resources.
boost::asio::basic_waitable_timer< std::chrono::steady_clock > timer_
void onConnect(error_code ec)
bool isProtocolSupported(ProtocolVersion const &v)
Determine whether we support a specific protocol version.
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
bool TX_REDUCE_RELAY_ENABLE
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.
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)
auto makeRequest(bool crawlPublic, bool comprEnabled, bool ledgerReplayEnabled, bool txReduceRelayEnabled, bool vpReduceRelayEnabled) -> request_type
Make outbound http request.
static boost::asio::ip::tcp::endpoint parse_endpoint(std::string const &s, boost::system::error_code &ec)
static bool isPeerUpgrade(http_request_type const &request)
void add_active(std::shared_ptr< PeerImp > const &peer)
boost::beast::multi_buffer read_buf_
void onTimer(error_code ec)
void onWrite(error_code ec)
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.