xrpld
Loading...
Searching...
No Matches
ServerHandler.h
1#pragma once
2
3#include <xrpld/app/main/Application.h>
4#include <xrpld/app/main/CollectorManager.h>
5#include <xrpld/rpc/detail/WSInfoSub.h>
6
7#include <xrpl/core/JobQueue.h>
8#include <xrpl/json/Output.h>
9#include <xrpl/server/Server.h>
10#include <xrpl/server/Session.h>
11#include <xrpl/server/WSSession.h>
12
13#include <boost/beast/core/tcp_stream.hpp>
14#include <boost/beast/ssl/ssl_stream.hpp>
15#include <boost/utility/string_view.hpp>
16
17#include <condition_variable>
18#include <map>
19#include <mutex>
20#include <vector>
21
22namespace xrpl {
23
24inline bool
25operator<(Port const& lhs, Port const& rhs)
26{
27 return lhs.name < rhs.name;
28}
29
31{
32public:
33 struct Setup
34 {
35 explicit Setup() = default;
36
38
39 // Memberspace
52
53 // Configuration when acting in client role
55
56 // Configuration for the Overlay
57 boost::asio::ip::tcp::endpoint overlay;
58
59 void
61 };
62
63private:
64 using socket_type = boost::beast::tcp_stream;
65 using stream_type = boost::beast::ssl_stream<socket_type>;
66
80 bool stopped_{false};
82
83 // A private type used to restrict access to the ServerHandler constructor.
85 {
86 explicit ServerHandlerCreator() = default;
87 };
88
89 // Friend declaration that allows make_ServerHandler to access the
90 // private type that restricts access to the ServerHandler ctor.
93 Application& app,
94 boost::asio::io_context&,
95 JobQueue&,
99
100public:
101 // Must be public so make_unique can call it.
104 Application& app,
105 boost::asio::io_context& ioContext,
106 JobQueue& jobQueue,
107 NetworkOPs& networkOPs,
108 Resource::Manager& resourceManager,
109 CollectorManager& cm);
110
112
114
115 void
116 setup(Setup const& setup, beast::Journal journal);
117
118 [[nodiscard]] Setup const&
119 setup() const
120 {
121 return setup_;
122 }
123
124 [[nodiscard]] Endpoints const&
125 endpoints() const
126 {
127 return endpoints_;
128 }
129
130 void
131 stop();
132
133 //
134 // Handler
135 //
136
137 bool
138 onAccept(Session& session, boost::asio::ip::tcp::endpoint endpoint);
139
140 Handoff
141 onHandoff(
142 Session& session,
144 http_request_type&& request,
145 boost::asio::ip::tcp::endpoint const& remoteAddress);
146
147 Handoff
149 Session& session,
150 http_request_type&& request, // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved)
151 boost::asio::ip::tcp::endpoint const& remoteAddress)
152 {
153 return onHandoff(session, {}, std::forward<http_request_type>(request), remoteAddress);
154 }
155
156 void
157 onRequest(Session& session);
158
159 void
163
164 void
165 onClose(Session& session, boost::system::error_code const&);
166
167 void
169
170private:
173 std::shared_ptr<WSSession> const& session,
175 json::Value const& jv);
176
177 void
179
180 void
182 Port const& port,
183 std::string const& request,
184 beast::IP::Endpoint const& remoteIPAddress,
185 Output const&,
188 std::string_view user);
189
190 [[nodiscard]] Handoff
191 statusResponse(http_request_type const& request) const;
192};
193
194ServerHandler::Setup
195setupServerHandler(Config const& c, std::ostream& log);
196
199 Application& app,
200 boost::asio::io_context&,
201 JobQueue&,
202 NetworkOPs&,
203 Resource::Manager&,
204 CollectorManager& cm);
205
206} // namespace xrpl
A version-independent IP address and port combination.
Definition IPEndpoint.h:17
A generic endpoint for log messages.
Definition Journal.h:38
A metric for measuring an integral value.
Definition Counter.h:19
A metric for reporting event timing.
Definition Event.h:21
Represents a JSON value.
Definition json_value.h:130
Provides the beast::insight::Collector service.
A pool of threads to perform work.
Definition JobQueue.h:43
Provides server functionality for clients.
Definition NetworkOPs.h:71
Tracks load and resource consumption.
std::condition_variable condition_
ServerHandler(ServerHandlerCreator const &, Application &app, boost::asio::io_context &ioContext, JobQueue &jobQueue, NetworkOPs &networkOPs, Resource::Manager &resourceManager, CollectorManager &cm)
friend std::unique_ptr< ServerHandler > makeServerHandler(Application &app, boost::asio::io_context &, JobQueue &, NetworkOPs &, Resource::Manager &, CollectorManager &cm)
Handoff onHandoff(Session &session, std::unique_ptr< stream_type > &&bundle, http_request_type &&request, boost::asio::ip::tcp::endpoint const &remoteAddress)
beast::insight::Event rpcTime_
boost::beast::tcp_stream socket_type
Resource::Manager & resourceManager_
beast::insight::Event rpcSize_
Application & app_
json::Value processSession(std::shared_ptr< WSSession > const &session, std::shared_ptr< JobQueue::Coro > const &coro, json::Value const &jv)
void onClose(Session &session, boost::system::error_code const &)
Setup const & setup() const
NetworkOPs & networkOPs_
Handoff onHandoff(Session &session, http_request_type &&request, boost::asio::ip::tcp::endpoint const &remoteAddress)
bool onAccept(Session &session, boost::asio::ip::tcp::endpoint endpoint)
void onStopped(Server &)
void setup(Setup const &setup, beast::Journal journal)
Handoff statusResponse(http_request_type const &request) const
Endpoints const & endpoints() const
void processRequest(Port const &port, std::string const &request, beast::IP::Endpoint const &remoteIPAddress, Output const &, std::shared_ptr< JobQueue::Coro > coro, std::string_view forwardedFor, std::string_view user)
std::map< std::reference_wrapper< Port const >, int > count_
void onRequest(Session &session)
void onWSMessage(std::shared_ptr< WSSession > session, std::vector< boost::asio::const_buffer > const &buffers)
boost::beast::ssl_stream< socket_type > stream_type
beast::Journal journal_
std::unique_ptr< Server > server_
beast::insight::Counter rpcRequests_
A multi-protocol server.
Definition ServerImpl.h:29
Persistent state information for a connection session.
Definition Session.h:24
T forward(T... args)
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:5
bool operator<(Slice const &lhs, Slice const &rhs) noexcept
Definition Slice.h:199
std::unordered_map< std::string, boost::asio::ip::tcp::endpoint > Endpoints
Definition ServerImpl.h:20
ServerHandler::Setup setupServerHandler(Config const &config, std::ostream &log)
std::unique_ptr< ServerHandler > makeServerHandler(Application &app, boost::asio::io_context &ioContext, JobQueue &jobQueue, NetworkOPs &networkOPs, Resource::Manager &resourceManager, CollectorManager &cm)
std::string_view forwardedFor(http_request_type const &request)
Definition Role.cpp:251
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Definition Handoff.h:12
Used to indicate the result of a server connection handoff.
Definition Handoff.h:18
Configuration information for a Server listening port.
Definition Port.h:28
std::string name
Definition Port.h:31
boost::asio::ip::tcp::endpoint overlay
std::vector< Port > ports