rippled
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 <ripple/app/misc/Manifest.h>
24 #include <ripple/basics/CountedObject.h>
25 #include <ripple/json/json_value.h>
26 #include <ripple/protocol/Book.h>
27 #include <ripple/protocol/ErrorCodes.h>
28 #include <ripple/resource/Consumer.h>
29 #include <mutex>
30 
31 namespace ripple {
32 
33 // Operations that clients may wish to perform against the network
34 // Master operational handler, server sequencer, network tracker
35 
36 class PathRequest;
37 
40 class InfoSub : public CountedObject<InfoSub>
41 {
42 public:
44 
45  // VFALCO TODO Standardize on the names of weak / strong pointer type
46  // aliases.
48 
49  using ref = const std::shared_ptr<InfoSub>&;
50 
52 
53 public:
56  class Source
57  {
58  public:
59  virtual ~Source() = default;
60 
61  // For some reason, these were originally called "rt"
62  // for "real time". They actually refer to whether
63  // you get transactions as they occur or once their
64  // results are confirmed
65  virtual void
66  subAccount(
67  ref ispListener,
68  hash_set<AccountID> const& vnaAccountIDs,
69  bool realTime) = 0;
70 
71  // for normal use, removes from InfoSub and server
72  virtual void
74  ref isplistener,
75  hash_set<AccountID> const& vnaAccountIDs,
76  bool realTime) = 0;
77 
78  // for use during InfoSub destruction
79  // Removes only from the server
80  virtual void
82  std::uint64_t uListener,
83  hash_set<AccountID> const& vnaAccountIDs,
84  bool realTime) = 0;
85 
91  virtual error_code_i
92  subAccountHistory(ref ispListener, AccountID const& account) = 0;
93 
102  virtual void
104  ref ispListener,
105  AccountID const& account,
106  bool historyOnly) = 0;
107 
108  virtual void
110  std::uint64_t uListener,
111  AccountID const& account,
112  bool historyOnly) = 0;
113 
114  // VFALCO TODO Document the bool return value
115  virtual bool
116  subLedger(ref ispListener, Json::Value& jvResult) = 0;
117  virtual bool
118  unsubLedger(std::uint64_t uListener) = 0;
119 
120  virtual bool
121  subManifests(ref ispListener) = 0;
122  virtual bool
123  unsubManifests(std::uint64_t uListener) = 0;
124  virtual void
125  pubManifest(Manifest const&) = 0;
126 
127  virtual bool
128  subServer(ref ispListener, Json::Value& jvResult, bool admin) = 0;
129  virtual bool
130  unsubServer(std::uint64_t uListener) = 0;
131 
132  virtual bool
133  subBook(ref ispListener, Book const&) = 0;
134  virtual bool
135  unsubBook(std::uint64_t uListener, Book const&) = 0;
136 
137  virtual bool
138  subTransactions(ref ispListener) = 0;
139  virtual bool
140  unsubTransactions(std::uint64_t uListener) = 0;
141 
142  virtual bool
143  subRTTransactions(ref ispListener) = 0;
144  virtual bool
145  unsubRTTransactions(std::uint64_t uListener) = 0;
146 
147  virtual bool
148  subValidations(ref ispListener) = 0;
149  virtual bool
150  unsubValidations(std::uint64_t uListener) = 0;
151 
152  virtual bool
153  subPeerStatus(ref ispListener) = 0;
154  virtual bool
155  unsubPeerStatus(std::uint64_t uListener) = 0;
156  virtual void
157  pubPeerStatus(std::function<Json::Value(void)> const&) = 0;
158 
159  virtual bool
160  subConsensus(ref ispListener) = 0;
161  virtual bool
162  unsubConsensus(std::uint64_t uListener) = 0;
163 
164  // VFALCO TODO Remove
165  // This was added for one particular partner, it
166  // "pushes" subscription data to a particular URL.
167  //
168  virtual pointer
169  findRpcSub(std::string const& strUrl) = 0;
170  virtual pointer
171  addRpcSub(std::string const& strUrl, ref rspEntry) = 0;
172  virtual bool
173  tryRemoveRpcSub(std::string const& strUrl) = 0;
174  };
175 
176 public:
177  InfoSub(Source& source);
178  InfoSub(Source& source, Consumer consumer);
179 
180  virtual ~InfoSub();
181 
182  Consumer&
183  getConsumer();
184 
185  virtual void
186  send(Json::Value const& jvObj, bool broadcast) = 0;
187 
189  getSeq();
190 
191  void
192  onSendEmpty();
193 
194  void
195  insertSubAccountInfo(AccountID const& account, bool rt);
196 
197  void
198  deleteSubAccountInfo(AccountID const& account, bool rt);
199 
200  // return false if already subscribed to this account
201  bool
202  insertSubAccountHistory(AccountID const& account);
203 
204  void
205  deleteSubAccountHistory(AccountID const& account);
206 
207  void
209 
210  void
212 
214  getPathRequest();
215 
216 protected:
218 
219 private:
227 
228  static int
230  {
231  static std::atomic<std::uint64_t> id(0);
232  return ++id;
233  }
234 };
235 
236 } // namespace ripple
237 
238 #endif
ripple::InfoSub::m_consumer
Consumer m_consumer
Definition: InfoSub.h:220
ripple::InfoSub::~InfoSub
virtual ~InfoSub()
Definition: InfoSub.cpp:45
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
std::string
STL class.
std::shared_ptr< InfoSub >
ripple::InfoSub::realTimeSubscriptions_
hash_set< AccountID > realTimeSubscriptions_
Definition: InfoSub.h:222
ripple::InfoSub::Source::unsubTransactions
virtual bool unsubTransactions(std::uint64_t uListener)=0
ripple::InfoSub::Source::pubManifest
virtual void pubManifest(Manifest const &)=0
ripple::Manifest
Definition: Manifest.h:78
ripple::InfoSub::Source::unsubConsensus
virtual bool unsubConsensus(std::uint64_t uListener)=0
std::unordered_set
STL class.
ripple::InfoSub
Manages a client's subscription to data feeds.
Definition: InfoSub.h:40
ripple::InfoSub::send
virtual void send(Json::Value const &jvObj, bool broadcast)=0
ripple::InfoSub::Source::subValidations
virtual bool subValidations(ref ispListener)=0
ripple::InfoSub::insertSubAccountInfo
void insertSubAccountInfo(AccountID const &account, bool rt)
Definition: InfoSub.cpp:86
ripple::InfoSub::normalSubscriptions_
hash_set< AccountID > normalSubscriptions_
Definition: InfoSub.h:223
std::function
ripple::InfoSub::assign_id
static int assign_id()
Definition: InfoSub.h:229
ripple::InfoSub::Source::subRTTransactions
virtual bool subRTTransactions(ref ispListener)=0
ripple::InfoSub::Source::subTransactions
virtual bool subTransactions(ref ispListener)=0
ripple::InfoSub::Source::subAccountHistory
virtual error_code_i subAccountHistory(ref ispListener, AccountID const &account)=0
subscribe an account's new transactions and retrieve the account's historical transactions
ripple::InfoSub::Source::unsubAccountInternal
virtual void unsubAccountInternal(std::uint64_t uListener, hash_set< AccountID > const &vnaAccountIDs, bool realTime)=0
ripple::InfoSub::Source::unsubValidations
virtual bool unsubValidations(std::uint64_t uListener)=0
ripple::error_code_i
error_code_i
Definition: ErrorCodes.h:40
ripple::InfoSub::Source::subBook
virtual bool subBook(ref ispListener, Book const &)=0
ripple::InfoSub::Source::findRpcSub
virtual pointer findRpcSub(std::string const &strUrl)=0
ripple::InfoSub::mLock
std::mutex mLock
Definition: InfoSub.h:217
ripple::InfoSub::Source::subManifests
virtual bool subManifests(ref ispListener)=0
ripple::base_uint< 160, detail::AccountIDTag >
ripple::InfoSub::clearPathRequest
void clearPathRequest()
Definition: InfoSub.cpp:122
ripple::InfoSub::Source::unsubAccountHistoryInternal
virtual void unsubAccountHistoryInternal(std::uint64_t uListener, AccountID const &account, bool historyOnly)=0
ripple::InfoSub::Source::subLedger
virtual bool subLedger(ref ispListener, Json::Value &jvResult)=0
ripple::InfoSub::Source::unsubBook
virtual bool unsubBook(std::uint64_t uListener, Book const &)=0
ripple::InfoSub::Source::unsubAccountHistory
virtual void unsubAccountHistory(ref ispListener, AccountID const &account, bool historyOnly)=0
unsubscribe an account's transactions
ripple::InfoSub::Source::pubPeerStatus
virtual void pubPeerStatus(std::function< Json::Value(void)> const &)=0
ripple::InfoSub::Source
Abstracts the source of subscription data.
Definition: InfoSub.h:56
ripple::InfoSub::Source::addRpcSub
virtual pointer addRpcSub(std::string const &strUrl, ref rspEntry)=0
ripple::InfoSub::deleteSubAccountInfo
void deleteSubAccountInfo(AccountID const &account, bool rt)
Definition: InfoSub.cpp:97
ripple::InfoSub::Source::unsubAccount
virtual void unsubAccount(ref isplistener, hash_set< AccountID > const &vnaAccountIDs, bool realTime)=0
std::uint64_t
ripple::InfoSub::Source::unsubRTTransactions
virtual bool unsubRTTransactions(std::uint64_t uListener)=0
ripple::InfoSub::Source::~Source
virtual ~Source()=default
std::atomic< std::uint64_t >
ripple::InfoSub::Source::unsubPeerStatus
virtual bool unsubPeerStatus(std::uint64_t uListener)=0
ripple::InfoSub::mPathRequest
std::shared_ptr< PathRequest > mPathRequest
Definition: InfoSub.h:224
std::weak_ptr< InfoSub >
ripple::InfoSub::Source::unsubServer
virtual bool unsubServer(std::uint64_t uListener)=0
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::InfoSub::deleteSubAccountHistory
void deleteSubAccountHistory(AccountID const &account)
Definition: InfoSub.cpp:115
ripple::InfoSub::insertSubAccountHistory
bool insertSubAccountHistory(AccountID const &account)
Definition: InfoSub.cpp:108
ripple::InfoSub::getSeq
std::uint64_t getSeq()
Definition: InfoSub.cpp:75
ripple::InfoSub::Source::unsubManifests
virtual bool unsubManifests(std::uint64_t uListener)=0
ripple::InfoSub::Source::tryRemoveRpcSub
virtual bool tryRemoveRpcSub(std::string const &strUrl)=0
ripple::InfoSub::m_source
Source & m_source
Definition: InfoSub.h:221
ripple::InfoSub::getPathRequest
std::shared_ptr< PathRequest > const & getPathRequest()
Definition: InfoSub.cpp:134
ripple::Resource::Consumer
An endpoint that consumes resources.
Definition: Consumer.h:34
ripple::InfoSub::mSeq
std::uint64_t mSeq
Definition: InfoSub.h:225
mutex
ripple::InfoSub::getConsumer
Consumer & getConsumer()
Definition: InfoSub.cpp:69
ripple::Book
Specifies an order book.
Definition: Book.h:32
ripple::InfoSub::accountHistorySubscriptions_
hash_set< AccountID > accountHistorySubscriptions_
Definition: InfoSub.h:226
ripple::InfoSub::Source::subConsensus
virtual bool subConsensus(ref ispListener)=0
ripple::InfoSub::Source::subPeerStatus
virtual bool subPeerStatus(ref ispListener)=0
ripple::InfoSub::setPathRequest
void setPathRequest(const std::shared_ptr< PathRequest > &req)
Definition: InfoSub.cpp:128
ripple::InfoSub::onSendEmpty
void onSendEmpty()
Definition: InfoSub.cpp:81
ripple::InfoSub::Source::subServer
virtual bool subServer(ref ispListener, Json::Value &jvResult, bool admin)=0
ripple::InfoSub::Source::subAccount
virtual void subAccount(ref ispListener, hash_set< AccountID > const &vnaAccountIDs, bool realTime)=0
ripple::InfoSub::InfoSub
InfoSub(Source &source)
Definition: InfoSub.cpp:36
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::InfoSub::Source::unsubLedger
virtual bool unsubLedger(std::uint64_t uListener)=0