3#include "util/Taggable.hpp"
4#include "web/dosguard/DOSGuardInterface.hpp"
5#include "web/impl/WsBase.hpp"
6#include "web/interface/ConnectionBase.hpp"
8#include <boost/beast/core/flat_buffer.hpp>
9#include <boost/beast/core/stream_traits.hpp>
10#include <boost/beast/core/tcp_stream.hpp>
11#include <boost/beast/http/message.hpp>
12#include <boost/beast/http/parser.hpp>
13#include <boost/beast/http/string_body.hpp>
14#include <boost/beast/ssl.hpp>
15#include <boost/beast/ssl/ssl_stream.hpp>
16#include <boost/beast/websocket/stream.hpp>
17#include <boost/optional/optional.hpp>
35template <SomeServerHandler HandlerType>
38 boost::beast::websocket::stream<boost::asio::ssl::stream<boost::beast::tcp_stream>>;
55 boost::asio::ssl::stream<boost::beast::tcp_stream>&& stream,
57 std::reference_wrapper<util::TagDecoratorFactory const> tagFactory,
58 std::reference_wrapper<dosguard::DOSGuardInterface> dosGuard,
59 std::shared_ptr<HandlerType>
const& handler,
60 boost::beast::flat_buffer&& buffer,
62 std::uint32_t maxWsSendingQueueSize
72 , ws_(std::move(stream))
74 ConnectionBase::isAdmin_ =
isAdmin;
94template <SomeServerHandler HandlerType>
95class SslWsUpgrader :
public std::enable_shared_from_this<SslWsUpgrader<HandlerType>> {
98 boost::asio::ssl::stream<boost::beast::tcp_stream> https_;
99 boost::optional<http::request_parser<http::string_body>> parser_;
100 boost::beast::flat_buffer buffer_;
102 std::reference_wrapper<util::TagDecoratorFactory const> tagFactory_;
103 std::reference_wrapper<dosguard::DOSGuardInterface> dosGuard_;
104 std::shared_ptr<HandlerType>
const handler_;
105 http::request<http::string_body> req_;
107 std::uint32_t maxWsSendingQueueSize_;
124 boost::asio::ssl::stream<boost::beast::tcp_stream> stream,
126 std::reference_wrapper<util::TagDecoratorFactory const> tagFactory,
127 std::reference_wrapper<dosguard::DOSGuardInterface> dosGuard,
128 std::shared_ptr<HandlerType> handler,
129 boost::beast::flat_buffer&& buffer,
130 http::request<http::string_body> request,
132 std::uint32_t maxWsSendingQueueSize
134 : https_(std::move(stream))
135 , buffer_(std::move(buffer))
137 , tagFactory_(tagFactory)
138 , dosGuard_(dosGuard)
139 , handler_(std::move(handler))
140 , req_(std::move(request))
142 , maxWsSendingQueueSize_(maxWsSendingQueueSize)
154 boost::beast::get_lowest_layer(https_).expires_after(std::chrono::seconds(30));
156 boost::asio::dispatch(
157 https_.get_executor(),
158 boost::beast::bind_front_handler(
159 &SslWsUpgrader<HandlerType>::doUpgrade, shared_from_this()
171 static constexpr auto kMaxBodySize = 10000;
172 parser_->body_limit(kMaxBodySize);
174 boost::beast::get_lowest_layer(https_).expires_after(std::chrono::seconds(30));
181 if (!boost::beast::websocket::is_upgrade(req_))
185 boost::beast::get_lowest_layer(https_).expires_never();
187 std::make_shared<SslWsSession<HandlerType>>(
195 maxWsSendingQueueSize_
197 ->
run(std::move(req_));
SslWsSession(boost::asio::ssl::stream< boost::beast::tcp_stream > &&stream, std::string ip, std::reference_wrapper< util::TagDecoratorFactory const > tagFactory, std::reference_wrapper< dosguard::DOSGuardInterface > dosGuard, std::shared_ptr< HandlerType > const &handler, boost::beast::flat_buffer &&buffer, bool isAdmin, std::uint32_t maxWsSendingQueueSize)
Create a new non-secure websocket session.
Definition SslWsSession.hpp:54
StreamType & ws()
Definition SslWsSession.hpp:81
The HTTPS upgrader class, upgrade from an HTTPS session to a secure websocket session.
Definition SslWsSession.hpp:95
void run()
Initiate the upgrade.
Definition SslWsSession.hpp:152
SslWsUpgrader(boost::asio::ssl::stream< boost::beast::tcp_stream > stream, std::string ip, std::reference_wrapper< util::TagDecoratorFactory const > tagFactory, std::reference_wrapper< dosguard::DOSGuardInterface > dosGuard, std::shared_ptr< HandlerType > handler, boost::beast::flat_buffer &&buffer, http::request< http::string_body > request, bool isAdmin, std::uint32_t maxWsSendingQueueSize)
Create a new upgrader to secure websocket.
Definition SslWsSession.hpp:123
Web socket implementation. This class is the base class of the web socket session,...
Definition WsBase.hpp:58
This namespace implements the web server and related components.
Definition Types.hpp:23
bool isAdmin() const
Indicates whether the connection has admin privileges.
Definition ConnectionBase.hpp:99