20 #ifndef RIPPLE_SERVER_SSLHTTPPEER_H_INCLUDED
21 #define RIPPLE_SERVER_SSLHTTPPEER_H_INCLUDED
23 #include <ripple/server/impl/BaseHTTPPeer.h>
24 #include <ripple/server/impl/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>
34 template <
class Handler>
52 template <
class ConstBufferSequence>
56 boost::asio::io_context& ioc,
59 ConstBufferSequence
const& buffers,
84 template <
class Handler>
85 template <
class ConstBufferSequence>
89 boost::asio::io_context& ioc,
92 ConstBufferSequence
const& buffers,
104 , stream_(*stream_ptr_)
105 , socket_(stream_.next_layer().socket())
110 template <
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));
131 template <
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_),
145 template <
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));
176 template <
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());
194 template <
class Handler>
199 stream_.async_shutdown(bind_executor(
203 this->shared_from_this(),
204 std::placeholders::_1)));
207 template <
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();