3#include <xrpl/basics/Log.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/server/Port.h>
6#include <xrpl/server/WSSession.h>
7#include <xrpl/server/detail/BaseHTTPPeer.h>
8#include <xrpl/server/detail/SSLWSPeer.h>
10#include <boost/asio/ip/tcp.hpp>
11#include <boost/asio/ssl/context.hpp>
12#include <boost/asio/ssl/stream.hpp>
13#include <boost/beast/core/tcp_stream.hpp>
14#include <boost/beast/ssl/ssl_stream.hpp>
21template <
class Handler>
39 template <
class ConstBufferSequence>
43 boost::asio::io_context& ioc,
46 ConstBufferSequence
const& buffers,
71template <
class Handler>
72template <
class ConstBufferSequence>
76 boost::asio::io_context& ioc,
79 ConstBufferSequence
const& buffers,
95template <
class Handler>
99 if (!this->
handler_.onAccept(this->session(), this->remoteAddress_))
108 self->doHandshake(doYield);
112template <
class Handler>
116 auto ws = this->
ios().template emplace<SSLWSPeer<Handler>>(
126template <
class Handler>
130 boost::system::error_code ec;
131 stream_.set_verify_mode(boost::asio::ssl::verify_none);
134 stream_.async_handshake(stream_type::server, this->readBuf_.data(), doYield[ec]));
136 if (ec == boost::beast::error::timeout)
139 return this->
fail(ec,
"handshake");
140 bool const http = this->
port().protocol.count(
"peer") > 0 ||
141 this->
port().protocol.count(
"wss") > 0 || this->
port().protocol.count(
"wss2") > 0 ||
142 this->
port().protocol.count(
"https") > 0;
146 self->doRead(doYield);
153template <
class Handler>
158 auto const what = this->
handler_.onHandoff(
163 return this->
write(what.response, what.keepAlive);
168template <
class Handler>
173 stream_.async_shutdown(bind_executor(
178template <
class Handler>
184 if (ec == boost::asio::error::operation_aborted)
188 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
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.