20#ifndef RIPPLE_SERVER_SSLHTTPPEER_H_INCLUDED
21#define RIPPLE_SERVER_SSLHTTPPEER_H_INCLUDED
23#include <xrpl/server/detail/BaseHTTPPeer.h>
24#include <xrpl/server/detail/SSLWSPeer.h>
26#include <boost/asio/ip/tcp.hpp>
27#include <boost/asio/ssl/context.hpp>
28#include <boost/asio/ssl/stream.hpp>
29#include <boost/beast/core/tcp_stream.hpp>
30#include <boost/beast/ssl/ssl_stream.hpp>
36template <
class Handler>
54 template <
class ConstBufferSequence>
58 boost::asio::io_context& ioc,
61 ConstBufferSequence
const& buffers,
86template <
class Handler>
87template <
class ConstBufferSequence>
91 boost::asio::io_context& ioc,
94 ConstBufferSequence
const& buffers,
106 , stream_(*stream_ptr_)
107 , socket_(stream_.next_layer().socket())
112template <
class Handler>
116 if (!this->handler_.onAccept(this->session(), this->remote_address_))
123 if (!socket_.is_open())
129 this->shared_from_this(),
130 std::placeholders::_1));
133template <
class Handler>
137 auto ws = this->ios().template emplace<SSLWSPeer<Handler>>(
140 this->remote_address_,
141 std::move(this->message_),
142 std::move(this->stream_ptr_),
147template <
class Handler>
151 boost::system::error_code ec;
152 stream_.set_verify_mode(boost::asio::ssl::verify_none);
154 this->read_buf_.consume(stream_.async_handshake(
155 stream_type::server, this->read_buf_.data(), do_yield[ec]));
156 this->cancel_timer();
157 if (ec == boost::beast::error::timeout)
158 return this->on_timer();
160 return this->fail(ec,
"handshake");
161 bool const http = this->port().protocol.count(
"peer") > 0 ||
162 this->port().protocol.count(
"wss") > 0 ||
163 this->port().protocol.count(
"wss2") > 0 ||
164 this->port().protocol.count(
"https") > 0;
171 this->shared_from_this(),
172 std::placeholders::_1));
178template <
class Handler>
182 ++this->request_count_;
183 auto const what = this->handler_.onHandoff(
185 std::move(stream_ptr_),
186 std::move(this->message_),
187 this->remote_address_);
191 return this->write(what.response, what.keep_alive);
193 this->handler_.onRequest(this->session());
196template <
class Handler>
201 stream_.async_shutdown(bind_executor(
205 this->shared_from_this(),
206 std::placeholders::_1)));
209template <
class Handler>
213 this->cancel_timer();
215 if (ec == boost::asio::error::operation_aborted)
219 JLOG(this->journal_.debug()) <<
"on_shutdown: " << ec.message();
223 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.