xrpld
Loading...
Searching...
No Matches
ConnectAttempt.h
1#pragma once
2
3#include <xrpld/overlay/Peer.h>
4#include <xrpld/overlay/detail/OverlayImpl.h>
5
6#include <sstream>
7
8namespace xrpl {
9
12 public std::enable_shared_from_this<ConnectAttempt>
13{
14private:
15 using error_code = boost::system::error_code;
16 using endpoint_type = boost::asio::ip::tcp::endpoint;
17 using request_type = boost::beast::http::request<boost::beast::http::empty_body>;
18 using response_type = boost::beast::http::response<boost::beast::http::dynamic_body>;
19
20 using socket_type = boost::asio::ip::tcp::socket;
21 using middle_type = boost::beast::tcp_stream;
22 using stream_type = boost::beast::ssl_stream<middle_type>;
24
31 boost::asio::strand<boost::asio::io_context::executor_type> strand_;
32 boost::asio::basic_waitable_timer<std::chrono::steady_clock> timer_;
36 boost::beast::multi_buffer readBuf_;
40
41public:
43 Application& app,
44 boost::asio::io_context& ioContext,
45 endpoint_type remoteEndpoint,
47 shared_context const& context,
48 Peer::id_t id,
50 beast::Journal journal,
51 OverlayImpl& overlay);
52
53 ~ConnectAttempt() override;
54
55 void
56 stop() override;
57
58 void
59 run();
60
61private:
62 void
63 close();
64 void
65 fail(std::string const& reason);
66 void
67 fail(std::string const& name, error_code ec);
68 void
69 setTimer();
70 void
72 void
74 void
76 void
78 void
80 void
82 void
84 void
86
87 template <class = void>
88 static boost::asio::ip::tcp::endpoint
89 parseEndpoint(std::string const& s, boost::system::error_code& ec)
90 {
93 is >> bep;
94 if (is.fail())
95 {
96 ec = boost::system::errc::make_error_code(boost::system::errc::invalid_argument);
97 return boost::asio::ip::tcp::endpoint{};
98 }
99
101 }
102};
103
104} // namespace xrpl
A version-independent IP address and port combination.
Definition IPEndpoint.h:17
A generic endpoint for log messages.
Definition Journal.h:38
Wraps a Journal::Sink to prefix its output with a string.
Definition WrappedSink.h:16
boost::system::error_code error_code
boost::beast::ssl_stream< middle_type > stream_type
void fail(std::string const &reason)
boost::asio::basic_waitable_timer< std::chrono::steady_clock > timer_
socket_type & socket_
boost::beast::http::request< boost::beast::http::empty_body > request_type
boost::beast::multi_buffer readBuf_
boost::asio::strand< boost::asio::io_context::executor_type > strand_
static boost::asio::ip::tcp::endpoint parseEndpoint(std::string const &s, boost::system::error_code &ec)
std::shared_ptr< boost::asio::ssl::context > shared_context
boost::beast::tcp_stream middle_type
void onRead(error_code ec)
endpoint_type remoteEndpoint_
void onConnect(error_code ec)
ConnectAttempt(Application &app, boost::asio::io_context &ioContext, endpoint_type remoteEndpoint, Resource::Consumer usage, shared_context const &context, Peer::id_t id, std::shared_ptr< PeerFinder::Slot > const &slot, beast::Journal journal, OverlayImpl &overlay)
stream_type & stream_
void onShutdown(error_code ec)
std::shared_ptr< PeerFinder::Slot > slot_
response_type response_
boost::asio::ip::tcp::socket socket_type
std::uint32_t const id_
std::unique_ptr< stream_type > streamPtr_
boost::asio::ip::tcp::endpoint endpoint_type
void onHandshake(error_code ec)
Resource::Consumer usage_
boost::beast::http::response< boost::beast::http::dynamic_body > response_type
beast::WrappedSink sink_
beast::Journal const journal_
void onWrite(error_code ec)
void onTimer(error_code ec)
std::uint32_t id_t
Uniquely identifies a peer.
An endpoint that consumes resources.
Definition Consumer.h:15
T fail(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
static boost::asio::ip::tcp::endpoint toAsioEndpoint(IP::Endpoint const &address)