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>
25#include <boost/asio/ip/tcp.hpp>
26#include <boost/asio/ssl/context.hpp>
27#include <boost/asio/ssl/stream.hpp>
28#include <boost/beast/core/tcp_stream.hpp>
29#include <boost/beast/ssl/ssl_stream.hpp>
34template <
class Handler>
52 template <
class ConstBufferSequence>
56 boost::asio::io_context& ioc,
59 ConstBufferSequence
const& buffers,
84template <
class Handler>
85template <
class ConstBufferSequence>
89 boost::asio::io_context& ioc,
92 ConstBufferSequence
const& buffers,
104 , stream_(*stream_ptr_)
105 , socket_(stream_.next_layer().socket())
110template <
class Handler>
114 if (!this->handler_.onAccept(this->session(), this->remote_address_))
121 if (!socket_.is_open())
127 this->shared_from_this(),
128 std::placeholders::_1));
131template <
class Handler>
135 auto ws = this->ios().template emplace<SSLWSPeer<Handler>>(
138 this->remote_address_,
139 std::move(this->message_),
140 std::move(this->stream_ptr_),
145template <
class Handler>
149 boost::system::error_code ec;
150 stream_.set_verify_mode(boost::asio::ssl::verify_none);
152 this->read_buf_.consume(stream_.async_handshake(
153 stream_type::server, this->read_buf_.data(), do_yield[ec]));
154 this->cancel_timer();
155 if (ec == boost::beast::error::timeout)
156 return this->on_timer();
158 return this->fail(ec,
"handshake");
159 bool const http = this->port().protocol.count(
"peer") > 0 ||
160 this->port().protocol.count(
"wss") > 0 ||
161 this->port().protocol.count(
"wss2") > 0 ||
162 this->port().protocol.count(
"https") > 0;
169 this->shared_from_this(),
170 std::placeholders::_1));
176template <
class Handler>
180 ++this->request_count_;
181 auto const what = this->handler_.onHandoff(
183 std::move(stream_ptr_),
184 std::move(this->message_),
185 this->remote_address_);
189 return this->write(what.response, what.keep_alive);
191 this->handler_.onRequest(this->session());
194template <
class Handler>
199 stream_.async_shutdown(bind_executor(
203 this->shared_from_this(),
204 std::placeholders::_1)));
207template <
class Handler>
211 this->cancel_timer();
213 if (ec == boost::asio::error::operation_aborted)
217 JLOG(this->journal_.debug()) <<
"on_shutdown: " << ec.message();
221 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
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Configuration information for a Server listening port.