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,
78 , stream_(*stream_ptr_)
79 , socket_(stream_.next_layer().socket())
84template <
class Handler>
88 if (!this->handler_.onAccept(this->session(), this->remote_address_))
93 if (!socket_.is_open())
98template <
class Handler>
102 auto ws = this->ios().template emplace<SSLWSPeer<Handler>>(
105 this->remote_address_,
106 std::move(this->message_),
107 std::move(this->stream_ptr_),
112template <
class Handler>
116 boost::system::error_code ec;
117 stream_.set_verify_mode(boost::asio::ssl::verify_none);
119 this->read_buf_.consume(stream_.async_handshake(stream_type::server, this->read_buf_.data(), do_yield[ec]));
120 this->cancel_timer();
121 if (ec == boost::beast::error::timeout)
122 return this->on_timer();
124 return this->fail(ec,
"handshake");
125 bool const http = this->port().protocol.count(
"peer") > 0 || this->port().protocol.count(
"wss") > 0 ||
126 this->port().protocol.count(
"wss2") > 0 || this->port().protocol.count(
"https") > 0;
135template <
class Handler>
139 ++this->request_count_;
140 auto const what = this->handler_.onHandoff(
141 this->session(), std::move(stream_ptr_), std::move(this->message_), this->remote_address_);
145 return this->write(what.response, what.keep_alive);
147 this->handler_.onRequest(this->session());
150template <
class Handler>
155 stream_.async_shutdown(bind_executor(
159template <
class Handler>
163 this->cancel_timer();
165 if (ec == boost::asio::error::operation_aborted)
169 JLOG(this->journal_.debug()) <<
"on_shutdown: " << ec.message();
173 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.