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,
90template <
class Handler>
94 if (!this->
handler_.onAccept(this->session(), this->remoteAddress_))
106template <
class Handler>
110 auto ws = this->
ios().template emplace<SSLWSPeer<Handler>>(
120template <
class Handler>
124 boost::system::error_code ec;
125 stream_.set_verify_mode(boost::asio::ssl::verify_none);
128 stream_.async_handshake(stream_type::server, this->readBuf_.data(), doYield[ec]));
130 if (ec == boost::beast::error::timeout)
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>
152 auto const what = this->
handler_.onHandoff(
157 return this->
write(what.response, what.keepAlive);
162template <
class Handler>
167 stream_.async_shutdown(bind_executor(
172template <
class Handler>
178 if (ec == boost::asio::error::operation_aborted)
182 JLOG(this->
journal_.debug()) <<
"on_shutdown: " << ec.message();
A generic endpoint for log messages.
BaseHTTPPeer(Port const &port, Handler &handler, boost::asio::executor const &executor, beast::Journal journal, endpoint_type remoteAddress, ConstBufferSequence const &buffers)
endpoint_type remoteAddress_
http_request_type message_
void write(void const *buffer, std::size_t bytes) override
beast::IP::Endpoint remoteAddress() override
beast::Journal const journal_
void fail(error_code ec, char const *what)
boost::asio::streambuf readBuf_
beast::Journal journal() override
boost::asio::strand< boost::asio::executor > strand_
Port const & port() override
void doRead(yield_context doYield)
boost::system::error_code error_code
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
void doRequest() override
boost::asio::ip::tcp::socket socket_type
SSLHTTPPeer(Port const &port, Handler &handler, boost::asio::io_context &ioc, beast::Journal journal, endpoint_type remoteAddress, ConstBufferSequence const &buffers, middle_type &&stream)
std::shared_ptr< WSSession > websocketUpgrade() override
Convert the connection to WebSocket.
void onShutdown(error_code ec)
std::unique_ptr< stream_type > streamPtr_
void doHandshake(yield_context doYield)
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.
T shared_from_this(T... args)
Configuration information for a Server listening port.