1#ifndef XRPL_SERVER_SSLHTTPPEER_H_INCLUDED
2#define XRPL_SERVER_SSLHTTPPEER_H_INCLUDED
4#include <xrpl/server/detail/BaseHTTPPeer.h>
5#include <xrpl/server/detail/SSLWSPeer.h>
7#include <boost/asio/ip/tcp.hpp>
8#include <boost/asio/ssl/context.hpp>
9#include <boost/asio/ssl/stream.hpp>
10#include <boost/beast/core/tcp_stream.hpp>
11#include <boost/beast/ssl/ssl_stream.hpp>
17template <
class Handler>
35 template <
class ConstBufferSequence>
39 boost::asio::io_context& ioc,
42 ConstBufferSequence
const& buffers,
67template <
class Handler>
68template <
class ConstBufferSequence>
72 boost::asio::io_context& ioc,
75 ConstBufferSequence
const& buffers,
87 , stream_(*stream_ptr_)
88 , socket_(stream_.next_layer().socket())
93template <
class Handler>
97 if (!this->handler_.onAccept(this->session(), this->remote_address_))
104 if (!socket_.is_open())
110 this->shared_from_this(),
111 std::placeholders::_1));
114template <
class Handler>
118 auto ws = this->ios().template emplace<SSLWSPeer<Handler>>(
121 this->remote_address_,
122 std::move(this->message_),
123 std::move(this->stream_ptr_),
128template <
class Handler>
132 boost::system::error_code ec;
133 stream_.set_verify_mode(boost::asio::ssl::verify_none);
135 this->read_buf_.consume(stream_.async_handshake(
136 stream_type::server, this->read_buf_.data(), do_yield[ec]));
137 this->cancel_timer();
138 if (ec == boost::beast::error::timeout)
139 return this->on_timer();
141 return this->fail(ec,
"handshake");
142 bool const http = this->port().protocol.count(
"peer") > 0 ||
143 this->port().protocol.count(
"wss") > 0 ||
144 this->port().protocol.count(
"wss2") > 0 ||
145 this->port().protocol.count(
"https") > 0;
152 this->shared_from_this(),
153 std::placeholders::_1));
159template <
class Handler>
163 ++this->request_count_;
164 auto const what = this->handler_.onHandoff(
166 std::move(stream_ptr_),
167 std::move(this->message_),
168 this->remote_address_);
172 return this->write(what.response, what.keep_alive);
174 this->handler_.onRequest(this->session());
177template <
class Handler>
182 stream_.async_shutdown(bind_executor(
186 this->shared_from_this(),
187 std::placeholders::_1)));
190template <
class Handler>
194 this->cancel_timer();
196 if (ec == boost::asio::error::operation_aborted)
200 JLOG(this->journal_.debug()) <<
"on_shutdown: " << ec.message();
204 stream_.next_layer().close();
A generic endpoint for log messages.
Represents an active connection.
Port const & port() override
void do_read(yield_context do_yield)
beast::Journal journal() override
boost::asio::ip::tcp::socket socket_type
void do_request() override
std::unique_ptr< stream_type > stream_ptr_
std::shared_ptr< WSSession > websocketUpgrade() override
Convert the connection to WebSocket.
void on_shutdown(error_code ec)
boost::system::error_code error_code
SSLHTTPPeer(Port const &port, Handler &handler, boost::asio::io_context &ioc, beast::Journal journal, endpoint_type remote_address, ConstBufferSequence const &buffers, middle_type &&stream)
boost::asio::ip::tcp::endpoint endpoint_type
boost::asio::yield_context yield_context
void do_handshake(yield_context do_yield)
boost::beast::ssl_stream< middle_type > stream_type
boost::beast::tcp_stream middle_type
void spawn(Ctx &&ctx, F &&func)
Spawns a coroutine using boost::asio::spawn
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Configuration information for a Server listening port.