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/Application.h>
24#include <xrpld/app/main/CollectorManager.h>
25#include <xrpld/core/JobQueue.h>
26#include <xrpld/rpc/detail/WSInfoSub.h>
27
28#include <xrpl/json/Output.h>
29#include <xrpl/server/Server.h>
30#include <xrpl/server/Session.h>
31#include <xrpl/server/WSSession.h>
32
33#include <boost/beast/core/tcp_stream.hpp>
34#include <boost/beast/ssl/ssl_stream.hpp>
35#include <boost/utility/string_view.hpp>
36
37#include <condition_variable>
38#include <map>
39#include <mutex>
40#include <vector>
41
42namespace ripple {
43
44inline bool
45operator<(Port const& lhs, Port const& rhs)
46{
47 return lhs.name < rhs.name;
48}
49
51{
52public:
53 struct Setup
54 {
55 explicit Setup() = default;
56
58
59 // Memberspace
60 struct client_t
61 {
62 explicit client_t() = default;
63
64 bool secure = false;
71 };
72
73 // Configuration when acting in client role
75
76 // Configuration for the Overlay
77 boost::asio::ip::tcp::endpoint overlay;
78
79 void
81 };
82
83private:
84 using socket_type = boost::beast::tcp_stream;
85 using stream_type = boost::beast::ssl_stream<socket_type>;
86
100 bool stopped_{false};
102
103 // A private type used to restrict access to the ServerHandler constructor.
105 {
106 explicit ServerHandlerCreator() = default;
107 };
108
109 // Friend declaration that allows make_ServerHandler to access the
110 // private type that restricts access to the ServerHandler ctor.
113 Application& app,
114 boost::asio::io_service&,
115 JobQueue&,
116 NetworkOPs&,
118 CollectorManager& cm);
119
120public:
121 // Must be public so make_unique can call it.
124 Application& app,
125 boost::asio::io_service& io_service,
126 JobQueue& jobQueue,
127 NetworkOPs& networkOPs,
128 Resource::Manager& resourceManager,
129 CollectorManager& cm);
130
132
134
135 void
136 setup(Setup const& setup, beast::Journal journal);
137
138 Setup const&
139 setup() const
140 {
141 return setup_;
142 }
143
144 Endpoints const&
145 endpoints() const
146 {
147 return endpoints_;
148 }
149
150 void
151 stop();
152
153 //
154 // Handler
155 //
156
157 bool
158 onAccept(Session& session, boost::asio::ip::tcp::endpoint endpoint);
159
160 Handoff
161 onHandoff(
162 Session& session,
164 http_request_type&& request,
165 boost::asio::ip::tcp::endpoint const& remote_address);
166
167 Handoff
169 Session& session,
170 http_request_type&& request,
171 boost::asio::ip::tcp::endpoint const& remote_address)
172 {
173 return onHandoff(
174 session,
175 {},
176 std::forward<http_request_type>(request),
177 remote_address);
178 }
179
180 void
181 onRequest(Session& session);
182
183 void
187
188 void
189 onClose(Session& session, boost::system::error_code const&);
190
191 void
193
194private:
197 std::shared_ptr<WSSession> const& session,
199 Json::Value const& jv);
200
201 void
205
206 void
208 Port const& port,
209 std::string const& request,
210 beast::IP::Endpoint const& remoteIPAddress,
211 Output&&,
214 std::string_view user);
215
216 Handoff
217 statusResponse(http_request_type const& request) const;
218};
219
220ServerHandler::Setup
221setup_ServerHandler(Config const& c, std::ostream&& log);
222
225 Application& app,
226 boost::asio::io_service&,
227 JobQueue&,
228 NetworkOPs&,
229 Resource::Manager&,
230 CollectorManager& cm);
231
232} // namespace ripple
233
234#endif
Represents a JSON value.
Definition: json_value.h:149
A version-independent IP address and port combination.
Definition: IPEndpoint.h:38
A generic endpoint for log messages.
Definition: Journal.h:60
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:58
Provides server functionality for clients.
Definition: NetworkOPs.h:89
Tracks load and resource consumption.
Resource::Manager & m_resourceManager
Definition: ServerHandler.h:88
std::condition_variable condition_
Definition: ServerHandler.h:99
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:91
beast::insight::Event rpc_size_
Definition: ServerHandler.h:96
Setup const & setup() const
beast::insight::Counter rpc_requests_
Definition: ServerHandler.h:95
beast::Journal m_journal
Definition: ServerHandler.h:89
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:84
NetworkOPs & m_networkOPs
Definition: ServerHandler.h:90
friend std::unique_ptr< ServerHandler > make_ServerHandler(Application &app, boost::asio::io_service &, JobQueue &, NetworkOPs &, Resource::Manager &, CollectorManager &cm)
Application & app_
Definition: ServerHandler.h:87
beast::insight::Event rpc_time_
Definition: ServerHandler.h:97
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:85
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:43
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:25
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:262
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Definition: Handoff.h:33
bool operator<(Slice const &lhs, Slice const &rhs) noexcept
Definition: Slice.h:223
Used to indicate the result of a server connection handoff.
Definition: Handoff.h:40
Configuration information for a Server listening port.
Definition: Port.h:50
std::string name
Definition: Port.h:53
boost::asio::ip::tcp::endpoint overlay
Definition: ServerHandler.h:77
std::vector< Port > ports
Definition: ServerHandler.h:57