3#include <xrpl/basics/Log.h>
4#include <xrpl/beast/net/IPAddressConversion.h>
6#include <boost/asio.hpp>
7#include <boost/asio/ip/tcp.hpp>
8#include <boost/asio/ssl.hpp>
9#include <boost/beast/core/bind_handler.hpp>
19 using ssl_socket = boost::asio::ssl::stream<boost::asio::ip::tcp::socket>;
30 boost::asio::io_context& s,
31 boost::asio::ssl::context& c,
35 ,
mBuffer((plainOnly || secureOnly) ? 0 : 4)
36 ,
j_{
beast::Journal::getNullSink()}
41 AutoSocket(boost::asio::io_context& s, boost::asio::ssl::context& c)
88 boost::system::error_code
89 cancel(boost::system::error_code& ec)
97 if ((type == ssl_socket::client) || (
mSecure))
101 mSocket->async_handshake(type, cbFunc);
112 mSocket->next_layer().async_receive(
114 boost::asio::socket_base::message_peek,
119 std::placeholders::_1,
120 std::placeholders::_2));
124 template <
typename ShutdownHandler>
129 mSocket->async_shutdown(handler);
137 catch (boost::system::system_error& e)
141 post(
mSocket->get_executor(), boost::beast::bind_handler(handler, ec));
145 template <
typename Seq,
typename Handler>
150 mSocket->async_read_some(buffers, handler);
155 template <
typename Seq,
typename Condition,
typename Handler>
160 boost::asio::async_read_until(*
mSocket, buffers, condition, handler);
162 boost::asio::async_read_until(
PlainSocket(), buffers, condition, handler);
165 template <
typename Allocator,
typename Handler>
168 boost::asio::basic_streambuf<Allocator>& buffers,
173 boost::asio::async_read_until(*
mSocket, buffers, delim, handler);
175 boost::asio::async_read_until(
PlainSocket(), buffers, delim, handler);
178 template <
typename Allocator,
typename MatchCondition,
typename Handler>
181 boost::asio::basic_streambuf<Allocator>& buffers,
186 boost::asio::async_read_until(*
mSocket, buffers, cond, handler);
188 boost::asio::async_read_until(
PlainSocket(), buffers, cond, handler);
191 template <
typename Buf,
typename Handler>
196 boost::asio::async_write(*
mSocket, buffers, handler);
198 boost::asio::async_write(
PlainSocket(), buffers, handler);
201 template <
typename Allocator,
typename Handler>
203 async_write(boost::asio::basic_streambuf<Allocator>& buffers, Handler handler)
206 boost::asio::async_write(*
mSocket, buffers, handler);
208 boost::asio::async_write(
PlainSocket(), buffers, handler);
211 template <
typename Buf,
typename Condition,
typename Handler>
213 async_read(Buf
const& buffers, Condition cond, Handler handler)
216 boost::asio::async_read(*
mSocket, buffers, cond, handler);
218 boost::asio::async_read(
PlainSocket(), buffers, cond, handler);
221 template <
typename Allocator,
typename Condition,
typename Handler>
223 async_read(boost::asio::basic_streambuf<Allocator>& buffers, Condition cond, Handler handler)
226 boost::asio::async_read(*
mSocket, buffers, cond, handler);
228 boost::asio::async_read(
PlainSocket(), buffers, cond, handler);
231 template <
typename Buf,
typename Handler>
236 boost::asio::async_read(*
mSocket, buffers, handler);
238 boost::asio::async_read(
PlainSocket(), buffers, handler);
241 template <
typename Seq,
typename Handler>
246 mSocket->async_write_some(buffers, handler);
255 using namespace xrpl;
259 JLOG(
j_.
warn()) <<
"Handle autodetect error: " << ec;
264 ((bytesTransferred < 2) || ((
mBuffer[1] < 127) && (
mBuffer[1] > 31))) &&
265 ((bytesTransferred < 3) || ((
mBuffer[2] < 127) && (
mBuffer[2] > 31))) &&
266 ((bytesTransferred < 4) || ((
mBuffer[3] < 127) && (
mBuffer[3] > 31))))
278 mSocket->async_handshake(ssl_socket::server, cbFunc);
void async_write(boost::asio::basic_streambuf< Allocator > &buffers, Handler handler)
AutoSocket(boost::asio::io_context &s, boost::asio::ssl::context &c, bool secureOnly, bool plainOnly)
ssl_socket::handshake_type handshake_type
ssl_socket::lowest_layer_type lowest_layer_type
ssl_socket::next_layer_type plain_socket
boost::asio::ip::tcp::socket::endpoint_type endpoint_type
beast::IP::Endpoint remote_endpoint()
void async_read(boost::asio::basic_streambuf< Allocator > &buffers, Condition cond, Handler handler)
void handle_autodetect(callback cbFunc, error_code const &ec, size_t bytesTransferred)
boost::system::error_code error_code
AutoSocket(boost::asio::io_context &s, boost::asio::ssl::context &c)
void async_handshake(handshake_type type, callback cbFunc)
void async_read_until(boost::asio::basic_streambuf< Allocator > &buffers, MatchCondition cond, Handler handler)
void async_read_until(boost::asio::basic_streambuf< Allocator > &buffers, std::string const &delim, Handler handler)
void async_read(Buf const &buffers, Handler handler)
void async_write(Buf const &buffers, Handler handler)
lowest_layer_type & lowest_layer()
beast::IP::Endpoint local_endpoint()
void async_read_until(Seq const &buffers, Condition condition, Handler handler)
plain_socket & PlainSocket()
void async_read(Buf const &buffers, Condition cond, Handler handler)
void async_read_some(Seq const &buffers, Handler handler)
std::vector< char > mBuffer
void swap(AutoSocket &s) noexcept
void async_write_some(Seq const &buffers, Handler handler)
void async_shutdown(ShutdownHandler handler)
boost::system::error_code cancel(boost::system::error_code &ec)
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > ssl_socket
A version-independent IP address and port combination.
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
Endpoint from_asio(boost::asio::ip::address const &address)
Convert to Endpoint.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.