rippled
Loading...
Searching...
No Matches
InfoSub.cpp
1#include <xrpl/server/InfoSub.h>
2
3namespace xrpl {
4
5// This is the primary interface into the "client" portion of the program.
6// Code that wants to do normal operations on the network such as
7// creating and monitoring accounts, creating transactions, and so on
8// should use this interface. The RPC code will primarily be a light wrapper
9// over this code.
10
11// Eventually, it will check the node's operating mode (synced, unsynced,
12// etcetera) and defer to the correct means of processing. The current
13// code assumes this node is synced (and will continue to do so until
14// there's a functional network.
15
16InfoSub::InfoSub(Source& source) : m_source(source), mSeq(assign_id())
17{
18}
19
21 : m_consumer(consumer), m_source(source), mSeq(assign_id())
22{
23}
24
26{
35
36 // Use the internal unsubscribe so that it won't call
37 // back to us and modify its own parameter
38 if (!realTimeSubscriptions_.empty())
40
41 if (!normalSubscriptions_.empty())
43
44 for (auto const& account : accountHistorySubscriptions_)
46}
47
50{
51 return m_consumer;
52}
53
56{
57 return mSeq;
58}
59
60void
64
65void
67{
68 std::lock_guard const sl(mLock);
69
70 if (rt)
71 {
72 realTimeSubscriptions_.insert(account);
73 }
74 else
75 {
76 normalSubscriptions_.insert(account);
77 }
78}
79
80void
82{
83 std::lock_guard const sl(mLock);
84
85 if (rt)
86 {
87 realTimeSubscriptions_.erase(account);
88 }
89 else
90 {
91 normalSubscriptions_.erase(account);
92 }
93}
94
95bool
97{
98 std::lock_guard const sl(mLock);
99 return accountHistorySubscriptions_.insert(account).second;
100}
101
102void
104{
105 std::lock_guard const sl(mLock);
106 accountHistorySubscriptions_.erase(account);
107}
108
109void
111{
112 request_.reset();
113}
114
115void
120
123{
124 return request_;
125}
126
127void
128InfoSub::setApiVersion(unsigned int apiVersion)
129{
130 apiVersion_ = apiVersion;
131}
132
133unsigned int
135{
136 XRPL_ASSERT(apiVersion_ > 0, "xrpl::InfoSub::getApiVersion : valid API version");
137 return apiVersion_;
138}
139
140} // namespace xrpl
Abstracts the source of subscription data.
Definition InfoSub.h:47
virtual void unsubAccountHistoryInternal(std::uint64_t uListener, AccountID const &account, bool historyOnly)=0
virtual bool unsubRTTransactions(std::uint64_t uListener)=0
virtual bool unsubConsensus(std::uint64_t uListener)=0
virtual bool unsubTransactions(std::uint64_t uListener)=0
virtual void unsubAccountInternal(std::uint64_t uListener, hash_set< AccountID > const &vnaAccountIDs, bool realTime)=0
virtual bool unsubServer(std::uint64_t uListener)=0
virtual bool unsubLedger(std::uint64_t uListener)=0
virtual bool unsubPeerStatus(std::uint64_t uListener)=0
virtual bool unsubManifests(std::uint64_t uListener)=0
virtual bool unsubValidations(std::uint64_t uListener)=0
Source & m_source
Definition InfoSub.h:214
void setRequest(std::shared_ptr< InfoSubRequest > const &req)
Definition InfoSub.cpp:116
InfoSub(Source &source)
Definition InfoSub.cpp:16
void clearRequest()
Definition InfoSub.cpp:110
bool insertSubAccountHistory(AccountID const &account)
Definition InfoSub.cpp:96
Consumer & getConsumer()
Definition InfoSub.cpp:49
void setApiVersion(unsigned int apiVersion)
Definition InfoSub.cpp:128
virtual ~InfoSub()
Definition InfoSub.cpp:25
std::uint64_t getSeq() const
Definition InfoSub.cpp:55
void insertSubAccountInfo(AccountID const &account, bool rt)
Definition InfoSub.cpp:66
hash_set< AccountID > accountHistorySubscriptions_
Definition InfoSub.h:219
hash_set< AccountID > normalSubscriptions_
Definition InfoSub.h:216
std::uint64_t mSeq
Definition InfoSub.h:218
hash_set< AccountID > realTimeSubscriptions_
Definition InfoSub.h:215
std::mutex mLock
Definition InfoSub.h:210
void deleteSubAccountInfo(AccountID const &account, bool rt)
Definition InfoSub.cpp:81
void deleteSubAccountHistory(AccountID const &account)
Definition InfoSub.cpp:103
unsigned int getApiVersion() const noexcept
Definition InfoSub.cpp:134
Consumer m_consumer
Definition InfoSub.h:213
unsigned int apiVersion_
Definition InfoSub.h:220
void onSendEmpty()
Definition InfoSub.cpp:61
std::shared_ptr< InfoSubRequest > const & getRequest()
Definition InfoSub.cpp:122
std::shared_ptr< InfoSubRequest > request_
Definition InfoSub.h:217
An endpoint that consumes resources.
Definition Consumer.h:16
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5