1#include <test/jtx/envconfig.h> 
    3#include <xrpl/basics/make_SSLContext.h> 
    4#include <xrpl/beast/core/CurrentThreadName.h> 
    5#include <xrpl/beast/unit_test.h> 
    7#include <boost/asio/bind_executor.hpp> 
    8#include <boost/asio/buffer.hpp> 
    9#include <boost/asio/ip/tcp.hpp> 
   10#include <boost/asio/read_until.hpp> 
   11#include <boost/asio/ssl.hpp> 
   12#include <boost/asio/strand.hpp> 
   13#include <boost/asio/streambuf.hpp> 
   14#include <boost/utility/in_place_factory.hpp> 
   38    using strand_type = boost::asio::strand<io_context_type::executor_type>;
 
   40        boost::asio::basic_waitable_timer<std::chrono::steady_clock>;
 
   49    boost::optional<boost::asio::executor_work_guard<
 
   50        boost::asio::io_context::executor_type>>
 
   55    template <
class Streambuf>
 
   59        using boost::asio::buffer;
 
   60        using boost::asio::buffer_copy;
 
   61        using boost::asio::buffer_size;
 
   62        boost::asio::const_buffer buf(s.
data(), s.
size());
 
   63        sb.commit(buffer_copy(sb.prepare(buffer_size(buf)), buf));
 
 
  100            assert(
list_.empty());
 
 
  107            list_.emplace(child.get(), child);
 
 
  129                for (
auto const& c : 
list_)
 
  131                    if (
auto p = c.second.lock())
 
 
  147            while (!
list_.empty())
 
 
 
  175                          boost::asio::ip::make_address(
 
  176                              test::getEnvLocalhostAddr()),
 
 
  188                if (!
strand_.running_in_this_thread())
 
 
  205                            std::placeholders::_1)));
 
 
  213                    if (ec != boost::asio::error::operation_aborted)
 
 
  223                    return fail(
"accept", ec);
 
  235                            std::placeholders::_1)));
 
 
 
  263                if (!
strand_.running_in_this_thread())
 
 
  278                timer_.async_wait(bind_executor(
 
  283                        std::placeholders::_1)));
 
  291                            std::placeholders::_1)));
 
 
  299                    if (ec != boost::asio::error::operation_aborted)
 
  300                        test_.
log << 
"[server] " << what << 
": " << ec.message()
 
 
  310                if (ec == boost::asio::error::operation_aborted)
 
  313                    return fail(
"timer", ec);
 
 
  322                    return fail(
"handshake", ec);
 
  324                boost::asio::async_read_until(
 
  333                            std::placeholders::_1,
 
  334                            std::placeholders::_2)));
 
 
  343                if (ec == boost::asio::error::eof)
 
  346                    return stream_.async_shutdown(bind_executor(
 
  351                            std::placeholders::_1)));
 
  354                    return fail(
"read", ec);
 
  356                buf_.commit(bytes_transferred);
 
  357                buf_.consume(bytes_transferred);
 
  359                boost::asio::async_write(
 
  367                            std::placeholders::_1,
 
  368                            std::placeholders::_2)));
 
 
  374                buf_.consume(bytes_transferred);
 
  376                    return fail(
"write", ec);
 
  377                stream_.async_shutdown(bind_executor(
 
  382                        std::placeholders::_1)));
 
 
  389                    return fail(
"shutdown", ec);
 
 
 
 
  449                if (!
strand_.running_in_this_thread())
 
 
  464                timer_.async_wait(bind_executor(
 
  469                        std::placeholders::_1)));
 
  477                            std::placeholders::_1)));
 
 
  485                    if (ec != boost::asio::error::operation_aborted)
 
  486                        test_.
log << 
"[client] " << what << 
": " << ec.message()
 
 
  496                if (ec == boost::asio::error::operation_aborted)
 
  499                    return fail(
"timer", ec);
 
 
  508                    return fail(
"connect", ec);
 
  516                            std::placeholders::_1)));
 
 
  523                    return fail(
"handshake", ec);
 
  527                boost::asio::async_write(
 
  535                            std::placeholders::_1,
 
  536                            std::placeholders::_2)));
 
  538                stream_.async_shutdown(bind_executor(
 
  543                        std::placeholders::_1)));
 
 
  550                buf_.consume(bytes_transferred);
 
  552                    return fail(
"write", ec);
 
  554                boost::asio::async_read_until(
 
  563                            std::placeholders::_1,
 
  564                            std::placeholders::_2)));
 
  566                stream_.async_shutdown(bind_executor(
 
  571                        std::placeholders::_1)));
 
 
  579                    return fail(
"read", ec);
 
  580                buf_.commit(bytes_transferred);
 
  581                stream_.async_shutdown(bind_executor(
 
  586                        std::placeholders::_1)));
 
 
  593                    return fail(
"shutdown", ec);
 
 
 
 
  619            this->io_context_.run();
 
 
 
  641BEAST_DEFINE_TESTSUITE(short_read, overlay, 
ripple);
 
log_os< char > log
Logging output stream.
 
void pass()
Record a successful test condition.
 
std::map< Child *, std::weak_ptr< Child > > list_
 
void add(std::shared_ptr< Child > const &child)
 
void remove(Child *child)
 
std::condition_variable cond_
 
Client(short_read_test &test, endpoint_type const &ep)
 
Server(short_read_test &test)
 
endpoint_type const & endpoint() const
 
std::shared_ptr< boost::asio::ssl::context > context_
 
void run() override
Runs the suite.
 
boost::system::error_code error_code
 
boost::asio::ssl::stream< socket_type & > stream_type
 
boost::asio::io_context io_context_type
 
boost::asio::ip::tcp::endpoint endpoint_type
 
boost::asio::basic_waitable_timer< std::chrono::steady_clock > timer_type
 
boost::asio::ip::tcp::acceptor acceptor_type
 
io_context_type io_context_
 
static void write(Streambuf &sb, std::string const &s)
 
boost::asio::ip::address address_type
 
boost::asio::strand< io_context_type::executor_type > strand_type
 
boost::asio::ip::tcp::socket socket_type
 
boost::optional< boost::asio::executor_work_guard< boost::asio::io_context::executor_type > > work_
 
T emplace_back(T... args)
 
void setCurrentThreadName(std::string_view newThreadName)
Changes the name of the caller thread.
 
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
 
std::shared_ptr< boost::asio::ssl::context > make_SSLContext(std::string const &cipherList)
Create a self-signed SSL context that allows anonymous Diffie Hellman.
 
T shared_from_this(T... args)
 
void on_connect(error_code ec)
 
void on_read(error_code ec, std::size_t bytes_transferred)
 
void on_write(error_code ec, std::size_t bytes_transferred)
 
void fail(std::string const &what, error_code ec)
 
boost::asio::streambuf buf_
 
endpoint_type const  & ep_
 
Connection(Client &client, endpoint_type const &ep)
 
void run(endpoint_type const &ep)
 
void on_shutdown(error_code ec)
 
void on_timer(error_code ec)
 
void on_handshake(error_code ec)
 
void on_accept(error_code ec)
 
void fail(std::string const &what, error_code ec)
 
boost::asio::streambuf buf_
 
void fail(std::string const &what, error_code ec)
 
void on_timer(error_code ec)
 
void on_read(error_code ec, std::size_t bytes_transferred)
 
void on_write(error_code ec, std::size_t bytes_transferred)
 
void on_shutdown(error_code ec)
 
Connection(Server &server, socket_type &&socket)
 
void on_handshake(error_code ec)