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

Public Types

using pointer = std::shared_ptr<InfoSub>
using wptr = std::weak_ptr<InfoSub>
using ref = std::shared_ptr<InfoSub> const&
using Consumer = resource::Consumer

Public Member Functions

 RPCSubImp (InfoSub::Source &source, boost::asio::io_context &ioContext, JobQueue &jobQueue, std::string const &strUrl, std::string strUsername, std::string strPassword, ServiceRegistry &registry)
 ~RPCSubImp () override=default
void send (json::Value const &jvObj, bool broadcast) override
void setUsername (std::string const &strUsername) override
void setPassword (std::string const &strPassword) override
ConsumergetConsumer ()
std::uint64_t getSeq () const
std::size_t totalSubscriptionCount () const
 Return the number of subscriptions currently tracked on this connection.
bool tryReserveAccountSubscriptions (hash_set< AccountID > const &proposedAccounts, hash_set< AccountID > const &normalAccounts, std::size_t cap)
 Enforce the cap and reserve a request's net-new accounts, atomically.
bool hasAccountHistorySubscription (AccountID const &account) const
 Whether this connection already tracks an account-history for account.
void onSendEmpty ()
void insertSubAccountInfo (AccountID const &account, bool rt)
void deleteSubAccountInfo (AccountID const &account, bool rt)
void insertBookSubscription (Book const &book)
 Record that this subscriber is following book.
void deleteBookSubscription (Book const &book)
 Stop tracking book for this subscriber.
bool insertSubAccountHistory (AccountID const &account)
void deleteSubAccountHistory (AccountID const &account)
void clearRequest ()
void setRequest (std::shared_ptr< InfoSubRequest > const &req)
std::shared_ptr< InfoSubRequest > const & getRequest ()
void setApiVersion (unsigned int apiVersion)
unsigned int getApiVersion () const noexcept

Public Attributes

friend Object

Protected Attributes

std::mutex lock_

Private Member Functions

void sendThread ()

Static Private Member Functions

static int assignId ()
static auto & getCounter () noexcept

Private Attributes

boost::asio::io_context & ioContext_
JobQueuejobQueue_
std::string url_
std::string ip_
std::uint16_t port_
bool ssl_ {false}
std::string username_
std::string password_
std::string path_
int seq_
bool sending_ {false}
std::deque< std::pair< int, json::Value > > deque_
beast::Journal const j_
Logslogs_
Consumer consumer_
Sourcesource_
hash_set< AccountIDrealTimeSubscriptions_
hash_set< AccountIDnormalSubscriptions_
std::shared_ptr< InfoSubRequestrequest_
hash_set< AccountIDaccountHistorySubscriptions_
hash_set< BookbookSubscriptions_
unsigned int apiVersion_ = 0

Detailed Description

Definition at line 30 of file RPCSub.cpp.

Member Typedef Documentation

◆ pointer

Definition at line 91 of file InfoSub.h.

◆ wptr

Definition at line 95 of file InfoSub.h.

◆ ref

using xrpl::InfoSub::ref = std::shared_ptr<InfoSub> const&
inherited

Definition at line 97 of file InfoSub.h.

◆ Consumer

Definition at line 99 of file InfoSub.h.

Constructor & Destructor Documentation

◆ RPCSubImp()

xrpl::RPCSubImp::RPCSubImp ( InfoSub::Source & source,
boost::asio::io_context & ioContext,
JobQueue & jobQueue,
std::string const & strUrl,
std::string strUsername,
std::string strPassword,
ServiceRegistry & registry )

Definition at line 33 of file RPCSub.cpp.

◆ ~RPCSubImp()

xrpl::RPCSubImp::~RPCSubImp ( )
overridedefault

Member Function Documentation

◆ send()

void xrpl::RPCSubImp::send ( json::Value const & jvObj,
bool broadcast )
overridevirtual

Implements xrpl::InfoSub.

Definition at line 85 of file RPCSub.cpp.

◆ setUsername()

void xrpl::RPCSubImp::setUsername ( std::string const & strUsername)
overridevirtual

Implements xrpl::RPCSub.

Definition at line 105 of file RPCSub.cpp.

◆ setPassword()

void xrpl::RPCSubImp::setPassword ( std::string const & strPassword)
overridevirtual

Implements xrpl::RPCSub.

Definition at line 113 of file RPCSub.cpp.

◆ sendThread()

void xrpl::RPCSubImp::sendThread ( )
private

Definition at line 124 of file RPCSub.cpp.

◆ getConsumer()

resource::Consumer & xrpl::InfoSub::getConsumer ( )
inherited

Definition at line 132 of file libxrpl/server/InfoSub.cpp.

◆ getSeq()

std::uint64_t xrpl::InfoSub::getSeq ( ) const
nodiscardinherited

Definition at line 138 of file libxrpl/server/InfoSub.cpp.

◆ totalSubscriptionCount()

std::size_t xrpl::InfoSub::totalSubscriptionCount ( ) const
nodiscardinherited

Return the number of subscriptions currently tracked on this connection.

The combined size of the per-connection account, real-time account, and account-history subscription sets. doSubscribe reads this to enforce the per-connection subscription cap before admitting more.

Returns
The total tracked subscription count for this connection.
Note
Thread-safe: takes lock_ for the read; read-only.

Definition at line 149 of file libxrpl/server/InfoSub.cpp.

◆ tryReserveAccountSubscriptions()

bool xrpl::InfoSub::tryReserveAccountSubscriptions ( hash_set< AccountID > const & proposedAccounts,
hash_set< AccountID > const & normalAccounts,
std::size_t cap )
nodiscardinherited

Enforce the cap and reserve a request's net-new accounts, atomically.

Under one hold of lock_: count the net-new entries in the two sets, check the total against cap, and insert them only if it fits. All-or-nothing. Doing check and insert together stops two concurrent requests sharing an InfoSub (the admin subscribe-by-url path) from both passing the check before either records its accounts. The server-side maps are populated afterwards by subAccount, whose re-insert is a no-op.

Parameters
proposedAccountsReal-time (accounts_proposed) ids to reserve.
normalAccountsNormal (accounts) ids to reserve.
capThe effective per-connection cap.
Returns
true if reserved; false if the request must be rejected.
Note
Thread-safe: takes lock_.

Definition at line 161 of file libxrpl/server/InfoSub.cpp.

◆ hasAccountHistorySubscription()

bool xrpl::InfoSub::hasAccountHistorySubscription ( AccountID const & account) const
nodiscardinherited

Whether this connection already tracks an account-history for account.

doSubscribe reads this to charge the cap for an account_history_tx_stream only when it is net-new, matching the account branches.

Parameters
accountThe account an account_history_tx_stream would add.
Returns
true if account is already in the account-history set.
Note
Thread-safe: takes lock_; read-only.

Definition at line 240 of file libxrpl/server/InfoSub.cpp.

◆ onSendEmpty()

void xrpl::InfoSub::onSendEmpty ( )
inherited

Definition at line 144 of file libxrpl/server/InfoSub.cpp.

◆ insertSubAccountInfo()

void xrpl::InfoSub::insertSubAccountInfo ( AccountID const & account,
bool rt )
inherited

Definition at line 196 of file libxrpl/server/InfoSub.cpp.

◆ deleteSubAccountInfo()

void xrpl::InfoSub::deleteSubAccountInfo ( AccountID const & account,
bool rt )
inherited

Definition at line 211 of file libxrpl/server/InfoSub.cpp.

◆ insertBookSubscription()

void xrpl::InfoSub::insertBookSubscription ( Book const & book)
inherited

Record that this subscriber is following book.

Called by NetworkOPsImp::subBook so that ~InfoSub() can issue a matching unsubBook for every book this subscriber is tracking, keeping per-subscriber state symmetric with the server-side map.

Parameters
bookThe order book this subscriber has just subscribed to.
Note
Idempotent: re-inserting an already-tracked book is a no-op.
Thread-safe: takes InfoSub::lock_.

Definition at line 247 of file libxrpl/server/InfoSub.cpp.

◆ deleteBookSubscription()

void xrpl::InfoSub::deleteBookSubscription ( Book const & book)
inherited

Stop tracking book for this subscriber.

Called by the unsubscribe RPC handler so that the book is not re-unsubscribed by ~InfoSub(). Pairs with insertBookSubscription.

Parameters
bookThe order book to forget.
Note
No-op if book was not previously inserted.
Thread-safe: takes InfoSub::lock_.

Definition at line 254 of file libxrpl/server/InfoSub.cpp.

◆ insertSubAccountHistory()

bool xrpl::InfoSub::insertSubAccountHistory ( AccountID const & account)
inherited

Definition at line 226 of file libxrpl/server/InfoSub.cpp.

◆ deleteSubAccountHistory()

void xrpl::InfoSub::deleteSubAccountHistory ( AccountID const & account)
inherited

Definition at line 233 of file libxrpl/server/InfoSub.cpp.

◆ clearRequest()

void xrpl::InfoSub::clearRequest ( )
inherited

Definition at line 261 of file libxrpl/server/InfoSub.cpp.

◆ setRequest()

void xrpl::InfoSub::setRequest ( std::shared_ptr< InfoSubRequest > const & req)
inherited

Definition at line 267 of file libxrpl/server/InfoSub.cpp.

◆ getRequest()

std::shared_ptr< InfoSubRequest > const & xrpl::InfoSub::getRequest ( )
inherited

Definition at line 273 of file libxrpl/server/InfoSub.cpp.

◆ setApiVersion()

void xrpl::InfoSub::setApiVersion ( unsigned int apiVersion)
inherited

Definition at line 279 of file libxrpl/server/InfoSub.cpp.

◆ getApiVersion()

unsigned int xrpl::InfoSub::getApiVersion ( ) const
nodiscardnoexceptinherited

Definition at line 285 of file libxrpl/server/InfoSub.cpp.

◆ assignId()

int xrpl::InfoSub::assignId ( )
staticprivateinherited

Definition at line 433 of file InfoSub.h.

◆ getCounter()

auto & xrpl::CountedObject< InfoSub >::getCounter ( )
staticprivatenoexceptinherited

Definition at line 113 of file CountedObject.h.

Member Data Documentation

◆ ioContext_

boost::asio::io_context& xrpl::RPCSubImp::ioContext_
private

Definition at line 183 of file RPCSub.cpp.

◆ jobQueue_

JobQueue& xrpl::RPCSubImp::jobQueue_
private

Definition at line 184 of file RPCSub.cpp.

◆ url_

std::string xrpl::RPCSubImp::url_
private

Definition at line 186 of file RPCSub.cpp.

◆ ip_

std::string xrpl::RPCSubImp::ip_
private

Definition at line 187 of file RPCSub.cpp.

◆ port_

std::uint16_t xrpl::RPCSubImp::port_
private

Definition at line 188 of file RPCSub.cpp.

◆ ssl_

bool xrpl::RPCSubImp::ssl_ {false}
private

Definition at line 189 of file RPCSub.cpp.

◆ username_

std::string xrpl::RPCSubImp::username_
private

Definition at line 190 of file RPCSub.cpp.

◆ password_

std::string xrpl::RPCSubImp::password_
private

Definition at line 191 of file RPCSub.cpp.

◆ path_

std::string xrpl::RPCSubImp::path_
private

Definition at line 192 of file RPCSub.cpp.

◆ seq_

int xrpl::RPCSubImp::seq_
private

Definition at line 194 of file RPCSub.cpp.

◆ sending_

bool xrpl::RPCSubImp::sending_ {false}
private

Definition at line 196 of file RPCSub.cpp.

◆ deque_

std::deque<std::pair<int, json::Value> > xrpl::RPCSubImp::deque_
private

Definition at line 198 of file RPCSub.cpp.

◆ j_

beast::Journal const xrpl::RPCSubImp::j_
private

Definition at line 200 of file RPCSub.cpp.

◆ logs_

Logs& xrpl::RPCSubImp::logs_
private

Definition at line 201 of file RPCSub.cpp.

◆ lock_

std::mutex xrpl::InfoSub::lock_
mutableprotectedinherited

Definition at line 419 of file InfoSub.h.

◆ consumer_

Consumer xrpl::InfoSub::consumer_
privateinherited

Definition at line 422 of file InfoSub.h.

◆ source_

Source& xrpl::InfoSub::source_
privateinherited

Definition at line 423 of file InfoSub.h.

◆ realTimeSubscriptions_

hash_set<AccountID> xrpl::InfoSub::realTimeSubscriptions_
privateinherited

Definition at line 424 of file InfoSub.h.

◆ normalSubscriptions_

hash_set<AccountID> xrpl::InfoSub::normalSubscriptions_
privateinherited

Definition at line 425 of file InfoSub.h.

◆ request_

std::shared_ptr<InfoSubRequest> xrpl::InfoSub::request_
privateinherited

Definition at line 426 of file InfoSub.h.

◆ accountHistorySubscriptions_

hash_set<AccountID> xrpl::InfoSub::accountHistorySubscriptions_
privateinherited

Definition at line 428 of file InfoSub.h.

◆ bookSubscriptions_

hash_set<Book> xrpl::InfoSub::bookSubscriptions_
privateinherited

Definition at line 429 of file InfoSub.h.

◆ apiVersion_

unsigned int xrpl::InfoSub::apiVersion_ = 0
privateinherited

Definition at line 430 of file InfoSub.h.

◆ Object

Definition at line 138 of file CountedObject.h.