rippled
Loading...
Searching...
No Matches
InfoSub.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_NET_INFOSUB_H_INCLUDED
21#define RIPPLE_NET_INFOSUB_H_INCLUDED
22
23#include <xrpld/app/misc/Manifest.h>
24
25#include <xrpl/basics/CountedObject.h>
26#include <xrpl/json/json_value.h>
27#include <xrpl/protocol/Book.h>
28#include <xrpl/protocol/ErrorCodes.h>
29#include <xrpl/resource/Consumer.h>
30
31namespace ripple {
32
33// Operations that clients may wish to perform against the network
34// Master operational handler, server sequencer, network tracker
35
36class InfoSubRequest : public CountedObject<InfoSubRequest>
37{
38public:
40
41 virtual ~InfoSubRequest() = default;
42
43 virtual Json::Value
44 doClose() = 0;
45 virtual Json::Value
46 doStatus(Json::Value const&) = 0;
47};
48
51class InfoSub : public CountedObject<InfoSub>
52{
53public:
55
56 // VFALCO TODO Standardize on the names of weak / strong pointer type
57 // aliases.
59
61
63
64public:
67 class Source
68 {
69 public:
70 virtual ~Source() = default;
71
72 // For some reason, these were originally called "rt"
73 // for "real time". They actually refer to whether
74 // you get transactions as they occur or once their
75 // results are confirmed
76 virtual void
78 ref ispListener,
79 hash_set<AccountID> const& vnaAccountIDs,
80 bool realTime) = 0;
81
82 // for normal use, removes from InfoSub and server
83 virtual void
85 ref isplistener,
86 hash_set<AccountID> const& vnaAccountIDs,
87 bool realTime) = 0;
88
89 // for use during InfoSub destruction
90 // Removes only from the server
91 virtual void
93 std::uint64_t uListener,
94 hash_set<AccountID> const& vnaAccountIDs,
95 bool realTime) = 0;
96
102 virtual error_code_i
103 subAccountHistory(ref ispListener, AccountID const& account) = 0;
104
113 virtual void
115 ref ispListener,
116 AccountID const& account,
117 bool historyOnly) = 0;
118
119 virtual void
121 std::uint64_t uListener,
122 AccountID const& account,
123 bool historyOnly) = 0;
124
125 // VFALCO TODO Document the bool return value
126 virtual bool
127 subLedger(ref ispListener, Json::Value& jvResult) = 0;
128 virtual bool
130
131 virtual bool
132 subBookChanges(ref ispListener) = 0;
133 virtual bool
135
136 virtual bool
137 subManifests(ref ispListener) = 0;
138 virtual bool
140 virtual void
142
143 virtual bool
144 subServer(ref ispListener, Json::Value& jvResult, bool admin) = 0;
145 virtual bool
147
148 virtual bool
149 subBook(ref ispListener, Book const&) = 0;
150 virtual bool
151 unsubBook(std::uint64_t uListener, Book const&) = 0;
152
153 virtual bool
154 subTransactions(ref ispListener) = 0;
155 virtual bool
157
158 virtual bool
159 subRTTransactions(ref ispListener) = 0;
160 virtual bool
162
163 virtual bool
164 subValidations(ref ispListener) = 0;
165 virtual bool
167
168 virtual bool
169 subPeerStatus(ref ispListener) = 0;
170 virtual bool
172 virtual void
174
175 virtual bool
176 subConsensus(ref ispListener) = 0;
177 virtual bool
179
180 // VFALCO TODO Remove
181 // This was added for one particular partner, it
182 // "pushes" subscription data to a particular URL.
183 //
184 virtual pointer
185 findRpcSub(std::string const& strUrl) = 0;
186 virtual pointer
187 addRpcSub(std::string const& strUrl, ref rspEntry) = 0;
188 virtual bool
189 tryRemoveRpcSub(std::string const& strUrl) = 0;
190 };
191
192public:
193 InfoSub(Source& source);
194 InfoSub(Source& source, Consumer consumer);
195
196 virtual ~InfoSub();
197
198 Consumer&
199 getConsumer();
200
201 virtual void
202 send(Json::Value const& jvObj, bool broadcast) = 0;
203
205 getSeq();
206
207 void
208 onSendEmpty();
209
210 void
211 insertSubAccountInfo(AccountID const& account, bool rt);
212
213 void
214 deleteSubAccountInfo(AccountID const& account, bool rt);
215
216 // return false if already subscribed to this account
217 bool
218 insertSubAccountHistory(AccountID const& account);
219
220 void
221 deleteSubAccountHistory(AccountID const& account);
222
223 void
224 clearRequest();
225
226 void
228
230 getRequest();
231
232 void
233 setApiVersion(unsigned int apiVersion);
234
235 unsigned int
236 getApiVersion() const noexcept;
237
238protected:
239 std::mutex mLock;
240
241private:
247 std::uint64_t mSeq;
249 unsigned int apiVersion_ = 0;
250
251 static int
253 {
254 static std::atomic<std::uint64_t> id(0);
255 return ++id;
256 }
257};
258
259} // namespace ripple
260
261#endif
Represents a JSON value.
Definition json_value.h:149
Specifies an order book.
Definition Book.h:36
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:68
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:52
std::uint64_t getSeq()
Definition InfoSub.cpp:74
Source & m_source
Definition InfoSub.h:243
std::mutex mLock
Definition InfoSub.h:239
virtual void send(Json::Value const &jvObj, bool broadcast)=0
std::shared_ptr< InfoSubRequest > const & getRequest()
Definition InfoSub.cpp:133
hash_set< AccountID > realTimeSubscriptions_
Definition InfoSub.h:244
unsigned int getApiVersion() const noexcept
Definition InfoSub.cpp:145
Consumer m_consumer
Definition InfoSub.h:242
bool insertSubAccountHistory(AccountID const &account)
Definition InfoSub.cpp:107
static int assign_id()
Definition InfoSub.h:252
hash_set< AccountID > normalSubscriptions_
Definition InfoSub.h:245
void deleteSubAccountInfo(AccountID const &account, bool rt)
Definition InfoSub.cpp:96
hash_set< AccountID > accountHistorySubscriptions_
Definition InfoSub.h:248
void setApiVersion(unsigned int apiVersion)
Definition InfoSub.cpp:139
void onSendEmpty()
Definition InfoSub.cpp:80
void insertSubAccountInfo(AccountID const &account, bool rt)
Definition InfoSub.cpp:85
void deleteSubAccountHistory(AccountID const &account)
Definition InfoSub.cpp:114
std::uint64_t mSeq
Definition InfoSub.h:247
void clearRequest()
Definition InfoSub.cpp:121
unsigned int apiVersion_
Definition InfoSub.h:249
std::shared_ptr< InfoSubRequest > request_
Definition InfoSub.h:246
virtual ~InfoSub()
Definition InfoSub.cpp:44
void setRequest(std::shared_ptr< InfoSubRequest > const &req)
Definition InfoSub.cpp:127
Consumer & getConsumer()
Definition InfoSub.cpp:68
An endpoint that consumes resources.
Definition Consumer.h:35
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
STL namespace.