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/core/JobQueue.h>
24 #include <ripple/rpc/impl/WSInfoSub.h>
25 #include <ripple/server/Server.h>
26 #include <ripple/server/Session.h>
27 #include <ripple/server/WSSession.h>
28 #include <ripple/rpc/RPCHandler.h>
29 #include <ripple/app/main/CollectorManager.h>
30 #include <ripple/json/Output.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
41 bool operator< (Port const& lhs, Port const& rhs)
42 {
43  return lhs.name < rhs.name;
44 }
45 
47  : public Stoppable
48 {
49 public:
50  struct Setup
51  {
52  explicit Setup() = default;
53 
55 
56  // Memberspace
57  struct client_t
58  {
59  explicit client_t() = default;
60 
61  bool secure = false;
68  };
69 
70  // Configuration when acting in client role
72 
73  // Configuration for the Overlay
74  struct overlay_t
75  {
76  explicit overlay_t() = default;
77 
78  boost::asio::ip::address ip;
80  };
81 
83 
84  void
85  makeContexts();
86  };
87 
88 private:
89  using socket_type = boost::beast::tcp_stream;
90  using stream_type = boost::beast::ssl_stream <socket_type>;
91 
104 
105 public:
106  ServerHandlerImp (Application& app, Stoppable& parent,
107  boost::asio::io_service& io_service, JobQueue& jobQueue,
108  NetworkOPs& networkOPs, Resource::Manager& resourceManager,
109  CollectorManager& cm);
110 
112 
114 
115  void
116  setup (Setup const& setup, beast::Journal journal);
117 
118  Setup const&
119  setup() const
120  {
121  return setup_;
122  }
123 
124  //
125  // Stoppable
126  //
127 
128  void
129  onStop() override;
130 
131  //
132  // Handler
133  //
134 
135  bool
136  onAccept (Session& session,
137  boost::asio::ip::tcp::endpoint endpoint);
138 
139  Handoff
140  onHandoff(
141  Session& session,
143  http_request_type&& request,
144  boost::asio::ip::tcp::endpoint const& remote_address);
145 
146  Handoff
148  Session& session,
149  http_request_type&& request,
150  boost::asio::ip::tcp::endpoint const& remote_address)
151  {
152  return onHandoff(
153  session,
154  {},
155  std::forward<http_request_type>(request),
156  remote_address);
157  }
158 
159  void
160  onRequest (Session& session);
161 
162  void
165 
166  void
167  onClose (Session& session,
168  boost::system::error_code const&);
169 
170  void
171  onStopped (Server&);
172 
173 private:
176  std::shared_ptr<WSSession> const& session,
178  Json::Value const& jv);
179 
180  void
183 
184  void
185  processRequest (Port const& port, std::string const& request,
186  beast::IP::Endpoint const& remoteIPAddress, Output&&,
188  boost::string_view forwardedFor, boost::string_view user);
189 
190  Handoff
191  statusResponse(http_request_type const& request) const;
192 };
193 
194 }
195 
196 #endif
ripple::NetworkOPs
Provides server functionality for clients.
Definition: NetworkOPs.h:89
ripple::Application
Definition: Application.h:85
ripple::ServerHandlerImp::count_
std::map< std::reference_wrapper< Port const >, int > count_
Definition: ServerHandlerImp.h:103
ripple::ServerHandlerImp::Output
Json::Output Output
Definition: ServerHandlerImp.h:113
ripple::ServerHandlerImp::Setup::client_t::user
std::string user
Definition: ServerHandlerImp.h:64
ripple::ServerHandlerImp::m_journal
beast::Journal m_journal
Definition: ServerHandlerImp.h:94
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:98
ripple::ServerHandlerImp::setup_
Setup setup_
Definition: ServerHandlerImp.h:97
ripple::ServerHandlerImp::stream_type
boost::beast::ssl_stream< socket_type > stream_type
Definition: ServerHandlerImp.h:90
ripple::http_request_type
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Definition: Handoff.h:31
ripple::ServerHandlerImp::Setup::client_t::secure
bool secure
Definition: ServerHandlerImp.h:61
vector
ripple::ServerHandlerImp::Setup::client_t::admin_user
std::string admin_user
Definition: ServerHandlerImp.h:66
ripple::ServerHandlerImp::Setup
Definition: ServerHandlerImp.h:50
ripple::CollectorManager
Provides the beast::insight::Collector service.
Definition: CollectorManager.h:29
ripple::ServerHandlerImp::rpc_requests_
beast::insight::Counter rpc_requests_
Definition: ServerHandlerImp.h:99
ripple::ServerHandlerImp::Setup::client_t::port
std::uint16_t port
Definition: ServerHandlerImp.h:63
std::function
ripple::Port::name
std::string name
Definition: Port.h:42
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:78
ripple::ServerHandlerImp::onRequest
void onRequest(Session &session)
Definition: ServerHandlerImp.cpp:274
ripple::ServerHandlerImp::Setup::makeContexts
void makeContexts()
Definition: ServerHandlerImp.cpp:962
ripple::ServerHandlerImp::statusResponse
Handoff statusResponse(http_request_type const &request) const
Definition: ServerHandlerImp.cpp:929
ripple::ServerHandlerImp::onClose
void onClose(Session &session, boost::system::error_code const &)
Definition: ServerHandlerImp.cpp:365
ripple::ServerHandlerImp::m_networkOPs
NetworkOPs & m_networkOPs
Definition: ServerHandlerImp.h:95
ripple::ServerHandlerImp::Setup::client_t::ip
std::string ip
Definition: ServerHandlerImp.h:62
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:112
ripple::ServerHandlerImp::onHandoff
Handoff onHandoff(Session &session, http_request_type &&request, boost::asio::ip::tcp::endpoint const &remote_address)
Definition: ServerHandlerImp.h:147
ripple::ServerHandlerImp::rpc_time_
beast::insight::Event rpc_time_
Definition: ServerHandlerImp.h:101
ripple::ServerHandlerImp::Setup::overlay_t::port
std::uint16_t port
Definition: ServerHandlerImp.h:79
ripple::Stoppable
Provides an interface for starting and stopping.
Definition: Stoppable.h:200
ripple::ServerHandlerImp::onStop
void onStop() override
Override called when the stop notification is issued.
Definition: ServerHandlerImp.cpp:146
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:559
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:381
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:154
ripple::forwardedFor
boost::string_view forwardedFor(http_request_type const &request)
Definition: Role.cpp:112
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:71
ripple::ServerHandlerImp::rpc_size_
beast::insight::Event rpc_size_
Definition: ServerHandlerImp.h:100
ripple::ServerHandlerImp::socket_type
boost::beast::tcp_stream socket_type
Definition: ServerHandlerImp.h:89
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:60
std::uint16_t
ripple::ServerHandlerImp::Setup::overlay_t
Definition: ServerHandlerImp.h:74
ripple::Port
Configuration information for a Server listening port.
Definition: Port.h:38
map
ripple::ServerHandlerImp::app_
Application & app_
Definition: ServerHandlerImp.h:92
ripple::ServerHandlerImp::m_server
std::unique_ptr< Server > m_server
Definition: ServerHandlerImp.h:96
ripple::ServerHandlerImp::m_resourceManager
Resource::Manager & m_resourceManager
Definition: ServerHandlerImp.h:93
Json::Output
std::function< void(boost::beast::string_view const &)> Output
Definition: json/Output.h:30
ripple::JobQueue
A pool of threads to perform work.
Definition: JobQueue.h:56
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:67
ripple::ServerHandlerImp::onWSMessage
void onWSMessage(std::shared_ptr< WSSession > session, std::vector< boost::asio::const_buffer > const &buffers)
Definition: ServerHandlerImp.cpp:310
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:119
ripple::ServerHandlerImp::Setup::ports
std::vector< Port > ports
Definition: ServerHandlerImp.h:54
ripple::Handoff
Used to indicate the result of a server connection handoff.
Definition: Handoff.h:37
mutex
ripple::ServerHandlerImp::~ServerHandlerImp
~ServerHandlerImp()
Definition: ServerHandlerImp.cpp:131
beast::IP::Endpoint
A version-independent IP address and port combination.
Definition: IPEndpoint.h:39
ripple::operator<
bool operator<(base_uint< Bits, Tag > const &a, base_uint< Bits, Tag > const &b)
Definition: base_uint.h:456
ripple::ServerHandlerImp::Setup::overlay_t::overlay_t
overlay_t()=default
ripple::ServerHandlerImp::Setup::Setup
Setup()=default
ripple::ServerHandlerImp::Setup::client_t
Definition: ServerHandlerImp.h:57
ripple::ServerHandlerImp::Setup::overlay
overlay_t overlay
Definition: ServerHandlerImp.h:82
ripple::ServerHandlerImp::Setup::client_t::password
std::string password
Definition: ServerHandlerImp.h:65
std::unique_ptr
STL class.
ripple::ServerHandlerImp::onStopped
void onStopped(Server &)
Definition: ServerHandlerImp.cpp:373
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:173
Json::Value
Represents a JSON value.
Definition: json_value.h:141
ripple::ServerHandlerImp::countlock_
std::mutex countlock_
Definition: ServerHandlerImp.h:102