xrpld
Loading...
Searching...
No Matches
ConnectAttempt.h
1#pragma once
2
3#include <xrpld/app/main/Application.h>
4#include <xrpld/overlay/Peer.h>
5#include <xrpld/overlay/detail/OverlayImpl.h>
6
7#include <xrpl/beast/net/IPAddressConversion.h>
8#include <xrpl/beast/net/IPEndpoint.h>
9#include <xrpl/beast/utility/Journal.h>
10#include <xrpl/beast/utility/WrappedSink.h>
11#include <xrpl/peerfinder/Slot.h>
12#include <xrpl/resource/Consumer.h>
13
14#include <chrono>
15#include <cstdint>
16#include <memory>
17#include <sstream>
18#include <string>
19
20namespace xrpl {
21
26 public std::enable_shared_from_this<ConnectAttempt>
27{
28private:
29 using ErrorCode = boost::system::error_code;
30 using EndpointType = boost::asio::ip::tcp::endpoint;
31 using RequestType = boost::beast::http::request<boost::beast::http::empty_body>;
32 using ResponseType = boost::beast::http::response<boost::beast::http::dynamic_body>;
33
34 using SocketType = boost::asio::ip::tcp::socket;
35 using MiddleType = boost::beast::tcp_stream;
36 using StreamType = boost::beast::ssl_stream<MiddleType>;
38
45 boost::asio::strand<boost::asio::io_context::executor_type> strand_;
46 boost::asio::basic_waitable_timer<std::chrono::steady_clock> timer_;
50 boost::beast::multi_buffer readBuf_;
54
55public:
57 Application& app,
58 boost::asio::io_context& ioContext,
59 EndpointType remoteEndpoint,
61 SharedContext const& context,
62 Peer::ID id,
64 beast::Journal journal,
65 OverlayImpl& overlay);
66
67 ~ConnectAttempt() override;
68
69 void
70 stop() override;
71
72 void
73 run();
74
75private:
76 void
77 close();
78 void
79 fail(std::string const& reason);
80 void
81 fail(std::string const& name, ErrorCode ec);
82 void
83 setTimer();
84 void
86 void
88 void
90 void
92 void
94 void
95 onRead(ErrorCode ec);
96 void
98 void
100
101 template <class = void>
102 static boost::asio::ip::tcp::endpoint
103 parseEndpoint(std::string const& s, boost::system::error_code& ec)
104 {
106 std::istringstream is(s);
107 is >> bep;
108 if (is.fail())
109 {
110 ec = boost::system::errc::make_error_code(boost::system::errc::invalid_argument);
111 return boost::asio::ip::tcp::endpoint{};
112 }
113
115 }
116};
117
118} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
Wraps a Journal::Sink to prefix its output with a string.
Definition WrappedSink.h:19
A version-independent IP address and port combination.
Definition IPEndpoint.h:24
void fail(std::string const &reason)
EndpointType remoteEndpoint_
boost::beast::tcp_stream MiddleType
boost::asio::basic_waitable_timer< std::chrono::steady_clock > timer_
std::shared_ptr< boost::asio::ssl::context > SharedContext
boost::beast::multi_buffer readBuf_
boost::asio::strand< boost::asio::io_context::executor_type > strand_
ConnectAttempt(Application &app, boost::asio::io_context &ioContext, EndpointType remoteEndpoint, resource::Consumer usage, SharedContext const &context, Peer::ID id, std::shared_ptr< peer_finder::Slot > const &slot, beast::Journal journal, OverlayImpl &overlay)
static boost::asio::ip::tcp::endpoint parseEndpoint(std::string const &s, boost::system::error_code &ec)
std::unique_ptr< StreamType > streamPtr_
void onWrite(ErrorCode ec)
boost::asio::ip::tcp::socket SocketType
void onTimer(ErrorCode ec)
boost::beast::ssl_stream< MiddleType > StreamType
void onRead(ErrorCode ec)
std::shared_ptr< peer_finder::Slot > slot_
void onConnect(ErrorCode ec)
std::uint32_t const id_
boost::beast::http::request< boost::beast::http::empty_body > RequestType
void onHandshake(ErrorCode ec)
boost::beast::http::response< boost::beast::http::dynamic_body > ResponseType
resource::Consumer usage_
boost::system::error_code ErrorCode
beast::WrappedSink sink_
beast::Journal const journal_
void onShutdown(ErrorCode ec)
boost::asio::ip::tcp::endpoint EndpointType
std::uint32_t ID
Uniquely identifies a peer.
An endpoint that consumes resources.
Definition Consumer.h:20
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)