xrpld
Loading...
Searching...
No Matches
xrpl::test::WSClientImpl Class Reference
Inheritance diagram for xrpl::test::WSClientImpl:
Collaboration diagram for xrpl::test::WSClientImpl:

Classes

struct  Msg

Public Member Functions

 WSClientImpl (Config const &cfg, bool v2, unsigned rpcVersion, std::unordered_map< std::string, std::string > const &headers={})
 ~WSClientImpl () override
json::Value invoke (std::string const &cmd, json::Value const &params) override
 Submit a command synchronously.
std::optional< json::ValuegetMsg (std::chrono::milliseconds const &timeout) override
 Retrieve a message.
std::optional< json::ValuefindMsg (std::chrono::milliseconds const &timeout, std::function< bool(json::Value const &)> pred) override
 Retrieve a message that meets the predicate criteria.
unsigned version () const override
 Get RPC 1.0 or RPC 2.0.
void disconnect () override
 Close the client's connection to the server.

Private Types

using error_code = boost::system::error_code

Private Member Functions

void cleanup ()
void onReadMsg (error_code const &ec)

Static Private Member Functions

static boost::asio::ip::tcp::endpoint getEndpoint (BasicConfig const &cfg, bool v2)
template<class ConstBuffers>
static std::string bufferString (ConstBuffers const &b)

Private Attributes

boost::asio::io_context ios_
std::optional< boost::asio::executor_work_guard< boost::asio::io_context::executor_type > > work_
boost::asio::strand< boost::asio::io_context::executor_type > strand_
std::thread thread_
boost::asio::ip::tcp::socket stream_
boost::beast::websocket::stream< boost::asio::ip::tcp::socket & > ws_
boost::beast::multi_buffer rb_
bool peerClosed_ = false
xrpl::Mutex< bool > readEnded_
std::condition_variable readEndCv_
std::mutex m_
std::condition_variable cv_
std::list< std::shared_ptr< Msg > > msgs_
unsigned rpcVersion_

Static Private Attributes

static constexpr auto kDisconnectTimeout = std::chrono::seconds{1}

Detailed Description

Definition at line 50 of file WSClient.cpp.

Member Typedef Documentation

◆ error_code

using xrpl::test::WSClientImpl::error_code = boost::system::error_code
private

Definition at line 52 of file WSClient.cpp.

Constructor & Destructor Documentation

◆ WSClientImpl()

xrpl::test::WSClientImpl::WSClientImpl ( Config const & cfg,
bool v2,
unsigned rpcVersion,
std::unordered_map< std::string, std::string > const & headers = {} )

Definition at line 157 of file WSClient.cpp.

◆ ~WSClientImpl()

xrpl::test::WSClientImpl::~WSClientImpl ( )
override

Definition at line 192 of file WSClient.cpp.

Member Function Documentation

◆ getEndpoint()

boost::asio::ip::tcp::endpoint xrpl::test::WSClientImpl::getEndpoint ( BasicConfig const & cfg,
bool v2 )
staticprivate

Definition at line 64 of file WSClient.cpp.

◆ bufferString()

template<class ConstBuffers>
std::string xrpl::test::WSClientImpl::bufferString ( ConstBuffers const & b)
staticprivate

Definition at line 96 of file WSClient.cpp.

◆ cleanup()

void xrpl::test::WSClientImpl::cleanup ( )
private

Definition at line 130 of file WSClient.cpp.

◆ invoke()

json::Value xrpl::test::WSClientImpl::invoke ( std::string const & cmd,
json::Value const & params )
overridevirtual

Submit a command synchronously.

The arguments to the function and the returned JSON are in a normalized format, the same whether the client is using the JSON-RPC over HTTP/S or WebSocket transport.

Parameters
cmdThe command to execute
paramsjson::Value of null or object type with zero or more key/value pairs.
Returns
The server response in normalized format.

Implements xrpl::test::AbstractClient.

Definition at line 198 of file WSClient.cpp.

◆ getMsg()

std::optional< json::Value > xrpl::test::WSClientImpl::getMsg ( std::chrono::milliseconds const & timeout)
overridevirtual

Retrieve a message.

Implements xrpl::test::WSClient.

Definition at line 252 of file WSClient.cpp.

◆ findMsg()

std::optional< json::Value > xrpl::test::WSClientImpl::findMsg ( std::chrono::milliseconds const & timeout,
std::function< bool(json::Value const &)> pred )
overridevirtual

Retrieve a message that meets the predicate criteria.

Implements xrpl::test::WSClient.

Definition at line 266 of file WSClient.cpp.

◆ version()

unsigned xrpl::test::WSClientImpl::version ( ) const
nodiscardoverridevirtual

Get RPC 1.0 or RPC 2.0.

Implements xrpl::test::AbstractClient.

Definition at line 292 of file WSClient.cpp.

◆ disconnect()

void xrpl::test::WSClientImpl::disconnect ( )
overridevirtual

Close the client's connection to the server.

Releases the connection the client holds against the server's per-port connection limit. After this call the client must not be used to invoke() again. Tests use this to deterministically free the slot rather than waiting for the server's idle timeout to drop it.

Implements xrpl::test::AbstractClient.

Definition at line 298 of file WSClient.cpp.

◆ onReadMsg()

void xrpl::test::WSClientImpl::onReadMsg ( error_code const & ec)
private

Definition at line 337 of file WSClient.cpp.

Member Data Documentation

◆ ios_

boost::asio::io_context xrpl::test::WSClientImpl::ios_
private

Definition at line 106 of file WSClient.cpp.

◆ work_

std::optional<boost::asio::executor_work_guard<boost::asio::io_context::executor_type> > xrpl::test::WSClientImpl::work_
private

Definition at line 107 of file WSClient.cpp.

◆ strand_

boost::asio::strand<boost::asio::io_context::executor_type> xrpl::test::WSClientImpl::strand_
private

Definition at line 108 of file WSClient.cpp.

◆ thread_

std::thread xrpl::test::WSClientImpl::thread_
private

Definition at line 109 of file WSClient.cpp.

◆ stream_

boost::asio::ip::tcp::socket xrpl::test::WSClientImpl::stream_
private

Definition at line 110 of file WSClient.cpp.

◆ ws_

boost::beast::websocket::stream<boost::asio::ip::tcp::socket&> xrpl::test::WSClientImpl::ws_
private

Definition at line 111 of file WSClient.cpp.

◆ rb_

boost::beast::multi_buffer xrpl::test::WSClientImpl::rb_
private

Definition at line 112 of file WSClient.cpp.

◆ peerClosed_

bool xrpl::test::WSClientImpl::peerClosed_ = false
private

Definition at line 114 of file WSClient.cpp.

◆ kDisconnectTimeout

auto xrpl::test::WSClientImpl::kDisconnectTimeout = std::chrono::seconds{1}
staticconstexprprivate

Definition at line 118 of file WSClient.cpp.

◆ readEnded_

xrpl::Mutex<bool> xrpl::test::WSClientImpl::readEnded_
private

Definition at line 119 of file WSClient.cpp.

◆ readEndCv_

std::condition_variable xrpl::test::WSClientImpl::readEndCv_
private

Definition at line 120 of file WSClient.cpp.

◆ m_

std::mutex xrpl::test::WSClientImpl::m_
private

Definition at line 123 of file WSClient.cpp.

◆ cv_

std::condition_variable xrpl::test::WSClientImpl::cv_
private

Definition at line 124 of file WSClient.cpp.

◆ msgs_

std::list<std::shared_ptr<Msg> > xrpl::test::WSClientImpl::msgs_
private

Definition at line 125 of file WSClient.cpp.

◆ rpcVersion_

unsigned xrpl::test::WSClientImpl::rpcVersion_
private

Definition at line 127 of file WSClient.cpp.