rippled
InboundHandoff.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012-2021 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_INBOUNDHANDOFF_H_INCLUDED
21 #define RIPPLE_OVERLAY_INBOUNDHANDOFF_H_INCLUDED
22 
23 #include <ripple/overlay/impl/OverlayImpl.h>
24 
25 namespace ripple {
26 
32  public std::enable_shared_from_this<InboundHandoff>
33 {
34 private:
35  using error_code = boost::system::error_code;
36  using socket_type = boost::asio::ip::tcp::socket;
37  using middle_type = boost::beast::tcp_stream;
38  using stream_type = boost::beast::ssl_stream<middle_type>;
39  using id_t = Peer::id_t;
41  id_t const id_;
45  boost::asio::strand<boost::asio::executor> strand_;
52 
53 public:
54  virtual ~InboundHandoff() override = default;
55 
57  Application& app,
58  id_t id,
60  http_request_type&& request,
61  PublicKey const& publicKey,
63  Resource::Consumer consumer,
64  std::unique_ptr<stream_type>&& stream_ptr,
65  OverlayImpl& overlay);
66 
67  // This class isn't meant to be copied
68  InboundHandoff(InboundHandoff const&) = delete;
70  operator=(InboundHandoff const&) = delete;
71 
73  void
74  run();
76  void
77  stop() override;
78 
79 private:
81  void
82  sendResponse();
84  void
85  createPeer();
87  void
88  fail(std::string const& name, error_code const& ec);
90  void
91  fail(std::string const& reason);
93  void
94  close();
97  socket() const;
98 };
99 
100 } // namespace ripple
101 
102 #endif // RIPPLE_OVERLAY_INBOUNDHANDOFF_H_INCLUDED
ripple::Application
Definition: Application.h:116
ripple::InboundHandoff::slot_
const std::shared_ptr< PeerFinder::Slot > slot_
Definition: InboundHandoff.h:50
ripple::InboundHandoff::~InboundHandoff
virtual ~InboundHandoff() override=default
std::string
STL class.
std::shared_ptr
STL class.
std::pair
ripple::Peer::id_t
std::uint32_t id_t
Uniquely identifies a peer.
Definition: ripple/overlay/Peer.h:56
ripple::InboundHandoff::close
void close()
Close connection.
Definition: InboundHandoff.cpp:153
ripple::InboundHandoff::createPeer
void createPeer()
Instantiate and run the overlay peer.
Definition: InboundHandoff.cpp:163
ripple::InboundHandoff::usage_
Resource::Consumer usage_
Definition: InboundHandoff.h:49
ripple::InboundHandoff::strand_
boost::asio::strand< boost::asio::executor > strand_
Definition: InboundHandoff.h:45
ripple::InboundHandoff::app_
Application & app_
Definition: InboundHandoff.h:40
ripple::InboundHandoff::stream_ptr_
std::unique_ptr< stream_type > stream_ptr_
Definition: InboundHandoff.h:44
ripple::InboundHandoff::InboundHandoff
InboundHandoff(Application &app, id_t id, std::shared_ptr< PeerFinder::Slot > const &slot, http_request_type &&request, PublicKey const &publicKey, ProtocolVersion protocol, Resource::Consumer consumer, std::unique_ptr< stream_type > &&stream_ptr, OverlayImpl &overlay)
Definition: InboundHandoff.cpp:28
ripple::InboundHandoff::sink_
beast::WrappedSink sink_
Definition: InboundHandoff.h:42
ripple::PublicKey
A public key.
Definition: PublicKey.h:61
ripple::InboundHandoff::stop
void stop() override
Stop the child.
Definition: InboundHandoff.cpp:70
ripple::InboundHandoff::sendResponse
void sendResponse()
Send upgrade response to the client.
Definition: InboundHandoff.cpp:83
ripple::InboundHandoff::protocol_
ProtocolVersion protocol_
Definition: InboundHandoff.h:47
std::enable_shared_from_this
ripple::InboundHandoff::request_
http_request_type request_
Definition: InboundHandoff.h:51
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
ripple::InboundHandoff::stream_type
boost::beast::ssl_stream< middle_type > stream_type
Definition: InboundHandoff.h:38
ripple::InboundHandoff::fail
void fail(std::string const &name, error_code const &ec)
Log and close.
Definition: InboundHandoff.cpp:129
ripple::InboundHandoff::socket_type
boost::asio::ip::tcp::socket socket_type
Definition: InboundHandoff.h:36
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::InboundHandoff::middle_type
boost::beast::tcp_stream middle_type
Definition: InboundHandoff.h:37
protocol
Definition: ValidatorList.h:38
ripple::InboundHandoff::journal_
const beast::Journal journal_
Definition: InboundHandoff.h:43
ripple::Resource::Consumer
An endpoint that consumes resources.
Definition: Consumer.h:34
ripple::InboundHandoff::error_code
boost::system::error_code error_code
Definition: InboundHandoff.h:35
beast::WrappedSink
Wraps a Journal::Sink to prefix its output with a string.
Definition: WrappedSink.h:33
ripple::InboundHandoff::remote_address_
const beast::IP::Endpoint remote_address_
Definition: InboundHandoff.h:46
ripple::InboundHandoff::operator=
InboundHandoff & operator=(InboundHandoff const &)=delete
beast::IP::Endpoint
A version-independent IP address and port combination.
Definition: IPEndpoint.h:38
ripple::InboundHandoff::run
void run()
Start the handshake.
Definition: InboundHandoff.cpp:61
ripple::OverlayImpl
Definition: OverlayImpl.h:58
ripple::InboundHandoff::socket
socket_type & socket() const
Get underlying socket.
Definition: InboundHandoff.cpp:180
ripple::OverlayImpl::Child
Definition: OverlayImpl.h:61
ripple::InboundHandoff
Sends HTTP response.
Definition: InboundHandoff.h:31
ripple::http_request_type
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Definition: Handshake.h:47
std::unique_ptr< stream_type >
ripple::InboundHandoff::id_
const id_t id_
Definition: InboundHandoff.h:41
ripple::InboundHandoff::publicKey_
const PublicKey publicKey_
Definition: InboundHandoff.h:48