rippled
Loading...
Searching...
No Matches
ConnectAttempt.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_OVERLAY_CONNECTATTEMPT_H_INCLUDED
21#define RIPPLE_OVERLAY_CONNECTATTEMPT_H_INCLUDED
22
23#include <xrpld/overlay/detail/OverlayImpl.h>
24#include <xrpld/overlay/detail/Tuning.h>
25
26namespace ripple {
27
30 public std::enable_shared_from_this<ConnectAttempt>
31{
32private:
33 using error_code = boost::system::error_code;
34
35 using endpoint_type = boost::asio::ip::tcp::endpoint;
36
38 boost::beast::http::request<boost::beast::http::empty_body>;
39
41 boost::beast::http::response<boost::beast::http::dynamic_body>;
42
43 using socket_type = boost::asio::ip::tcp::socket;
44 using middle_type = boost::beast::tcp_stream;
45 using stream_type = boost::beast::ssl_stream<middle_type>;
47
54 boost::asio::io_service::strand strand_;
55 boost::asio::basic_waitable_timer<std::chrono::steady_clock> timer_;
59 boost::beast::multi_buffer read_buf_;
63
64public:
66 Application& app,
67 boost::asio::io_service& io_service,
68 endpoint_type const& remote_endpoint,
70 shared_context const& context,
73 beast::Journal journal,
74 OverlayImpl& overlay);
75
77
78 void
79 stop() override;
80
81 void
82 run();
83
84private:
85 void
86 close();
87 void
88 fail(std::string const& reason);
89 void
90 fail(std::string const& name, error_code ec);
91 void
92 setTimer();
93 void
95 void
97 void
99 void
101 void
103 void
104 onRead(error_code ec);
105 void
107 void
109
110 template <class = void>
111 static boost::asio::ip::tcp::endpoint
112 parse_endpoint(std::string const& s, boost::system::error_code& ec)
113 {
115 std::istringstream is(s);
116 is >> bep;
117 if (is.fail())
118 {
119 ec = boost::system::errc::make_error_code(
120 boost::system::errc::invalid_argument);
121 return boost::asio::ip::tcp::endpoint{};
122 }
123
125 }
126};
127
128} // namespace ripple
129
130#endif
A version-independent IP address and port combination.
Definition: IPEndpoint.h:39
A generic endpoint for log messages.
Definition: Journal.h:59
Wraps a Journal::Sink to prefix its output with a string.
Definition: WrappedSink.h:34
Manages an outbound connection attempt.
std::uint32_t const id_
boost::beast::tcp_stream middle_type
boost::asio::ip::tcp::socket socket_type
boost::asio::io_service::strand strand_
boost::system::error_code error_code
std::unique_ptr< stream_type > stream_ptr_
std::shared_ptr< PeerFinder::Slot > slot_
Resource::Consumer usage_
void onHandshake(error_code ec)
response_type response_
boost::asio::ip::tcp::endpoint endpoint_type
void onWrite(error_code ec)
void onTimer(error_code ec)
boost::beast::http::response< boost::beast::http::dynamic_body > response_type
void onShutdown(error_code ec)
boost::beast::ssl_stream< middle_type > stream_type
boost::beast::multi_buffer read_buf_
void onConnect(error_code ec)
beast::WrappedSink sink_
void fail(std::string const &reason)
void onRead(error_code ec)
static boost::asio::ip::tcp::endpoint parse_endpoint(std::string const &s, boost::system::error_code &ec)
beast::Journal const journal_
boost::beast::http::request< boost::beast::http::empty_body > request_type
boost::asio::basic_waitable_timer< std::chrono::steady_clock > timer_
endpoint_type remote_endpoint_
An endpoint that consumes resources.
Definition: Consumer.h:35
T fail(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
static boost::asio::ip::tcp::endpoint to_asio_endpoint(IP::Endpoint const &address)