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>
53 template <
class ConstBufferSequence>
57 boost::asio::io_context& ioc,
60 ConstBufferSequence
const& buffers,
85 template <
class Handler>
86 template <
class ConstBufferSequence>
90 boost::asio::io_context& ioc,
93 ConstBufferSequence
const& buffers,
104 , stream_(*stream_ptr_)
105 , socket_(stream_.next_layer().socket())
110 template<
class Handler>
115 if(! this->handler_.onAccept(this->session(), this->remote_address_))
117 boost::asio::spawn(this->strand_,
119 this->shared_from_this()));
122 if (! socket_.is_open())
124 boost::asio::spawn(this->strand_,
std::bind(
126 std::placeholders::_1));
129 template<
class Handler>
134 auto ws = this->ios().template emplace<SSLWSPeer<Handler>>(
135 this->port_, this->handler_, this->remote_address_,
136 std::move(this->message_), std::move(this->stream_ptr_),
141 template<
class Handler>
146 boost::system::error_code ec;
147 stream_.set_verify_mode(boost::asio::ssl::verify_none);
149 this->read_buf_.consume(stream_.async_handshake(
150 stream_type::server, this->read_buf_.data(), do_yield[ec]));
151 this->cancel_timer();
152 if(ec == boost::beast::error::timeout)
153 return this->on_timer();
155 return this->fail(ec,
"handshake");
157 this->port().protocol.count(
"peer") > 0 ||
158 this->port().protocol.count(
"wss") > 0 ||
159 this->port().protocol.count(
"wss2") > 0 ||
160 this->port().protocol.count(
"https") > 0;
163 boost::asio::spawn(this->strand_,
165 this->shared_from_this(), std::placeholders::_1));
171 template<
class Handler>
176 ++this->request_count_;
177 auto const what = this->handler_.onHandoff(this->session(),
178 std::move(stream_ptr_), std::move(this->message_),
179 this->remote_address_);
183 return this->write(what.response, what.keep_alive);
185 this->handler_.onRequest(this->session());
188 template<
class Handler>
194 stream_.async_shutdown(bind_executor(
198 this->shared_from_this(),
199 std::placeholders::_1)));
202 template<
class Handler>
207 this->cancel_timer();
209 if (ec == boost::asio::error::operation_aborted)
213 JLOG(this->journal_.debug()) <<
214 "on_shutdown: " << ec.message();
218 stream_.next_layer().close();