xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
overlay
detail
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
20
namespace
xrpl
{
21
25
class
ConnectAttempt
:
public
OverlayImpl::Child
,
26
public
std::enable_shared_from_this
<ConnectAttempt>
27
{
28
private
:
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>;
37
using
SharedContext
=
std::shared_ptr<boost::asio::ssl::context>
;
38
39
Application
&
app_
;
40
std::uint32_t
const
id_
;
41
beast::WrappedSink
sink_
;
42
beast::Journal
const
journal_
;
43
EndpointType
remoteEndpoint_
;
44
resource::Consumer
usage_
;
45
boost::asio::strand<boost::asio::io_context::executor_type>
strand_
;
46
boost::asio::basic_waitable_timer<std::chrono::steady_clock>
timer_
;
47
std::unique_ptr<StreamType>
streamPtr_
;
48
SocketType
&
socket_
;
49
StreamType
&
stream_
;
50
boost::beast::multi_buffer
readBuf_
;
51
ResponseType
response_
;
52
std::shared_ptr<peer_finder::Slot>
slot_
;
53
RequestType
req_
;
54
55
public
:
56
ConnectAttempt
(
57
Application
& app,
58
boost::asio::io_context& ioContext,
59
EndpointType
remoteEndpoint,
60
resource::Consumer
usage,
61
SharedContext
const
& context,
62
Peer::ID
id
,
63
std::shared_ptr<peer_finder::Slot>
const
& slot,
64
beast::Journal
journal,
65
OverlayImpl
& overlay);
66
67
~ConnectAttempt
()
override
;
68
69
void
70
stop
()
override
;
71
72
void
73
run
();
74
75
private
:
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
85
cancelTimer
();
86
void
87
onTimer
(
ErrorCode
ec);
88
void
89
onConnect
(
ErrorCode
ec);
90
void
91
onHandshake
(
ErrorCode
ec);
92
void
93
onWrite
(
ErrorCode
ec);
94
void
95
onRead
(
ErrorCode
ec);
96
void
97
onShutdown
(
ErrorCode
ec);
98
void
99
processResponse
();
100
101
template
<
class
=
void
>
102
static
boost::asio::ip::tcp::endpoint
103
parseEndpoint
(
std::string
const
& s, boost::system::error_code& ec)
104
{
105
beast::ip::Endpoint
bep;
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
114
return
beast::IPAddressConversion::toAsioEndpoint
(bep);
115
}
116
};
117
118
}
// namespace xrpl
std::istringstream
std::string
chrono
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:44
beast::WrappedSink
Wraps a Journal::Sink to prefix its output with a string.
Definition
WrappedSink.h:19
beast::ip::Endpoint
A version-independent IP address and port combination.
Definition
IPEndpoint.h:24
xrpl::Application
Definition
Application.h:94
xrpl::ConnectAttempt::socket_
SocketType & socket_
Definition
ConnectAttempt.h:48
xrpl::ConnectAttempt::fail
void fail(std::string const &reason)
Definition
ConnectAttempt.cpp:134
xrpl::ConnectAttempt::remoteEndpoint_
EndpointType remoteEndpoint_
Definition
ConnectAttempt.h:43
xrpl::ConnectAttempt::MiddleType
boost::beast::tcp_stream MiddleType
Definition
ConnectAttempt.h:35
xrpl::ConnectAttempt::timer_
boost::asio::basic_waitable_timer< std::chrono::steady_clock > timer_
Definition
ConnectAttempt.h:46
xrpl::ConnectAttempt::SharedContext
std::shared_ptr< boost::asio::ssl::context > SharedContext
Definition
ConnectAttempt.h:37
xrpl::ConnectAttempt::readBuf_
boost::beast::multi_buffer readBuf_
Definition
ConnectAttempt.h:50
xrpl::ConnectAttempt::processResponse
void processResponse()
Definition
ConnectAttempt.cpp:371
xrpl::ConnectAttempt::strand_
boost::asio::strand< boost::asio::io_context::executor_type > strand_
Definition
ConnectAttempt.h:45
xrpl::ConnectAttempt::ConnectAttempt
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)
Definition
ConnectAttempt.cpp:48
xrpl::ConnectAttempt::parseEndpoint
static boost::asio::ip::tcp::endpoint parseEndpoint(std::string const &s, boost::system::error_code &ec)
Definition
ConnectAttempt.h:103
xrpl::ConnectAttempt::setTimer
void setTimer()
Definition
ConnectAttempt.cpp:148
xrpl::ConnectAttempt::streamPtr_
std::unique_ptr< StreamType > streamPtr_
Definition
ConnectAttempt.h:47
xrpl::ConnectAttempt::stop
void stop() override
Definition
ConnectAttempt.cpp:85
xrpl::ConnectAttempt::onWrite
void onWrite(ErrorCode ec)
Definition
ConnectAttempt.cpp:294
xrpl::ConnectAttempt::req_
RequestType req_
Definition
ConnectAttempt.h:53
xrpl::ConnectAttempt::~ConnectAttempt
~ConnectAttempt() override
Definition
ConnectAttempt.cpp:77
xrpl::ConnectAttempt::SocketType
boost::asio::ip::tcp::socket SocketType
Definition
ConnectAttempt.h:34
xrpl::ConnectAttempt::onTimer
void onTimer(ErrorCode ec)
Definition
ConnectAttempt.cpp:179
xrpl::ConnectAttempt::StreamType
boost::beast::ssl_stream< MiddleType > StreamType
Definition
ConnectAttempt.h:36
xrpl::ConnectAttempt::response_
ResponseType response_
Definition
ConnectAttempt.h:51
xrpl::ConnectAttempt::onRead
void onRead(ErrorCode ec)
Definition
ConnectAttempt.cpp:320
xrpl::ConnectAttempt::slot_
std::shared_ptr< peer_finder::Slot > slot_
Definition
ConnectAttempt.h:52
xrpl::ConnectAttempt::onConnect
void onConnect(ErrorCode ec)
Definition
ConnectAttempt.cpp:199
xrpl::ConnectAttempt::stream_
StreamType & stream_
Definition
ConnectAttempt.h:49
xrpl::ConnectAttempt::close
void close()
Definition
ConnectAttempt.cpp:113
xrpl::ConnectAttempt::id_
std::uint32_t const id_
Definition
ConnectAttempt.h:40
xrpl::ConnectAttempt::RequestType
boost::beast::http::request< boost::beast::http::empty_body > RequestType
Definition
ConnectAttempt.h:31
xrpl::ConnectAttempt::run
void run()
Definition
ConnectAttempt.cpp:100
xrpl::ConnectAttempt::onHandshake
void onHandshake(ErrorCode ec)
Definition
ConnectAttempt.cpp:233
xrpl::ConnectAttempt::ResponseType
boost::beast::http::response< boost::beast::http::dynamic_body > ResponseType
Definition
ConnectAttempt.h:32
xrpl::ConnectAttempt::app_
Application & app_
Definition
ConnectAttempt.h:39
xrpl::ConnectAttempt::usage_
resource::Consumer usage_
Definition
ConnectAttempt.h:44
xrpl::ConnectAttempt::ErrorCode
boost::system::error_code ErrorCode
Definition
ConnectAttempt.h:29
xrpl::ConnectAttempt::sink_
beast::WrappedSink sink_
Definition
ConnectAttempt.h:41
xrpl::ConnectAttempt::journal_
beast::Journal const journal_
Definition
ConnectAttempt.h:42
xrpl::ConnectAttempt::onShutdown
void onShutdown(ErrorCode ec)
Definition
ConnectAttempt.cpp:351
xrpl::ConnectAttempt::cancelTimer
void cancelTimer()
Definition
ConnectAttempt.cpp:166
xrpl::ConnectAttempt::EndpointType
boost::asio::ip::tcp::endpoint EndpointType
Definition
ConnectAttempt.h:30
xrpl::OverlayImpl::Child
Definition
OverlayImpl.h:73
xrpl::OverlayImpl
Definition
OverlayImpl.h:70
xrpl::Peer::ID
std::uint32_t ID
Uniquely identifies a peer.
Definition
xrpld/overlay/Peer.h:41
xrpl::resource::Consumer
An endpoint that consumes resources.
Definition
Consumer.h:20
cstdint
std::enable_shared_from_this
std::istringstream::fail
T fail(T... args)
std::uint32_t
memory
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
std::shared_ptr
sstream
string
beast::IPAddressConversion::toAsioEndpoint
static boost::asio::ip::tcp::endpoint toAsioEndpoint(ip::Endpoint const &address)
Definition
IPAddressConversion.h:60
std::unique_ptr
Generated by
1.17.0