xrpld
Loading...
Searching...
No Matches
xrpl::WSInfoSub Class Reference

#include <WSInfoSub.h>

Inheritance diagram for xrpl::WSInfoSub:
Collaboration diagram for xrpl::WSInfoSub:

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

 WSInfoSub (Source &source, std::shared_ptr< WSSession > const &ws)
std::string_view user () const
std::string_view forwardedFor () const
void send (json::Value const &jv, bool) override
Consumer & getConsumer ()
std::uint64_t getSeq () const
std::size_t totalSubscriptionCount () const
 Return the number of subscriptions currently tracked on this connection.
bool tryReserveAccountSubscriptions (HashSet< AccountID > const &proposedAccounts, HashSet< AccountID > const &normalAccounts, std::size_t cap)
 Enforce the cap and reserve a request's net-new accounts, atomically.
bool tryReserveMPTSubscriptions (HashSet< MPTID > const &mptIDs, std::size_t cap)
 Enforce the cap and reserve a request's net-new MPT issuances, 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
void insertSubMPTInfo (MPTID const &mptID)
void deleteSubMPTInfo (MPTID const &mptID)

Public Attributes

friend Object

Protected Attributes

std::mutex lock_

Private Types

using ScopedLock = std::scoped_lock<decltype(lock_)>

Private Member Functions

std::size_t subscriptionCount (ScopedLock const &lock) const
 The combined tally the per-connection cap is enforced against.

Static Private Member Functions

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

Private Attributes

std::weak_ptr< WSSession > ws_
std::string user_
std::string fwdfor_
Consumer consumer_
Source & source_
HashSet< AccountID > realTimeSubscriptions_
HashSet< AccountID > normalSubscriptions_
std::shared_ptr< InfoSubRequest > request_
std::uint64_t seq_
HashSet< AccountID > accountHistorySubscriptions_
HashSet< Book > bookSubscriptions_
HashSet< MPTID > mptSubscriptions_
unsigned int apiVersion_ = 0

Detailed Description

Definition at line 18 of file WSInfoSub.h.

Member Typedef Documentation

◆ pointer

Definition at line 92 of file InfoSub.h.

◆ Wptr

Definition at line 96 of file InfoSub.h.

◆ Ref

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

Definition at line 98 of file InfoSub.h.

◆ Consumer

Definition at line 100 of file InfoSub.h.

◆ ScopedLock

using xrpl::InfoSub::ScopedLock = std::scoped_lock<decltype(lock_)>
privateinherited

Definition at line 469 of file InfoSub.h.

Constructor & Destructor Documentation

◆ WSInfoSub()

xrpl::WSInfoSub::WSInfoSub ( Source & source,
std::shared_ptr< WSSession > const & ws )

Definition at line 25 of file WSInfoSub.h.

Member Function Documentation

◆ user()

std::string_view xrpl::WSInfoSub::user ( ) const
nodiscard

Definition at line 41 of file WSInfoSub.h.

◆ forwardedFor()

std::string_view xrpl::WSInfoSub::forwardedFor ( ) const
nodiscard

Definition at line 47 of file WSInfoSub.h.

◆ send()

void xrpl::WSInfoSub::send ( json::Value const & jv,
bool  )
overridevirtual

Implements xrpl::InfoSub.

Definition at line 53 of file WSInfoSub.h.

◆ getConsumer()

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

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

◆ getSeq()

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

Definition at line 166 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, account-history, and MPT issuance 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 184 of file libxrpl/server/InfoSub.cpp.

◆ tryReserveAccountSubscriptions()

bool xrpl::InfoSub::tryReserveAccountSubscriptions ( HashSet< AccountID > const & proposedAccounts,
HashSet< 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 194 of file libxrpl/server/InfoSub.cpp.

◆ tryReserveMPTSubscriptions()

bool xrpl::InfoSub::tryReserveMPTSubscriptions ( HashSet< MPTID > const & mptIDs,
std::size_t cap )
nodiscardinherited

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

The MPT analogue of tryReserveAccountSubscriptions: under one hold of lock_, count the net-new issuances, check the total against cap, and insert them only if it fits. All-or-nothing, so a rejected request records 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 issuances. The server-side map is populated afterwards by subMPT, whose re-insert is a no-op.

Parameters
mptIDsThe MPT issuance 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 214 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 271 of file libxrpl/server/InfoSub.cpp.

◆ onSendEmpty()

void xrpl::InfoSub::onSendEmpty ( )
inherited

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

◆ insertSubAccountInfo()

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

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

◆ deleteSubAccountInfo()

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

Definition at line 242 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 278 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 285 of file libxrpl/server/InfoSub.cpp.

◆ insertSubAccountHistory()

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

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

◆ deleteSubAccountHistory()

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

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

◆ clearRequest()

void xrpl::InfoSub::clearRequest ( )
inherited

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

◆ setRequest()

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

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

◆ getRequest()

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

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

◆ setApiVersion()

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

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

◆ getApiVersion()

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

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

◆ insertSubMPTInfo()

void xrpl::InfoSub::insertSubMPTInfo ( MPTID const & mptID)
inherited

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

◆ deleteSubMPTInfo()

void xrpl::InfoSub::deleteSubMPTInfo ( MPTID const & mptID)
inherited

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

◆ subscriptionCount()

std::size_t xrpl::InfoSub::subscriptionCount ( ScopedLock const & lock) const
nodiscardprivateinherited

The combined tally the per-connection cap is enforced against.

Parameters
lockProof that lock_ is held; unused otherwise.

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

◆ assignId()

int xrpl::InfoSub::assignId ( )
staticprivateinherited

Definition at line 491 of file InfoSub.h.

◆ getCounter()

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

Definition at line 113 of file CountedObject.h.

Member Data Documentation

◆ ws_

std::weak_ptr<WSSession> xrpl::WSInfoSub::ws_
private

Definition at line 20 of file WSInfoSub.h.

◆ user_

std::string xrpl::WSInfoSub::user_
private

Definition at line 21 of file WSInfoSub.h.

◆ fwdfor_

std::string xrpl::WSInfoSub::fwdfor_
private

Definition at line 22 of file WSInfoSub.h.

◆ lock_

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

Definition at line 465 of file InfoSub.h.

◆ consumer_

Consumer xrpl::InfoSub::consumer_
privateinherited

Definition at line 479 of file InfoSub.h.

◆ source_

Source& xrpl::InfoSub::source_
privateinherited

Definition at line 480 of file InfoSub.h.

◆ realTimeSubscriptions_

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

Definition at line 481 of file InfoSub.h.

◆ normalSubscriptions_

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

Definition at line 482 of file InfoSub.h.

◆ request_

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

Definition at line 483 of file InfoSub.h.

◆ seq_

std::uint64_t xrpl::InfoSub::seq_
privateinherited

Definition at line 484 of file InfoSub.h.

◆ accountHistorySubscriptions_

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

Definition at line 485 of file InfoSub.h.

◆ bookSubscriptions_

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

Definition at line 486 of file InfoSub.h.

◆ mptSubscriptions_

HashSet<MPTID> xrpl::InfoSub::mptSubscriptions_
privateinherited

Definition at line 487 of file InfoSub.h.

◆ apiVersion_

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

Definition at line 488 of file InfoSub.h.

◆ Object

Definition at line 138 of file CountedObject.h.