rippled
Loading...
Searching...
No Matches
ServerHandler.h
1#ifndef XRPL_RPC_SERVERHANDLER_H_INCLUDED
2#define XRPL_RPC_SERVERHANDLER_H_INCLUDED
3
4#include <xrpld/app/main/Application.h>
5#include <xrpld/app/main/CollectorManager.h>
6#include <xrpld/core/JobQueue.h>
7#include <xrpld/rpc/detail/WSInfoSub.h>
8
9#include <xrpl/json/Output.h>
10#include <xrpl/server/Server.h>
11#include <xrpl/server/Session.h>
12#include <xrpl/server/WSSession.h>
13
14#include <boost/beast/core/tcp_stream.hpp>
15#include <boost/beast/ssl/ssl_stream.hpp>
16#include <boost/utility/string_view.hpp>
17
18#include <condition_variable>
19#include <map>
20#include <mutex>
21#include <vector>
22
23namespace ripple {
24
25inline bool
26operator<(Port const& lhs, Port const& rhs)
27{
28 return lhs.name < rhs.name;
29}
30
32{
33public:
34 struct Setup
35 {
36 explicit Setup() = default;
37
39
40 // Memberspace
53
54 // Configuration when acting in client role
56
57 // Configuration for the Overlay
58 boost::asio::ip::tcp::endpoint overlay;
59
60 void
62 };
63
64private:
65 using socket_type = boost::beast::tcp_stream;
66 using stream_type = boost::beast::ssl_stream<socket_type>;
67
81 bool stopped_{false};
83
84 // A private type used to restrict access to the ServerHandler constructor.
86 {
87 explicit ServerHandlerCreator() = default;
88 };
89
90 // Friend declaration that allows make_ServerHandler to access the
91 // private type that restricts access to the ServerHandler ctor.
94 Application& app,
95 boost::asio::io_context&,
96 JobQueue&,
100
101public:
102 // Must be public so make_unique can call it.
105 Application& app,
106 boost::asio::io_context& io_context,
107 JobQueue& jobQueue,
108 NetworkOPs& networkOPs,
109 Resource::Manager& resourceManager,
110 CollectorManager& cm);
111
113
115
116 void
117 setup(Setup const& setup, beast::Journal journal);
118
119 Setup const&
120 setup() const
121 {
122 return setup_;
123 }
124
125 Endpoints const&
126 endpoints() const
127 {
128 return endpoints_;
129 }
130
131 void
132 stop();
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 {},
158 remote_address);
159 }
160
161 void
162 onRequest(Session& session);
163
164 void
168
169 void
170 onClose(Session& session, boost::system::error_code const&);
171
172 void
174
175private:
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&&,
195 std::string_view user);
196
197 Handoff
198 statusResponse(http_request_type const& request) const;
199};
200
201ServerHandler::Setup
202setup_ServerHandler(Config const& c, std::ostream&& log);
203
206 Application& app,
207 boost::asio::io_context&,
208 JobQueue&,
209 NetworkOPs&,
210 Resource::Manager&,
211 CollectorManager& cm);
212
213} // namespace ripple
214
215#endif
Represents a JSON value.
Definition json_value.h:131
A version-independent IP address and port combination.
Definition IPEndpoint.h:19
A generic endpoint for log messages.
Definition Journal.h:41
A metric for measuring an integral value.
Definition Counter.h:20
A metric for reporting event timing.
Definition Event.h:22
Provides the beast::insight::Collector service.
A pool of threads to perform work.
Definition JobQueue.h:39
Provides server functionality for clients.
Definition NetworkOPs.h:70
Tracks load and resource consumption.
Resource::Manager & m_resourceManager
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
beast::insight::Event rpc_size_
Setup const & setup() const
beast::insight::Counter rpc_requests_
friend std::unique_ptr< ServerHandler > make_ServerHandler(Application &app, boost::asio::io_context &, JobQueue &, NetworkOPs &, Resource::Manager &, CollectorManager &cm)
beast::Journal m_journal
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
NetworkOPs & m_networkOPs
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 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
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:31
Persistent state information for a connection session.
Definition Session.h:24
T is_same_v
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:6
ServerHandler::Setup setup_ServerHandler(Config const &config, std::ostream &&log)
std::string_view forwardedFor(http_request_type const &request)
Definition Role.cpp:243
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Definition Handoff.h:14
bool operator<(Slice const &lhs, Slice const &rhs) noexcept
Definition Slice.h:204
std::unique_ptr< ServerHandler > make_ServerHandler(Application &app, boost::asio::io_context &io_context, JobQueue &jobQueue, NetworkOPs &networkOPs, Resource::Manager &resourceManager, CollectorManager &cm)
Used to indicate the result of a server connection handoff.
Definition Handoff.h:21
Configuration information for a Server listening port.
Definition Port.h:31
std::string name
Definition Port.h:34
boost::asio::ip::tcp::endpoint overlay
std::vector< Port > ports