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
32#include <boost/beast/core/tcp_stream.hpp>
33#include <boost/beast/ssl/ssl_stream.hpp>
34#include <boost/utility/string_view.hpp>
35
36#include <condition_variable>
37#include <map>
38#include <mutex>
39#include <vector>
40
41namespace ripple {
42
43inline bool
44operator<(Port const& lhs, Port const& rhs)
45{
46 return lhs.name < rhs.name;
47}
48
50{
51public:
52 struct Setup
53 {
54 explicit Setup() = default;
55
57
58 // Memberspace
59 struct client_t
60 {
61 explicit client_t() = default;
62
63 bool secure = false;
70 };
71
72 // Configuration when acting in client role
74
75 // Configuration for the Overlay
76 boost::asio::ip::tcp::endpoint overlay;
77
78 void
80 };
81
82private:
83 using socket_type = boost::beast::tcp_stream;
84 using stream_type = boost::beast::ssl_stream<socket_type>;
85
99 bool stopped_{false};
101
102 // A private type used to restrict access to the ServerHandler constructor.
104 {
105 explicit ServerHandlerCreator() = default;
106 };
107
108 // Friend declaration that allows make_ServerHandler to access the
109 // private type that restricts access to the ServerHandler ctor.
112 Application& app,
113 boost::asio::io_service&,
114 JobQueue&,
115 NetworkOPs&,
117 CollectorManager& cm);
118
119public:
120 // Must be public so make_unique can call it.
123 Application& app,
124 boost::asio::io_service& io_service,
125 JobQueue& jobQueue,
126 NetworkOPs& networkOPs,
127 Resource::Manager& resourceManager,
128 CollectorManager& cm);
129
131
133
134 void
135 setup(Setup const& setup, beast::Journal journal);
136
137 Setup const&
138 setup() const
139 {
140 return setup_;
141 }
142
143 Endpoints const&
144 endpoints() const
145 {
146 return endpoints_;
147 }
148
149 void
150 stop();
151
152 //
153 // Handler
154 //
155
156 bool
157 onAccept(Session& session, boost::asio::ip::tcp::endpoint endpoint);
158
159 Handoff
160 onHandoff(
161 Session& session,
163 http_request_type&& request,
164 boost::asio::ip::tcp::endpoint const& remote_address);
165
166 Handoff
168 Session& session,
169 http_request_type&& request,
170 boost::asio::ip::tcp::endpoint const& remote_address)
171 {
172 return onHandoff(
173 session,
174 {},
175 std::forward<http_request_type>(request),
176 remote_address);
177 }
178
179 void
180 onRequest(Session& session);
181
182 void
186
187 void
188 onClose(Session& session, boost::system::error_code const&);
189
190 void
192
193private:
196 std::shared_ptr<WSSession> const& session,
198 Json::Value const& jv);
199
200 void
204
205 void
207 Port const& port,
208 std::string const& request,
209 beast::IP::Endpoint const& remoteIPAddress,
210 Output&&,
213 std::string_view user);
214
215 Handoff
216 statusResponse(http_request_type const& request) const;
217};
218
219ServerHandler::Setup
220setup_ServerHandler(Config const& c, std::ostream&& log);
221
224 Application& app,
225 boost::asio::io_service&,
226 JobQueue&,
227 NetworkOPs&,
228 Resource::Manager&,
229 CollectorManager& cm);
230
231} // namespace ripple
232
233#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:87
std::condition_variable condition_
Definition: ServerHandler.h:98
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:90
beast::insight::Event rpc_size_
Definition: ServerHandler.h:95
Setup const & setup() const
beast::insight::Counter rpc_requests_
Definition: ServerHandler.h:94
beast::Journal m_journal
Definition: ServerHandler.h:88
Endpoints const & endpoints() const
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:83
NetworkOPs & m_networkOPs
Definition: ServerHandler.h:89
friend std::unique_ptr< ServerHandler > make_ServerHandler(Application &app, boost::asio::io_service &, JobQueue &, NetworkOPs &, Resource::Manager &, CollectorManager &cm)
Application & app_
Definition: ServerHandler.h:86
beast::insight::Event rpc_time_
Definition: ServerHandler.h:96
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:84
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:48
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
boost::asio::ip::tcp::endpoint overlay
Definition: ServerHandler.h:76
std::vector< Port > ports
Definition: ServerHandler.h:56