rippled
Loading...
Searching...
No Matches
InfoSub.h
1#pragma once
2
3#include <xrpl/basics/CountedObject.h>
4#include <xrpl/json/json_value.h>
5#include <xrpl/protocol/Book.h>
6#include <xrpl/protocol/ErrorCodes.h>
7#include <xrpl/resource/Consumer.h>
8#include <xrpl/server/Manifest.h>
9
10namespace xrpl {
11
12// Operations that clients may wish to perform against the network
13// Master operational handler, server sequencer, network tracker
14
15class InfoSubRequest : public CountedObject<InfoSubRequest>
16{
17public:
19
20 virtual ~InfoSubRequest() = default;
21
22 virtual Json::Value
23 doClose() = 0;
24 virtual Json::Value
25 doStatus(Json::Value const&) = 0;
26};
27
30class InfoSub : public CountedObject<InfoSub>
31{
32public:
34
35 // VFALCO TODO Standardize on the names of weak / strong pointer type
36 // aliases.
38
40
42
43public:
46 class Source
47 {
48 public:
49 virtual ~Source() = default;
50
51 // For some reason, these were originally called "rt"
52 // for "real time". They actually refer to whether
53 // you get transactions as they occur or once their
54 // results are confirmed
55 virtual void
56 subAccount(ref ispListener, hash_set<AccountID> const& vnaAccountIDs, bool realTime) = 0;
57
58 // for normal use, removes from InfoSub and server
59 virtual void
60 unsubAccount(ref isplistener, hash_set<AccountID> const& vnaAccountIDs, bool realTime) = 0;
61
62 // for use during InfoSub destruction
63 // Removes only from the server
64 virtual void
66 std::uint64_t uListener,
67 hash_set<AccountID> const& vnaAccountIDs,
68 bool realTime) = 0;
69
75 virtual error_code_i
76 subAccountHistory(ref ispListener, AccountID const& account) = 0;
77
86 virtual void
87 unsubAccountHistory(ref ispListener, AccountID const& account, bool historyOnly) = 0;
88
89 virtual void
91 std::uint64_t uListener,
92 AccountID const& account,
93 bool historyOnly) = 0;
94
95 // VFALCO TODO Document the bool return value
96 virtual bool
97 subLedger(ref ispListener, Json::Value& jvResult) = 0;
98 virtual bool
99 unsubLedger(std::uint64_t uListener) = 0;
100
101 virtual bool
102 subBookChanges(ref ispListener) = 0;
103 virtual bool
105
106 virtual bool
107 subManifests(ref ispListener) = 0;
108 virtual bool
110 virtual void
112
113 virtual bool
114 subServer(ref ispListener, Json::Value& jvResult, bool admin) = 0;
115 virtual bool
117
118 virtual bool
119 subBook(ref ispListener, Book const&) = 0;
120 virtual bool
121 unsubBook(std::uint64_t uListener, Book const&) = 0;
122
123 virtual bool
124 subTransactions(ref ispListener) = 0;
125 virtual bool
127
128 virtual bool
129 subRTTransactions(ref ispListener) = 0;
130 virtual bool
132
133 virtual bool
134 subValidations(ref ispListener) = 0;
135 virtual bool
137
138 virtual bool
139 subPeerStatus(ref ispListener) = 0;
140
141 virtual bool
143 virtual void
145
146 virtual bool
147 subConsensus(ref ispListener) = 0;
148 virtual bool
150
151 // VFALCO TODO Remove
152 // This was added for one particular partner, it
153 // "pushes" subscription data to a particular URL.
154 //
155 virtual pointer
156 findRpcSub(std::string const& strUrl) = 0;
157 virtual pointer
158 addRpcSub(std::string const& strUrl, ref rspEntry) = 0;
159 virtual bool
160 tryRemoveRpcSub(std::string const& strUrl) = 0;
161 };
162
163public:
164 InfoSub(Source& source);
165 InfoSub(Source& source, Consumer consumer);
166
167 virtual ~InfoSub();
168
169 Consumer&
170 getConsumer();
171
172 virtual void
173 send(Json::Value const& jvObj, bool broadcast) = 0;
174
176 getSeq() const;
177
178 void
179 onSendEmpty();
180
181 void
182 insertSubAccountInfo(AccountID const& account, bool rt);
183
184 void
185 deleteSubAccountInfo(AccountID const& account, bool rt);
186
187 // return false if already subscribed to this account
188 bool
189 insertSubAccountHistory(AccountID const& account);
190
191 void
192 deleteSubAccountHistory(AccountID const& account);
193
194 void
195 clearRequest();
196
197 void
199
201 getRequest();
202
203 void
204 setApiVersion(unsigned int apiVersion);
205
206 unsigned int
207 getApiVersion() const noexcept;
208
209protected:
210 std::mutex mLock;
211
212private:
218 std::uint64_t mSeq;
220 unsigned int apiVersion_ = 0;
221
222 static int
224 {
225 static std::atomic<std::uint64_t> id(0);
226 return ++id;
227 }
228};
229
230} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
Specifies an order book.
Definition Book.h:16
Tracks the number of instances of an object.
virtual Json::Value doClose()=0
virtual Json::Value doStatus(Json::Value const &)=0
virtual ~InfoSubRequest()=default
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 subTransactions(ref ispListener)=0
virtual void pubManifest(Manifest const &)=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 error_code_i subAccountHistory(ref ispListener, AccountID const &account)=0
subscribe an account's new transactions and retrieve the account's historical transactions
virtual bool tryRemoveRpcSub(std::string const &strUrl)=0
virtual bool unsubBookChanges(std::uint64_t uListener)=0
virtual void unsubAccountHistory(ref ispListener, AccountID const &account, bool historyOnly)=0
unsubscribe an account's transactions
virtual bool subPeerStatus(ref ispListener)=0
virtual bool subConsensus(ref ispListener)=0
virtual void subAccount(ref ispListener, hash_set< AccountID > const &vnaAccountIDs, bool realTime)=0
virtual bool subBook(ref ispListener, Book const &)=0
virtual bool subValidations(ref ispListener)=0
virtual ~Source()=default
virtual bool subRTTransactions(ref ispListener)=0
virtual bool unsubLedger(std::uint64_t uListener)=0
virtual bool unsubBook(std::uint64_t uListener, Book const &)=0
virtual bool unsubPeerStatus(std::uint64_t uListener)=0
virtual bool subBookChanges(ref ispListener)=0
virtual bool unsubManifests(std::uint64_t uListener)=0
virtual pointer addRpcSub(std::string const &strUrl, ref rspEntry)=0
virtual void pubPeerStatus(std::function< Json::Value(void)> const &)=0
virtual bool subServer(ref ispListener, Json::Value &jvResult, bool admin)=0
virtual bool subManifests(ref ispListener)=0
virtual bool unsubValidations(std::uint64_t uListener)=0
virtual bool subLedger(ref ispListener, Json::Value &jvResult)=0
virtual pointer findRpcSub(std::string const &strUrl)=0
virtual void unsubAccount(ref isplistener, hash_set< AccountID > const &vnaAccountIDs, bool realTime)=0
Manages a client's subscription to data feeds.
Definition InfoSub.h:31
Source & m_source
Definition InfoSub.h:214
void setRequest(std::shared_ptr< InfoSubRequest > const &req)
Definition InfoSub.cpp:116
void clearRequest()
Definition InfoSub.cpp:110
bool insertSubAccountHistory(AccountID const &account)
Definition InfoSub.cpp:96
static int assign_id()
Definition InfoSub.h:223
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
virtual void send(Json::Value const &jvObj, bool broadcast)=0
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
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
error_code_i
Definition ErrorCodes.h:20