rippled
Loading...
Searching...
No Matches
ServerHandler.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_SERVERHANDLER_H_INCLUDED
21#define RIPPLE_RPC_SERVERHANDLER_H_INCLUDED
22
23#include <xrpld/app/main/CollectorManager.h>
24#include <xrpld/core/JobQueue.h>
25#include <xrpld/rpc/RPCHandler.h>
26#include <xrpld/rpc/detail/WSInfoSub.h>
27#include <xrpl/json/Output.h>
28#include <xrpl/server/Server.h>
29#include <xrpl/server/Session.h>
30#include <xrpl/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 <condition_variable>
35#include <map>
36#include <mutex>
37#include <vector>
38
39namespace ripple {
40
41inline bool
42operator<(Port const& lhs, Port const& rhs)
43{
44 return lhs.name < rhs.name;
45}
46
48{
49public:
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
86 };
87
88private:
89 using socket_type = boost::beast::tcp_stream;
90 using stream_type = boost::beast::ssl_stream<socket_type>;
91
104 bool stopped_{false};
106
107 // A private type used to restrict access to the ServerHandler constructor.
109 {
110 explicit ServerHandlerCreator() = default;
111 };
112
113 // Friend declaration that allows make_ServerHandler to access the
114 // private type that restricts access to the ServerHandler ctor.
117 Application& app,
118 boost::asio::io_service&,
119 JobQueue&,
120 NetworkOPs&,
122 CollectorManager& cm);
123
124public:
125 // Must be public so make_unique can call it.
128 Application& app,
129 boost::asio::io_service& io_service,
130 JobQueue& jobQueue,
131 NetworkOPs& networkOPs,
132 Resource::Manager& resourceManager,
133 CollectorManager& cm);
134
136
138
139 void
140 setup(Setup const& setup, beast::Journal journal);
141
142 Setup const&
143 setup() const
144 {
145 return setup_;
146 }
147
148 void
149 stop();
150
151 //
152 // Handler
153 //
154
155 bool
156 onAccept(Session& session, boost::asio::ip::tcp::endpoint endpoint);
157
158 Handoff
159 onHandoff(
160 Session& session,
162 http_request_type&& request,
163 boost::asio::ip::tcp::endpoint const& remote_address);
164
165 Handoff
167 Session& session,
168 http_request_type&& request,
169 boost::asio::ip::tcp::endpoint const& remote_address)
170 {
171 return onHandoff(
172 session,
173 {},
174 std::forward<http_request_type>(request),
175 remote_address);
176 }
177
178 void
179 onRequest(Session& session);
180
181 void
185
186 void
187 onClose(Session& session, boost::system::error_code const&);
188
189 void
191
192private:
195 std::shared_ptr<WSSession> const& session,
197 Json::Value const& jv);
198
199 void
203
204 void
206 Port const& port,
207 std::string const& request,
208 beast::IP::Endpoint const& remoteIPAddress,
209 Output&&,
212 std::string_view user);
213
214 Handoff
215 statusResponse(http_request_type const& request) const;
216};
217
218ServerHandler::Setup
219setup_ServerHandler(Config const& c, std::ostream&& log);
220
223 Application& app,
224 boost::asio::io_service&,
225 JobQueue&,
226 NetworkOPs&,
227 Resource::Manager&,
228 CollectorManager& cm);
229
230} // namespace ripple
231
232#endif
Represents a JSON value.
Definition: json_value.h:147
A version-independent IP address and port combination.
Definition: IPEndpoint.h:39
A generic endpoint for log messages.
Definition: Journal.h:59
A metric for measuring an integral value.
Definition: Counter.h:39
A metric for reporting event timing.
Definition: Event.h:41
Provides the beast::insight::Collector service.
A pool of threads to perform work.
Definition: JobQueue.h:56
Provides server functionality for clients.
Definition: NetworkOPs.h:87
Tracks load and resource consumption.
Resource::Manager & m_resourceManager
Definition: ServerHandler.h:93
std::condition_variable condition_
Json::Value processSession(std::shared_ptr< WSSession > const &session, std::shared_ptr< JobQueue::Coro > const &coro, Json::Value const &jv)
void onWSMessage(std::shared_ptr< WSSession > session, std::vector< boost::asio::const_buffer > const &buffers)
std::unique_ptr< Server > m_server
Definition: ServerHandler.h:96
beast::insight::Event rpc_size_
Setup const & setup() const
beast::insight::Counter rpc_requests_
Definition: ServerHandler.h:99
beast::Journal m_journal
Definition: ServerHandler.h:94
void onClose(Session &session, boost::system::error_code const &)
Handoff statusResponse(http_request_type const &request) const
boost::beast::tcp_stream socket_type
Definition: ServerHandler.h:89
NetworkOPs & m_networkOPs
Definition: ServerHandler.h:95
friend std::unique_ptr< ServerHandler > make_ServerHandler(Application &app, boost::asio::io_service &, JobQueue &, NetworkOPs &, Resource::Manager &, CollectorManager &cm)
Application & app_
Definition: ServerHandler.h:92
beast::insight::Event rpc_time_
bool onAccept(Session &session, boost::asio::ip::tcp::endpoint endpoint)
Handoff onHandoff(Session &session, http_request_type &&request, boost::asio::ip::tcp::endpoint const &remote_address)
std::map< std::reference_wrapper< Port const >, int > count_
void onStopped(Server &)
void onRequest(Session &session)
void processRequest(Port const &port, std::string const &request, beast::IP::Endpoint const &remoteIPAddress, Output &&, std::shared_ptr< JobQueue::Coro > coro, std::string_view forwardedFor, std::string_view user)
boost::beast::ssl_stream< socket_type > stream_type
Definition: ServerHandler.h:90
Handoff onHandoff(Session &session, std::unique_ptr< stream_type > &&bundle, http_request_type &&request, boost::asio::ip::tcp::endpoint const &remote_address)
A multi-protocol server.
Definition: ServerImpl.h:45
Persistent state information for a connection session.
Definition: Session.h:41
std::function< void(boost::beast::string_view const &)> Output
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
std::unique_ptr< ServerHandler > make_ServerHandler(Application &app, boost::asio::io_service &io_service, JobQueue &jobQueue, NetworkOPs &networkOPs, Resource::Manager &resourceManager, CollectorManager &cm)
ServerHandler::Setup setup_ServerHandler(Config const &config, std::ostream &&log)
std::string_view forwardedFor(http_request_type const &request)
Definition: Role.cpp:261
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Definition: Handoff.h:31
bool operator<(Slice const &lhs, Slice const &rhs) noexcept
Definition: Slice.h:222
Used to indicate the result of a server connection handoff.
Definition: Handoff.h:38
Configuration information for a Server listening port.
Definition: Port.h:49
std::string name
Definition: Port.h:52
std::vector< Port > ports
Definition: ServerHandler.h:54