3#include <xrpl/server/detail/BaseHTTPPeer.h>
4#include <xrpl/server/detail/SSLWSPeer.h>
6#include <boost/asio/ip/tcp.hpp>
7#include <boost/asio/ssl/context.hpp>
8#include <boost/asio/ssl/stream.hpp>
9#include <boost/beast/core/tcp_stream.hpp>
10#include <boost/beast/ssl/ssl_stream.hpp>
16template <
class Handler>
34 template <
class ConstBufferSequence>
38 boost::asio::io_context& ioc,
41 ConstBufferSequence
const& buffers,
66template <
class Handler>
67template <
class ConstBufferSequence>
71 boost::asio::io_context& ioc,
74 ConstBufferSequence
const& buffers,
84 , stream_(*stream_ptr_)
85 , socket_(stream_.next_layer().socket())
90template <
class Handler>
94 if (!this->handler_.onAccept(this->session(), this->remote_address_))
99 if (!socket_.is_open())
106template <
class Handler>
110 auto ws = this->ios().template emplace<SSLWSPeer<Handler>>(
113 this->remote_address_,
114 std::move(this->message_),
115 std::move(this->stream_ptr_),
120template <
class Handler>
124 boost::system::error_code ec;
125 stream_.set_verify_mode(boost::asio::ssl::verify_none);
127 this->read_buf_.consume(
128 stream_.async_handshake(stream_type::server, this->read_buf_.data(), do_yield[ec]));
129 this->cancel_timer();
130 if (ec == boost::beast::error::timeout)
131 return this->on_timer();
133 return this->fail(ec,
"handshake");
134 bool const http = this->port().protocol.count(
"peer") > 0 ||
135 this->port().protocol.count(
"wss") > 0 || this->port().protocol.count(
"wss2") > 0 ||
136 this->port().protocol.count(
"https") > 0;
147template <
class Handler>
151 ++this->request_count_;
152 auto const what = this->handler_.onHandoff(
153 this->session(), std::move(stream_ptr_), std::move(this->message_), this->remote_address_);
157 return this->write(what.response, what.keep_alive);
159 this->handler_.onRequest(this->session());
162template <
class Handler>
167 stream_.async_shutdown(bind_executor(
172template <
class Handler>
176 this->cancel_timer();
178 if (ec == boost::asio::error::operation_aborted)
182 JLOG(this->journal_.debug()) <<
"on_shutdown: " << ec.message();
186 stream_.next_layer().close();
A generic endpoint for log messages.
Represents an active connection.
void do_read(yield_context do_yield)
beast::Journal journal() override
Port const & port() override
boost::system::error_code error_code
void do_request() override
void do_handshake(yield_context do_yield)
boost::beast::ssl_stream< middle_type > stream_type
boost::asio::ip::tcp::endpoint endpoint_type
boost::asio::yield_context yield_context
boost::beast::tcp_stream middle_type
std::unique_ptr< stream_type > stream_ptr_
SSLHTTPPeer(Port const &port, Handler &handler, boost::asio::io_context &ioc, beast::Journal journal, endpoint_type remote_address, ConstBufferSequence const &buffers, middle_type &&stream)
void on_shutdown(error_code ec)
boost::asio::ip::tcp::socket socket_type
std::shared_ptr< WSSession > websocketUpgrade() override
Convert the connection to WebSocket.
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.