rippled
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& io_context,
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 Setup const&
119 setup() const
120 {
121 return setup_;
122 }
123
124 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& remote_address);
146
147 Handoff
148 onHandoff(Session& session, http_request_type&& request, boost::asio::ip::tcp::endpoint const& remote_address)
149 {
150 return onHandoff(session, {}, std::forward<http_request_type>(request), remote_address);
151 }
152
153 void
154 onRequest(Session& session);
155
156 void
158
159 void
160 onClose(Session& session, boost::system::error_code const&);
161
162 void
164
165private:
168 std::shared_ptr<WSSession> const& session,
170 Json::Value const& jv);
171
172 void
174
175 void
177 Port const& port,
178 std::string const& request,
179 beast::IP::Endpoint const& remoteIPAddress,
180 Output&&,
183 std::string_view user);
184
185 Handoff
186 statusResponse(http_request_type const& request) const;
187};
188
189ServerHandler::Setup
190setup_ServerHandler(Config const& c, std::ostream&& log);
191
194 Application& app,
195 boost::asio::io_context&,
196 JobQueue&,
197 NetworkOPs&,
198 Resource::Manager&,
199 CollectorManager& cm);
200
201} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
A version-independent IP address and port combination.
Definition IPEndpoint.h:18
A generic endpoint for log messages.
Definition Journal.h:40
A metric for measuring an integral value.
Definition Counter.h:19
A metric for reporting event timing.
Definition Event.h:21
Provides the beast::insight::Collector service.
A pool of threads to perform work.
Definition JobQueue.h:37
Provides server functionality for clients.
Definition NetworkOPs.h:69
Tracks load and resource consumption.
Resource::Manager & m_resourceManager
std::condition_variable condition_
Handoff onHandoff(Session &session, http_request_type &&request, boost::asio::ip::tcp::endpoint const &remote_address)
boost::beast::tcp_stream socket_type
Handoff onHandoff(Session &session, std::unique_ptr< stream_type > &&bundle, http_request_type &&request, boost::asio::ip::tcp::endpoint const &remote_address)
Application & app_
friend std::unique_ptr< ServerHandler > make_ServerHandler(Application &app, boost::asio::io_context &, JobQueue &, NetworkOPs &, Resource::Manager &, CollectorManager &cm)
void onClose(Session &session, boost::system::error_code const &)
Setup const & setup() const
bool onAccept(Session &session, boost::asio::ip::tcp::endpoint endpoint)
beast::insight::Event rpc_size_
void onStopped(Server &)
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 &&, 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)
beast::insight::Event rpc_time_
void onWSMessage(std::shared_ptr< WSSession > session, std::vector< boost::asio::const_buffer > const &buffers)
boost::beast::ssl_stream< socket_type > stream_type
NetworkOPs & m_networkOPs
beast::Journal m_journal
std::unique_ptr< Server > m_server
beast::insight::Counter rpc_requests_
Json::Value processSession(std::shared_ptr< WSSession > const &session, std::shared_ptr< JobQueue::Coro > const &coro, Json::Value const &jv)
A multi-protocol server.
Definition ServerImpl.h:29
Persistent state information for a connection session.
Definition Session.h:23
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:5
bool operator<(Slice const &lhs, Slice const &rhs) noexcept
Definition Slice.h:198
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Definition Handoff.h:12
std::string_view forwardedFor(http_request_type const &request)
Definition Role.cpp:228
ServerHandler::Setup setup_ServerHandler(Config const &config, std::ostream &&log)
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:18
Configuration information for a Server listening port.
Definition Port.h:30
std::string name
Definition Port.h:33
boost::asio::ip::tcp::endpoint overlay
std::vector< Port > ports