1#include <xrpl/server/InfoSub.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/UnorderedContainers.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/beast/utility/instrumentation.h>
7#include <xrpl/protocol/AccountID.h>
8#include <xrpl/protocol/Book.h>
9#include <xrpl/protocol/UintTypes.h>
10#include <xrpl/resource/Consumer.h>
31safeUnsub(std::uint64_t seq, F&& f, beast::Journal j)
noexcept
37 catch (std::exception
const& e)
39 JLOG(j.warn()) <<
"~InfoSub[seq=" << seq <<
"]: cleanup step failed: " << e.
what();
43 JLOG(j.warn()) <<
"~InfoSub[seq=" << seq <<
"]: cleanup step failed: unknown exception";
51[[nodiscard]] std::size_t
54 std::size_t fresh = 0;
55 for (
auto const& entry : requested)
57 if (!existing.contains(entry))
94 auto const& j =
source_.journal();
150 source_.scheduleAccountCleanup(
318 XRPL_ASSERT(
apiVersion_ > 0,
"xrpl::InfoSub::getApiVersion : valid API version");
Abstracts the source of subscription data.
void setRequest(std::shared_ptr< InfoSubRequest > const &req)
void insertBookSubscription(Book const &book)
Record that this subscriber is following book.
bool insertSubAccountHistory(AccountID const &account)
bool tryReserveMPTSubscriptions(HashSet< MPTID > const &mptIDs, std::size_t cap)
Enforce the cap and reserve a request's net-new MPT issuances, atomically.
HashSet< MPTID > mptSubscriptions_
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.
void deleteSubMPTInfo(MPTID const &mptID)
std::size_t totalSubscriptionCount() const
Return the number of subscriptions currently tracked on this connection.
void setApiVersion(unsigned int apiVersion)
std::uint64_t getSeq() const
HashSet< AccountID > realTimeSubscriptions_
std::scoped_lock< decltype(lock_)> ScopedLock
resource::Consumer Consumer
void insertSubAccountInfo(AccountID const &account, bool rt)
std::size_t subscriptionCount(ScopedLock const &lock) const
The combined tally the per-connection cap is enforced against.
void deleteBookSubscription(Book const &book)
Stop tracking book for this subscriber.
bool hasAccountHistorySubscription(AccountID const &account) const
Whether this connection already tracks an account-history for account.
HashSet< AccountID > normalSubscriptions_
HashSet< Book > bookSubscriptions_
void insertSubMPTInfo(MPTID const &mptID)
HashSet< AccountID > accountHistorySubscriptions_
void deleteSubAccountInfo(AccountID const &account, bool rt)
void deleteSubAccountHistory(AccountID const &account)
unsigned int getApiVersion() const noexcept
std::shared_ptr< InfoSubRequest > const & getRequest()
std::shared_ptr< InfoSubRequest > request_
An endpoint that consumes resources.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
BaseUInt< 192 > MPTID
MPTID is a 192-bit value representing MPT Issuance ID, which is a concatenation of a 32-bit sequence ...
std::unordered_set< Value, Hash, Pred, Allocator > HashSet
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
constexpr bool exceedsSubscriptionCap(std::size_t current, std::size_t additional, std::size_t cap=kMaxSubscriptionsPerConnection)
Whether adding additional subscriptions to a connection already holding current would exceed the cap.