22#include "data/LedgerCacheInterface.hpp"
23#include "util/Taggable.hpp"
24#include "web/AdminVerificationStrategy.hpp"
25#include "web/ProxyIpResolver.hpp"
26#include "web/SslWsSession.hpp"
27#include "web/dosguard/DOSGuardInterface.hpp"
28#include "web/impl/HttpBase.hpp"
29#include "web/interface/Concepts.hpp"
30#include "web/interface/ConnectionBase.hpp"
32#include <boost/asio/ip/tcp.hpp>
33#include <boost/asio/ssl/context.hpp>
34#include <boost/asio/ssl/stream_base.hpp>
35#include <boost/beast/core/error.hpp>
36#include <boost/beast/core/flat_buffer.hpp>
37#include <boost/beast/core/stream_traits.hpp>
38#include <boost/beast/core/tcp_stream.hpp>
39#include <boost/beast/ssl/ssl_stream.hpp>
51using tcp = boost::asio::ip::tcp;
61template <SomeServerHandler HandlerType>
63 public std::enable_shared_from_this<SslHttpSession<HandlerType>> {
64 boost::beast::ssl_stream<boost::beast::tcp_stream> stream_;
65 std::reference_wrapper<util::TagDecoratorFactory const> tagFactory_;
66 std::uint32_t maxWsSendingQueueSize_;
86 std::string
const& ip,
87 std::shared_ptr<AdminVerificationStrategy>
const& adminVerification,
88 std::shared_ptr<ProxyIpResolver> proxyIpResolver,
89 boost::asio::ssl::context& ctx,
90 std::reference_wrapper<util::TagDecoratorFactory const> tagFactory,
91 std::reference_wrapper<dosguard::DOSGuardInterface> dosGuard,
92 std::shared_ptr<HandlerType>
const& handler,
93 std::reference_wrapper<data::LedgerCacheInterface const> cache,
94 boost::beast::flat_buffer buffer,
95 std::uint32_t maxWsSendingQueueSize
101 std::move(proxyIpResolver),
107 , stream_(std::move(socket), ctx)
108 , tagFactory_(tagFactory)
109 , maxWsSendingQueueSize_(maxWsSendingQueueSize)
116 boost::beast::ssl_stream<boost::beast::tcp_stream>&
126 auto self = this->shared_from_this();
127 boost::asio::dispatch(stream_.get_executor(), [self]() {
129 boost::beast::get_lowest_layer(self->stream()).expires_after(std::chrono::seconds(30));
133 self->stream_.async_handshake(
134 boost::asio::ssl::stream_base::server,
135 self->buffer_.data(),
136 boost::beast::bind_front_handler(&SslHttpSession<HandlerType>::onHandshake, self)
151 return this->httpFail(ec,
"handshake");
153 this->buffer_.consume(bytesUsed);
161 boost::beast::get_lowest_layer(stream_).expires_after(std::chrono::seconds(30));
174 return this->httpFail(ec,
"shutdown");
182 std::make_shared<SslWsUpgrader<HandlerType>>(
188 std::move(this->buffer_),
189 std::move(this->req_),
191 maxWsSendingQueueSize_
Represents a HTTPS connection established by a client.
Definition SslHttpSession.hpp:63
void upgrade()
Upgrades connection to secure websocket.
Definition SslHttpSession.hpp:180
void run()
Initiates the handshake.
Definition SslHttpSession.hpp:124
SslHttpSession(tcp::socket &&socket, std::string const &ip, std::shared_ptr< AdminVerificationStrategy > const &adminVerification, std::shared_ptr< ProxyIpResolver > proxyIpResolver, boost::asio::ssl::context &ctx, std::reference_wrapper< util::TagDecoratorFactory const > tagFactory, std::reference_wrapper< dosguard::DOSGuardInterface > dosGuard, std::shared_ptr< HandlerType > const &handler, std::reference_wrapper< data::LedgerCacheInterface const > cache, boost::beast::flat_buffer buffer, std::uint32_t maxWsSendingQueueSize)
Create a new SSL session.
Definition SslHttpSession.hpp:84
void onShutdown(boost::beast::error_code ec)
Handles a connection shutdown.
Definition SslHttpSession.hpp:171
void doClose()
Closes the underlying connection.
Definition SslHttpSession.hpp:159
boost::beast::ssl_stream< boost::beast::tcp_stream > & stream()
Definition SslHttpSession.hpp:117
void onHandshake(boost::beast::error_code ec, std::size_t bytesUsed)
Handles the handshake.
Definition SslHttpSession.hpp:148
This is the implementation class for http sessions.
Definition HttpBase.hpp:100
This namespace implements the web server and related components.
Definition Types.hpp:43
bool isAdmin() const
Indicates whether the connection has admin privileges.
Definition ConnectionBase.hpp:118