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/core/Config.h>
6#include <xrpld/rpc/detail/WSInfoSub.h>
7
8#include <xrpl/beast/insight/Counter.h>
9#include <xrpl/beast/insight/Event.h>
10#include <xrpl/beast/net/IPEndpoint.h>
11#include <xrpl/beast/utility/Journal.h>
12#include <xrpl/core/JobQueue.h>
13#include <xrpl/json/Output.h>
14#include <xrpl/json/json_value.h>
15#include <xrpl/resource/ResourceManager.h>
16#include <xrpl/server/Handoff.h>
17#include <xrpl/server/Port.h>
18#include <xrpl/server/Server.h> // IWYU pragma: keep
19#include <xrpl/server/Session.h>
20#include <xrpl/server/WSSession.h>
21
22#include <boost/beast/core/tcp_stream.hpp>
23#include <boost/beast/ssl/ssl_stream.hpp>
24#include <boost/utility/string_view.hpp>
25
26#include <condition_variable>
27#include <cstdint>
28#include <functional>
29#include <map>
30#include <memory>
31#include <mutex>
32#include <ostream>
33#include <string>
34#include <string_view>
35#include <utility>
36#include <vector>
37
38namespace xrpl {
39
40inline bool
41operator<(Port const& lhs, Port const& rhs)
42{
43 return lhs.name < rhs.name;
44}
45
47{
48public:
49 struct Setup
50 {
51 explicit Setup() = default;
52
54
55 // Memberspace
68
69 // Configuration when acting in client role
71
72 // Configuration for the Overlay
73 boost::asio::ip::tcp::endpoint overlay;
74
75 void
77 };
78
79private:
80 using SocketType = boost::beast::tcp_stream;
81 using StreamType = boost::beast::ssl_stream<SocketType>;
82
96 bool stopped_{false};
98
99 // A private type used to restrict access to the ServerHandler constructor.
101 {
102 explicit ServerHandlerCreator() = default;
103 };
104
105 // Friend declaration that allows make_ServerHandler to access the
106 // private type that restricts access to the ServerHandler ctor.
109 Application& app,
110 boost::asio::io_context&,
111 JobQueue&,
112 NetworkOPs&,
114 CollectorManager& cm);
115
116public:
117 // Must be public so make_unique can call it.
120 Application& app,
121 boost::asio::io_context& ioContext,
122 JobQueue& jobQueue,
123 NetworkOPs& networkOPs,
124 resource::Manager& resourceManager,
125 CollectorManager& cm);
126
128
130
131 void
132 setup(Setup const& setup, beast::Journal journal);
133
134 [[nodiscard]] Setup const&
135 setup() const
136 {
137 return setup_;
138 }
139
140 [[nodiscard]] Endpoints const&
141 endpoints() const
142 {
143 return endpoints_;
144 }
145
146 void
147 stop();
148
149 //
150 // Handler
151 //
152
153 bool
154 onAccept(Session& session, boost::asio::ip::tcp::endpoint endpoint);
155
156 Handoff
157 onHandoff(
158 Session& session,
160 HttpRequestType&& request,
161 boost::asio::ip::tcp::endpoint const& remoteAddress);
162
163 Handoff
165 Session& session,
166 HttpRequestType&& request, // NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved)
167 boost::asio::ip::tcp::endpoint const& remoteAddress)
168 {
169 return onHandoff(session, {}, std::forward<HttpRequestType>(request), remoteAddress);
170 }
171
172 void
173 onRequest(Session& session);
174
175 void
179
180 void
181 onClose(Session& session, boost::system::error_code const&);
182
183 void
185
186private:
189 std::shared_ptr<WSSession> const& session,
191 json::Value const& jv);
192
193 void
195
196 void
198 Port const& port,
199 std::string const& request,
200 beast::ip::Endpoint const& remoteIPAddress,
201 Output const&,
204 std::string_view user);
205
206 [[nodiscard]] Handoff
207 statusResponse(HttpRequestType const& request) const;
208};
209
210ServerHandler::Setup
211setupServerHandler(Config const& c, std::ostream& log);
212
215 Application& app,
216 boost::asio::io_context&,
217 JobQueue&,
218 NetworkOPs&,
219 resource::Manager&,
220 CollectorManager& cm);
221
222} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
A metric for measuring an integral value.
Definition Counter.h:20
A metric for reporting event timing.
Definition Event.h:22
A version-independent IP address and port combination.
Definition IPEndpoint.h:24
Represents a JSON value.
Definition json_value.h:121
Provides the beast::insight::Collector service.
A pool of threads to perform work.
Definition JobQueue.h:60
Provides server functionality for clients.
Definition NetworkOPs.h:82
std::condition_variable condition_
boost::beast::ssl_stream< SocketType > StreamType
ServerHandler(ServerHandlerCreator const &, Application &app, boost::asio::io_context &ioContext, JobQueue &jobQueue, NetworkOPs &networkOPs, resource::Manager &resourceManager, CollectorManager &cm)
Handoff onHandoff(Session &session, std::unique_ptr< StreamType > &&bundle, HttpRequestType &&request, boost::asio::ip::tcp::endpoint const &remoteAddress)
beast::insight::Event rpcTime_
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 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)
void onClose(Session &session, boost::system::error_code const &)
Setup const & setup() const
NetworkOPs & networkOPs_
bool onAccept(Session &session, boost::asio::ip::tcp::endpoint endpoint)
friend std::unique_ptr< ServerHandler > makeServerHandler(Application &app, boost::asio::io_context &, JobQueue &, NetworkOPs &, resource::Manager &, CollectorManager &cm)
void onStopped(Server &)
void setup(Setup const &setup, beast::Journal journal)
resource::Manager & resourceManager_
Handoff statusResponse(HttpRequestType const &request) const
Endpoints const & endpoints() const
Handoff onHandoff(Session &session, HttpRequestType &&request, boost::asio::ip::tcp::endpoint const &remoteAddress)
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)
beast::Journal journal_
std::unique_ptr< Server > server_
boost::beast::tcp_stream SocketType
beast::insight::Counter rpcRequests_
A multi-protocol server.
Definition ServerImpl.h:37
Persistent state information for a connection session.
Definition Session.h:25
Tracks load and resource consumption.
T forward(T... args)
std::function< void(std::string_view)> Output
Definition Output.h:9
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:212
std::unordered_map< std::string, boost::asio::ip::tcp::endpoint > Endpoints
Definition ServerImpl.h:27
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)
boost::beast::http::request< boost::beast::http::dynamic_body > HttpRequestType
Definition Handoff.h:12
std::string_view forwardedFor(HttpRequestType const &request)
Definition Role.cpp:251
Used to indicate the result of a server connection handoff.
Definition Handoff.h:20
Configuration information for a Server listening port.
Definition Port.h:29
std::string name
Definition Port.h:32
boost::asio::ip::tcp::endpoint overlay
std::vector< Port > ports