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 error_code = boost::system::error_code;
30 using endpoint_type = boost::asio::ip::tcp::endpoint;
31 using request_type = boost::beast::http::request<boost::beast::http::empty_body>;
32 using response_type = boost::beast::http::response<boost::beast::http::dynamic_body>;
33
34 using socket_type = boost::asio::ip::tcp::socket;
35 using middle_type = boost::beast::tcp_stream;
36 using stream_type = boost::beast::ssl_stream<middle_type>;
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 endpoint_type remoteEndpoint,
61 shared_context const& context,
62 Peer::id_t 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, error_code ec);
82 void
83 setTimer();
84 void
86 void
88 void
90 void
92 void
94 void
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
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)
stream_type & stream_
void onShutdown(error_code ec)
response_type response_
boost::asio::ip::tcp::socket socket_type
std::shared_ptr< peer_finder::Slot > slot_
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)
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< peer_finder::Slot > const &slot, beast::Journal journal, OverlayImpl &overlay)
std::uint32_t id_t
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)