rippled
ServerHandlerImp.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_RPC_SERVERHANDLERIMP_H_INCLUDED
21 #define RIPPLE_RPC_SERVERHANDLERIMP_H_INCLUDED
22 
23 #include <ripple/app/main/CollectorManager.h>
24 #include <ripple/core/JobQueue.h>
25 #include <ripple/json/Output.h>
26 #include <ripple/rpc/RPCHandler.h>
27 #include <ripple/rpc/impl/WSInfoSub.h>
28 #include <ripple/server/Server.h>
29 #include <ripple/server/Session.h>
30 #include <ripple/server/WSSession.h>
31 #include <boost/beast/core/tcp_stream.hpp>
32 #include <boost/beast/ssl/ssl_stream.hpp>
33 #include <boost/utility/string_view.hpp>
34 #include <map>
35 #include <mutex>
36 #include <vector>
37 
38 namespace ripple {
39 
40 inline bool
41 operator<(Port const& lhs, Port const& rhs)
42 {
43  return lhs.name < rhs.name;
44 }
45 
47 {
48 public:
49  struct Setup
50  {
51  explicit Setup() = default;
52 
54 
55  // Memberspace
56  struct client_t
57  {
58  explicit client_t() = default;
59 
60  bool secure = false;
67  };
68 
69  // Configuration when acting in client role
71 
72  // Configuration for the Overlay
73  struct overlay_t
74  {
75  explicit overlay_t() = default;
76 
77  boost::asio::ip::address ip;
79  };
80 
82 
83  void
84  makeContexts();
85  };
86 
87 private:
88  using socket_type = boost::beast::tcp_stream;
89  using stream_type = boost::beast::ssl_stream<socket_type>;
90 
103 
104 public:
106  Application& app,
107  Stoppable& parent,
108  boost::asio::io_service& io_service,
109  JobQueue& jobQueue,
110  NetworkOPs& networkOPs,
111  Resource::Manager& resourceManager,
112  CollectorManager& cm);
113 
115 
117 
118  void
119  setup(Setup const& setup, beast::Journal journal);
120 
121  Setup const&
122  setup() const
123  {
124  return setup_;
125  }
126 
127  //
128  // Stoppable
129  //
130 
131  void
132  onStop() override;
133 
134  //
135  // Handler
136  //
137 
138  bool
139  onAccept(Session& session, boost::asio::ip::tcp::endpoint endpoint);
140 
141  Handoff
142  onHandoff(
143  Session& session,
145  http_request_type&& request,
146  boost::asio::ip::tcp::endpoint const& remote_address);
147 
148  Handoff
150  Session& session,
151  http_request_type&& request,
152  boost::asio::ip::tcp::endpoint const& remote_address)
153  {
154  return onHandoff(
155  session,
156  {},
157  std::forward<http_request_type>(request),
158  remote_address);
159  }
160 
161  void
162  onRequest(Session& session);
163 
164  void
165  onWSMessage(
168 
169  void
170  onClose(Session& session, boost::system::error_code const&);
171 
172  void
173  onStopped(Server&);
174 
175 private:
178  std::shared_ptr<WSSession> const& session,
180  Json::Value const& jv);
181 
182  void
186 
187  void
189  Port const& port,
190  std::string const& request,
191  beast::IP::Endpoint const& remoteIPAddress,
192  Output&&,
194  boost::string_view forwardedFor,
195  boost::string_view user);
196 
197  Handoff
198  statusResponse(http_request_type const& request) const;
199 };
200 
201 } // namespace ripple
202 
203 #endif
ripple::ServerHandlerImp::stream_type
boost::beast::ssl_stream< socket_type > stream_type
Definition: ServerHandlerImp.h:89
ripple::NetworkOPs
Provides server functionality for clients.
Definition: NetworkOPs.h:88
ripple::Application
Definition: Application.h:101
ripple::ServerHandlerImp::count_
std::map< std::reference_wrapper< Port const >, int > count_
Definition: ServerHandlerImp.h:102
ripple::ServerHandlerImp::Output
Json::Output Output
Definition: ServerHandlerImp.h:116
ripple::ServerHandlerImp::Setup::client_t::user
std::string user
Definition: ServerHandlerImp.h:63
ripple::ServerHandlerImp::m_journal
beast::Journal m_journal
Definition: ServerHandlerImp.h:93
std::string
STL class.
std::shared_ptr
STL class.
beast::insight::Counter
A metric for measuring an integral value.
Definition: Counter.h:38
ripple::ServerHandlerImp::m_jobQueue
JobQueue & m_jobQueue
Definition: ServerHandlerImp.h:97
ripple::ServerHandlerImp::setup_
Setup setup_
Definition: ServerHandlerImp.h:96
ripple::ServerHandlerImp::Setup::client_t::secure
bool secure
Definition: ServerHandlerImp.h:60
vector
ripple::ServerHandlerImp::Setup::client_t::admin_user
std::string admin_user
Definition: ServerHandlerImp.h:65
ripple::ServerHandlerImp::Setup
Definition: ServerHandlerImp.h:49
ripple::CollectorManager
Provides the beast::insight::Collector service.
Definition: CollectorManager.h:29
ripple::ServerHandlerImp::rpc_requests_
beast::insight::Counter rpc_requests_
Definition: ServerHandlerImp.h:98
ripple::ServerHandlerImp::Setup::client_t::port
std::uint16_t port
Definition: ServerHandlerImp.h:62
std::function
ripple::Port::name
std::string name
Definition: Port.h:48
ripple::Session
Persistent state information for a connection session.
Definition: Session.h:40
ripple::ServerHandlerImp::Setup::overlay_t::ip
boost::asio::ip::address ip
Definition: ServerHandlerImp.h:77
ripple::ServerHandlerImp::onRequest
void onRequest(Session &session)
Definition: ServerHandlerImp.cpp:268
ripple::ServerHandlerImp::Setup::makeContexts
void makeContexts()
Definition: ServerHandlerImp.cpp:968
ripple::ServerHandlerImp::statusResponse
Handoff statusResponse(http_request_type const &request) const
Definition: ServerHandlerImp.cpp:936
ripple::ServerHandlerImp::onClose
void onClose(Session &session, boost::system::error_code const &)
Definition: ServerHandlerImp.cpp:358
ripple::ServerHandlerImp::m_networkOPs
NetworkOPs & m_networkOPs
Definition: ServerHandlerImp.h:94
ripple::ServerHandlerImp::Setup::client_t::ip
std::string ip
Definition: ServerHandlerImp.h:61
ripple::ServerHandlerImp::ServerHandlerImp
ServerHandlerImp(Application &app, Stoppable &parent, boost::asio::io_service &io_service, JobQueue &jobQueue, NetworkOPs &networkOPs, Resource::Manager &resourceManager, CollectorManager &cm)
Definition: ServerHandlerImp.cpp:104
ripple::ServerHandlerImp::onHandoff
Handoff onHandoff(Session &session, http_request_type &&request, boost::asio::ip::tcp::endpoint const &remote_address)
Definition: ServerHandlerImp.h:149
ripple::ServerHandlerImp::rpc_time_
beast::insight::Event rpc_time_
Definition: ServerHandlerImp.h:100
ripple::ServerHandlerImp::Setup::overlay_t::port
std::uint16_t port
Definition: ServerHandlerImp.h:78
ripple::Stoppable
Provides an interface for starting and stopping.
Definition: Stoppable.h:201
ripple::ServerHandlerImp::onStop
void onStop() override
Override called when the stop notification is issued.
Definition: ServerHandlerImp.cpp:141
ripple::ServerHandlerImp::processRequest
void processRequest(Port const &port, std::string const &request, beast::IP::Endpoint const &remoteIPAddress, Output &&, std::shared_ptr< JobQueue::Coro > coro, boost::string_view forwardedFor, boost::string_view user)
Definition: ServerHandlerImp.cpp:556
ripple::operator<
bool operator<(CanonicalTXSet::Key const &lhs, CanonicalTXSet::Key const &rhs)
Definition: CanonicalTXSet.cpp:25
ripple::ServerHandlerImp
Definition: ServerHandlerImp.h:46
ripple::ServerHandlerImp::processSession
Json::Value processSession(std::shared_ptr< WSSession > const &session, std::shared_ptr< JobQueue::Coro > const &coro, Json::Value const &jv)
Definition: ServerHandlerImp.cpp:373
ripple::ServerHandlerImp::Setup::client_t::client_t
client_t()=default
ripple::ServerHandlerImp::onAccept
bool onAccept(Session &session, boost::asio::ip::tcp::endpoint endpoint)
Definition: ServerHandlerImp.cpp:149
ripple::forwardedFor
boost::string_view forwardedFor(http_request_type const &request)
Definition: Role.cpp:126
ripple::Server
A multi-protocol server.
Definition: ServerImpl.h:44
beast::insight::Event
A metric for reporting event timing.
Definition: Event.h:42
ripple::ServerHandlerImp::Setup::client
client_t client
Definition: ServerHandlerImp.h:70
ripple::ServerHandlerImp::rpc_size_
beast::insight::Event rpc_size_
Definition: ServerHandlerImp.h:99
ripple::ServerHandlerImp::socket_type
boost::beast::tcp_stream socket_type
Definition: ServerHandlerImp.h:88
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint16_t
ripple::ServerHandlerImp::Setup::overlay_t
Definition: ServerHandlerImp.h:73
ripple::Port
Configuration information for a Server listening port.
Definition: Port.h:44
map
ripple::ServerHandlerImp::app_
Application & app_
Definition: ServerHandlerImp.h:91
ripple::ServerHandlerImp::m_server
std::unique_ptr< Server > m_server
Definition: ServerHandlerImp.h:95
ripple::ServerHandlerImp::m_resourceManager
Resource::Manager & m_resourceManager
Definition: ServerHandlerImp.h:92
ripple::JobQueue
A pool of threads to perform work.
Definition: JobQueue.h:55
ripple::Resource::Manager
Tracks load and resource consumption.
Definition: ResourceManager.h:36
ripple::ServerHandlerImp::Setup::client_t::admin_password
std::string admin_password
Definition: ServerHandlerImp.h:66
ripple::ServerHandlerImp::onWSMessage
void onWSMessage(std::shared_ptr< WSSession > session, std::vector< boost::asio::const_buffer > const &buffers)
Definition: ServerHandlerImp.cpp:308
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::ServerHandlerImp::setup
Setup const & setup() const
Definition: ServerHandlerImp.h:122
ripple::ServerHandlerImp::Setup::ports
std::vector< Port > ports
Definition: ServerHandlerImp.h:53
ripple::Handoff
Used to indicate the result of a server connection handoff.
Definition: Handoff.h:37
mutex
ripple::ServerHandlerImp::~ServerHandlerImp
~ServerHandlerImp()
Definition: ServerHandlerImp.cpp:126
beast::IP::Endpoint
A version-independent IP address and port combination.
Definition: IPEndpoint.h:39
ripple::ServerHandlerImp::Setup::overlay_t::overlay_t
overlay_t()=default
ripple::ServerHandlerImp::Setup::Setup
Setup()=default
ripple::ServerHandlerImp::Setup::client_t
Definition: ServerHandlerImp.h:56
ripple::ServerHandlerImp::Setup::overlay
overlay_t overlay
Definition: ServerHandlerImp.h:81
ripple::ServerHandlerImp::Setup::client_t::password
std::string password
Definition: ServerHandlerImp.h:64
ripple::http_request_type
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Definition: Handshake.h:47
std::unique_ptr
STL class.
ripple::ServerHandlerImp::onStopped
void onStopped(Server &)
Definition: ServerHandlerImp.cpp:365
ripple::ServerHandlerImp::onHandoff
Handoff onHandoff(Session &session, std::unique_ptr< stream_type > &&bundle, http_request_type &&request, boost::asio::ip::tcp::endpoint const &remote_address)
Definition: ServerHandlerImp.cpp:168
Json::Output
std::function< void(boost::beast::string_view const &)> Output
Definition: json/Output.h:30
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::ServerHandlerImp::countlock_
std::mutex countlock_
Definition: ServerHandlerImp.h:101