xrpld
Loading...
Searching...
No Matches
InfoSub.h
1#pragma once
2
3#include <xrpl/basics/CountedObject.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/json/json_value.h>
6#include <xrpl/protocol/Book.h>
7#include <xrpl/protocol/ErrorCodes.h>
8#include <xrpl/resource/Consumer.h>
9#include <xrpl/server/Manifest.h>
10
11namespace xrpl {
12
13// Operations that clients may wish to perform against the network
14// Master operational handler, server sequencer, network tracker
15
16class InfoSubRequest : public CountedObject<InfoSubRequest>
17{
18public:
20
21 virtual ~InfoSubRequest() = default;
22
23 virtual json::Value
24 doClose() = 0;
25 virtual json::Value
26 doStatus(json::Value const&) = 0;
27};
28
44class InfoSub : public CountedObject<InfoSub>
45{
46public:
48
49 // VFALCO TODO Standardize on the names of weak / strong pointer type
50 // aliases.
52
54
56
57public:
60 class Source
61 {
62 public:
63 virtual ~Source() = default;
64
65 // For some reason, these were originally called "rt"
66 // for "real time". They actually refer to whether
67 // you get transactions as they occur or once their
68 // results are confirmed
69 virtual void
70 subAccount(ref ispListener, hash_set<AccountID> const& vnaAccountIDs, bool realTime) = 0;
71
72 // for normal use, removes from InfoSub and server
73 virtual void
74 unsubAccount(ref isplistener, hash_set<AccountID> const& vnaAccountIDs, bool realTime) = 0;
75
76 // for use during InfoSub destruction
77 // Removes only from the server
78 virtual void
80 std::uint64_t uListener,
81 hash_set<AccountID> const& vnaAccountIDs,
82 bool realTime) = 0;
83
89 virtual ErrorCodeI
90 subAccountHistory(ref ispListener, AccountID const& account) = 0;
91
100 virtual void
101 unsubAccountHistory(ref ispListener, AccountID const& account, bool historyOnly) = 0;
102
103 virtual void
105 std::uint64_t uListener,
106 AccountID const& account,
107 bool historyOnly) = 0;
108
109 // VFALCO TODO Document the bool return value
110 virtual bool
111 subLedger(ref ispListener, json::Value& jvResult) = 0;
112 virtual bool
114
115 virtual bool
116 subBookChanges(ref ispListener) = 0;
117 virtual bool
119
120 virtual bool
121 subManifests(ref ispListener) = 0;
122 virtual bool
124 virtual void
126
127 virtual bool
128 subServer(ref ispListener, json::Value& jvResult, bool admin) = 0;
129 virtual bool
131
132 virtual bool
133 subBook(ref ispListener, Book const&) = 0;
134
152 virtual bool
153 unsubBook(ref ispListener, Book const&) = 0;
154
169 virtual bool
170 unsubBookInternal(std::uint64_t uListener, Book const&) = 0;
171
172 virtual bool
173 subTransactions(ref ispListener) = 0;
174 virtual bool
176
177 virtual bool
178 subRTTransactions(ref ispListener) = 0;
179 virtual bool
181
182 virtual bool
183 subValidations(ref ispListener) = 0;
184 virtual bool
186
187 virtual bool
188 subPeerStatus(ref ispListener) = 0;
189
190 virtual bool
192 virtual void
194
195 virtual bool
196 subConsensus(ref ispListener) = 0;
197 virtual bool
199
200 // VFALCO TODO Remove
201 // This was added for one particular partner, it
202 // "pushes" subscription data to a particular URL.
203 //
204 virtual pointer
205 findRpcSub(std::string const& strUrl) = 0;
206 virtual pointer
207 addRpcSub(std::string const& strUrl, ref rspEntry) = 0;
208 virtual bool
209 tryRemoveRpcSub(std::string const& strUrl) = 0;
210
215 [[nodiscard]] virtual beast::Journal const&
216 journal() const = 0;
217 };
218
219public:
220 InfoSub(Source& source);
221 InfoSub(Source& source, Consumer consumer);
222
223 virtual ~InfoSub();
224
225 Consumer&
226 getConsumer();
227
228 virtual void
229 send(json::Value const& jvObj, bool broadcast) = 0;
230
231 [[nodiscard]] std::uint64_t
232 getSeq() const;
233
234 void
235 onSendEmpty();
236
237 void
238 insertSubAccountInfo(AccountID const& account, bool rt);
239
240 void
241 deleteSubAccountInfo(AccountID const& account, bool rt);
242
253 void
254 insertBookSubscription(Book const& book);
255
265 void
266 deleteBookSubscription(Book const& book);
267
268 // return false if already subscribed to this account
269 bool
270 insertSubAccountHistory(AccountID const& account);
271
272 void
273 deleteSubAccountHistory(AccountID const& account);
274
275 void
276 clearRequest();
277
278 void
280
282 getRequest();
283
284 void
285 setApiVersion(unsigned int apiVersion);
286
287 [[nodiscard]] unsigned int
288 getApiVersion() const noexcept;
289
290protected:
291 std::mutex lock_;
292
293private:
299 std::uint64_t seq_;
302 unsigned int apiVersion_ = 0;
303
304 static int
306 {
307 static std::atomic<std::uint64_t> kID(0);
308 return ++kID;
309 }
310};
311
312} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
Represents a JSON value.
Definition json_value.h:130
Specifies an order book.
Definition Book.h:16
std::shared_ptr< InfoSubRequest > pointer
Definition InfoSub.h:19
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:61
virtual ErrorCodeI subAccountHistory(ref ispListener, AccountID const &account)=0
subscribe an account's new transactions and retrieve the account's historical transactions
virtual void pubPeerStatus(std::function< json::Value(void)> const &)=0
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 beast::Journal const & journal() const =0
Journal used by InfoSub for diagnostics that occur after the owning subsystem (e.g.
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 subServer(ref ispListener, json::Value &jvResult, bool admin)=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 unsubBook(ref ispListener, Book const &)=0
Remove a book subscription for a live subscriber.
virtual bool unsubLedger(std::uint64_t uListener)=0
virtual bool subLedger(ref ispListener, json::Value &jvResult)=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 bool unsubBookInternal(std::uint64_t uListener, Book const &)=0
Remove a book subscription during InfoSub teardown.
virtual bool subManifests(ref ispListener)=0
virtual bool unsubValidations(std::uint64_t uListener)=0
virtual pointer findRpcSub(std::string const &strUrl)=0
virtual void unsubAccount(ref isplistener, hash_set< AccountID > const &vnaAccountIDs, bool realTime)=0
void setRequest(std::shared_ptr< InfoSubRequest > const &req)
Definition InfoSub.cpp:189
void insertBookSubscription(Book const &book)
Record that this subscriber is following book.
Definition InfoSub.cpp:169
virtual void send(json::Value const &jvObj, bool broadcast)=0
std::shared_ptr< InfoSub > pointer
Definition InfoSub.h:47
InfoSub(Source &source)
Definition InfoSub.cpp:56
Resource::Consumer Consumer
Definition InfoSub.h:55
void clearRequest()
Definition InfoSub.cpp:183
Consumer consumer_
Definition InfoSub.h:294
bool insertSubAccountHistory(AccountID const &account)
Definition InfoSub.cpp:155
Consumer & getConsumer()
Definition InfoSub.cpp:108
void setApiVersion(unsigned int apiVersion)
Definition InfoSub.cpp:201
static int assignId()
Definition InfoSub.h:305
virtual ~InfoSub()
Definition InfoSub.cpp:65
std::uint64_t getSeq() const
Definition InfoSub.cpp:114
void insertSubAccountInfo(AccountID const &account, bool rt)
Definition InfoSub.cpp:125
std::shared_ptr< InfoSub > const & ref
Definition InfoSub.h:53
void deleteBookSubscription(Book const &book)
Stop tracking book for this subscriber.
Definition InfoSub.cpp:176
Source & source_
Definition InfoSub.h:295
hash_set< AccountID > accountHistorySubscriptions_
Definition InfoSub.h:300
hash_set< AccountID > normalSubscriptions_
Definition InfoSub.h:297
hash_set< Book > bookSubscriptions_
Definition InfoSub.h:301
std::weak_ptr< InfoSub > wptr
Definition InfoSub.h:51
hash_set< AccountID > realTimeSubscriptions_
Definition InfoSub.h:296
void deleteSubAccountInfo(AccountID const &account, bool rt)
Definition InfoSub.cpp:140
void deleteSubAccountHistory(AccountID const &account)
Definition InfoSub.cpp:162
unsigned int getApiVersion() const noexcept
Definition InfoSub.cpp:207
std::uint64_t seq_
Definition InfoSub.h:299
std::mutex lock_
Definition InfoSub.h:291
unsigned int apiVersion_
Definition InfoSub.h:302
void onSendEmpty()
Definition InfoSub.cpp:120
std::shared_ptr< InfoSubRequest > const & getRequest()
Definition InfoSub.cpp:195
std::shared_ptr< InfoSubRequest > request_
Definition InfoSub.h:298
An endpoint that consumes resources.
Definition Consumer.h:15
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
ErrorCodeI
Definition ErrorCodes.h:22
std::unordered_set< Value, Hash, Pred, Allocator > hash_set
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28