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