3#include "data/LedgerCacheInterface.hpp"
4#include "util/Taggable.hpp"
5#include "web/AdminVerificationStrategy.hpp"
6#include "web/ProxyIpResolver.hpp"
7#include "web/SslWsSession.hpp"
8#include "web/dosguard/DOSGuardInterface.hpp"
9#include "web/impl/HttpBase.hpp"
10#include "web/interface/Concepts.hpp"
11#include "web/interface/ConnectionBase.hpp"
13#include <boost/asio/ip/tcp.hpp>
14#include <boost/asio/ssl/context.hpp>
15#include <boost/asio/ssl/stream_base.hpp>
16#include <boost/beast/core/error.hpp>
17#include <boost/beast/core/flat_buffer.hpp>
18#include <boost/beast/core/stream_traits.hpp>
19#include <boost/beast/core/tcp_stream.hpp>
20#include <boost/beast/ssl/ssl_stream.hpp>
32using tcp = boost::asio::ip::tcp;
42template <SomeServerHandler HandlerType>
44 public std::enable_shared_from_this<SslHttpSession<HandlerType>> {
45 boost::asio::ssl::stream<boost::beast::tcp_stream> stream_;
46 std::reference_wrapper<util::TagDecoratorFactory const> tagFactory_;
47 std::uint32_t maxWsSendingQueueSize_;
67 std::string
const& ip,
68 std::shared_ptr<AdminVerificationStrategy>
const& adminVerification,
69 std::shared_ptr<ProxyIpResolver> proxyIpResolver,
70 boost::asio::ssl::context& ctx,
71 std::reference_wrapper<util::TagDecoratorFactory const> tagFactory,
72 std::reference_wrapper<dosguard::DOSGuardInterface> dosGuard,
73 std::shared_ptr<HandlerType>
const& handler,
74 std::reference_wrapper<data::LedgerCacheInterface const> cache,
75 boost::beast::flat_buffer buffer,
76 std::uint32_t maxWsSendingQueueSize
82 std::move(proxyIpResolver),
88 , stream_(std::move(socket), ctx)
89 , tagFactory_(tagFactory)
90 , maxWsSendingQueueSize_(maxWsSendingQueueSize)
97 boost::asio::ssl::stream<boost::beast::tcp_stream>&
107 auto self = this->shared_from_this();
108 boost::asio::dispatch(stream_.get_executor(), [self]() {
110 boost::beast::get_lowest_layer(self->stream()).expires_after(std::chrono::seconds(30));
114 self->stream_.async_handshake(
115 boost::asio::ssl::stream_base::server,
116 self->buffer_.data(),
117 boost::beast::bind_front_handler(&SslHttpSession<HandlerType>::onHandshake, self)
132 return this->httpFail(ec,
"handshake");
134 this->buffer_.consume(bytesUsed);
142 boost::beast::get_lowest_layer(stream_).expires_after(std::chrono::seconds(30));
143 stream_.async_shutdown(
157 return this->httpFail(ec,
"shutdown");
165 std::make_shared<SslWsUpgrader<HandlerType>>(
171 std::move(this->buffer_),
172 std::move(this->req_),
174 maxWsSendingQueueSize_
Represents a HTTPS connection established by a client.
Definition SslHttpSession.hpp:44
void upgrade()
Upgrades connection to secure websocket.
Definition SslHttpSession.hpp:163
void run()
Initiates the handshake.
Definition SslHttpSession.hpp:105
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:65
void onShutdown(boost::beast::error_code ec)
Handles a connection shutdown.
Definition SslHttpSession.hpp:154
void doClose()
Closes the underlying connection.
Definition SslHttpSession.hpp:140
boost::asio::ssl::stream< boost::beast::tcp_stream > & stream()
Definition SslHttpSession.hpp:98
void onHandshake(boost::beast::error_code ec, std::size_t bytesUsed)
Handles the handshake.
Definition SslHttpSession.hpp:129
This is the implementation class for http sessions.
Definition HttpBase.hpp:81
This namespace implements the web server and related components.
Definition Types.hpp:24
bool isAdmin() const
Indicates whether the connection has admin privileges.
Definition ConnectionBase.hpp:99