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#include <xrpl/basics/CountedObject.h>
25#include <xrpl/json/json_value.h>
26#include <xrpl/protocol/Book.h>
27#include <xrpl/protocol/ErrorCodes.h>
28#include <xrpl/resource/Consumer.h>
29
30namespace ripple {
31
32// Operations that clients may wish to perform against the network
33// Master operational handler, server sequencer, network tracker
34
35class InfoSubRequest : public CountedObject<InfoSubRequest>
36{
37public:
39
40 virtual ~InfoSubRequest() = default;
41
42 virtual Json::Value
43 doClose() = 0;
44 virtual Json::Value
45 doStatus(Json::Value const&) = 0;
46};
47
50class InfoSub : public CountedObject<InfoSub>
51{
52public:
54
55 // VFALCO TODO Standardize on the names of weak / strong pointer type
56 // aliases.
58
60
62
63public:
66 class Source
67 {
68 public:
69 virtual ~Source() = default;
70
71 // For some reason, these were originally called "rt"
72 // for "real time". They actually refer to whether
73 // you get transactions as they occur or once their
74 // results are confirmed
75 virtual void
77 ref ispListener,
78 hash_set<AccountID> const& vnaAccountIDs,
79 bool realTime) = 0;
80
81 // for normal use, removes from InfoSub and server
82 virtual void
84 ref isplistener,
85 hash_set<AccountID> const& vnaAccountIDs,
86 bool realTime) = 0;
87
88 // for use during InfoSub destruction
89 // Removes only from the server
90 virtual void
92 std::uint64_t uListener,
93 hash_set<AccountID> const& vnaAccountIDs,
94 bool realTime) = 0;
95
101 virtual error_code_i
102 subAccountHistory(ref ispListener, AccountID const& account) = 0;
103
112 virtual void
114 ref ispListener,
115 AccountID const& account,
116 bool historyOnly) = 0;
117
118 virtual void
120 std::uint64_t uListener,
121 AccountID const& account,
122 bool historyOnly) = 0;
123
124 // VFALCO TODO Document the bool return value
125 virtual bool
126 subLedger(ref ispListener, Json::Value& jvResult) = 0;
127 virtual bool
129
130 virtual bool
131 subBookChanges(ref ispListener) = 0;
132 virtual bool
134
135 virtual bool
136 subManifests(ref ispListener) = 0;
137 virtual bool
139 virtual void
141
142 virtual bool
143 subServer(ref ispListener, Json::Value& jvResult, bool admin) = 0;
144 virtual bool
146
147 virtual bool
148 subBook(ref ispListener, Book const&) = 0;
149 virtual bool
150 unsubBook(std::uint64_t uListener, Book const&) = 0;
151
152 virtual bool
153 subTransactions(ref ispListener) = 0;
154 virtual bool
156
157 virtual bool
158 subRTTransactions(ref ispListener) = 0;
159 virtual bool
161
162 virtual bool
163 subValidations(ref ispListener) = 0;
164 virtual bool
166
167 virtual bool
168 subPeerStatus(ref ispListener) = 0;
169 virtual bool
171 virtual void
173
174 virtual bool
175 subConsensus(ref ispListener) = 0;
176 virtual bool
178
179 // VFALCO TODO Remove
180 // This was added for one particular partner, it
181 // "pushes" subscription data to a particular URL.
182 //
183 virtual pointer
184 findRpcSub(std::string const& strUrl) = 0;
185 virtual pointer
186 addRpcSub(std::string const& strUrl, ref rspEntry) = 0;
187 virtual bool
188 tryRemoveRpcSub(std::string const& strUrl) = 0;
189 };
190
191public:
192 InfoSub(Source& source);
193 InfoSub(Source& source, Consumer consumer);
194
195 virtual ~InfoSub();
196
197 Consumer&
198 getConsumer();
199
200 virtual void
201 send(Json::Value const& jvObj, bool broadcast) = 0;
202
204 getSeq();
205
206 void
207 onSendEmpty();
208
209 void
210 insertSubAccountInfo(AccountID const& account, bool rt);
211
212 void
213 deleteSubAccountInfo(AccountID const& account, bool rt);
214
215 // return false if already subscribed to this account
216 bool
217 insertSubAccountHistory(AccountID const& account);
218
219 void
220 deleteSubAccountHistory(AccountID const& account);
221
222 void
223 clearRequest();
224
225 void
227
229 getRequest();
230
231 void
232 setApiVersion(unsigned int apiVersion);
233
234 unsigned int
235 getApiVersion() const noexcept;
236
237protected:
238 std::mutex mLock;
239
240private:
246 std::uint64_t mSeq;
248 unsigned int apiVersion_ = 0;
249
250 static int
252 {
253 static std::atomic<std::uint64_t> id(0);
254 return ++id;
255 }
256};
257
258} // namespace ripple
259
260#endif
Represents a JSON value.
Definition: json_value.h:148
Specifies an order book.
Definition: Book.h:35
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:67
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:51
std::uint64_t getSeq()
Definition: InfoSub.cpp:74
Source & m_source
Definition: InfoSub.h:242
std::mutex mLock
Definition: InfoSub.h:238
virtual void send(Json::Value const &jvObj, bool broadcast)=0
hash_set< AccountID > realTimeSubscriptions_
Definition: InfoSub.h:243
unsigned int getApiVersion() const noexcept
Definition: InfoSub.cpp:145
Consumer m_consumer
Definition: InfoSub.h:241
bool insertSubAccountHistory(AccountID const &account)
Definition: InfoSub.cpp:107
static int assign_id()
Definition: InfoSub.h:251
hash_set< AccountID > normalSubscriptions_
Definition: InfoSub.h:244
void deleteSubAccountInfo(AccountID const &account, bool rt)
Definition: InfoSub.cpp:96
hash_set< AccountID > accountHistorySubscriptions_
Definition: InfoSub.h:247
void setApiVersion(unsigned int apiVersion)
Definition: InfoSub.cpp:139
std::shared_ptr< InfoSubRequest > const & getRequest()
Definition: InfoSub.cpp:133
void onSendEmpty()
Definition: InfoSub.cpp:80
void insertSubAccountInfo(AccountID const &account, bool rt)
Definition: InfoSub.cpp:85
void setRequest(const std::shared_ptr< InfoSubRequest > &req)
Definition: InfoSub.cpp:127
void deleteSubAccountHistory(AccountID const &account)
Definition: InfoSub.cpp:114
std::uint64_t mSeq
Definition: InfoSub.h:246
void clearRequest()
Definition: InfoSub.cpp:121
unsigned int apiVersion_
Definition: InfoSub.h:248
std::shared_ptr< InfoSubRequest > request_
Definition: InfoSub.h:245
virtual ~InfoSub()
Definition: InfoSub.cpp:44
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:26
error_code_i
Definition: ErrorCodes.h:40
STL namespace.