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/resource/Consumer.h>
28 #include <mutex>
29 
30 namespace ripple {
31 
32 // Operations that clients may wish to perform against the network
33 // Master operational handler, server sequencer, network tracker
34 
35 class PathRequest;
36 
39 class InfoSub : public CountedObject<InfoSub>
40 {
41 public:
43 
44  // VFALCO TODO Standardize on the names of weak / strong pointer type
45  // aliases.
47 
48  using ref = const std::shared_ptr<InfoSub>&;
49 
51 
52 public:
55  class Source
56  {
57  public:
58  virtual ~Source() = default;
59 
60  // For some reason, these were originally called "rt"
61  // for "real time". They actually refer to whether
62  // you get transactions as they occur or once their
63  // results are confirmed
64  virtual void
65  subAccount(
66  ref ispListener,
67  hash_set<AccountID> const& vnaAccountIDs,
68  bool realTime) = 0;
69 
70  // for normal use, removes from InfoSub and server
71  virtual void
73  ref isplistener,
74  hash_set<AccountID> const& vnaAccountIDs,
75  bool realTime) = 0;
76 
77  // for use during InfoSub destruction
78  // Removes only from the server
79  virtual void
81  std::uint64_t uListener,
82  hash_set<AccountID> const& vnaAccountIDs,
83  bool realTime) = 0;
84 
85  // VFALCO TODO Document the bool return value
86  virtual bool
87  subLedger(ref ispListener, Json::Value& jvResult) = 0;
88  virtual bool
89  unsubLedger(std::uint64_t uListener) = 0;
90 
91  virtual bool
92  subManifests(ref ispListener) = 0;
93  virtual bool
94  unsubManifests(std::uint64_t uListener) = 0;
95  virtual void
96  pubManifest(Manifest const&) = 0;
97 
98  virtual bool
99  subServer(ref ispListener, Json::Value& jvResult, bool admin) = 0;
100  virtual bool
101  unsubServer(std::uint64_t uListener) = 0;
102 
103  virtual bool
104  subBook(ref ispListener, Book const&) = 0;
105  virtual bool
106  unsubBook(std::uint64_t uListener, Book const&) = 0;
107 
108  virtual bool
109  subTransactions(ref ispListener) = 0;
110  virtual bool
111  unsubTransactions(std::uint64_t uListener) = 0;
112 
113  virtual bool
114  subRTTransactions(ref ispListener) = 0;
115  virtual bool
116  unsubRTTransactions(std::uint64_t uListener) = 0;
117 
118  virtual bool
119  subValidations(ref ispListener) = 0;
120  virtual bool
121  unsubValidations(std::uint64_t uListener) = 0;
122 
123  virtual bool
124  subPeerStatus(ref ispListener) = 0;
125  virtual bool
126  unsubPeerStatus(std::uint64_t uListener) = 0;
127  virtual void
128  pubPeerStatus(std::function<Json::Value(void)> const&) = 0;
129 
130  virtual bool
131  subConsensus(ref ispListener) = 0;
132  virtual bool
133  unsubConsensus(std::uint64_t uListener) = 0;
134 
135  // VFALCO TODO Remove
136  // This was added for one particular partner, it
137  // "pushes" subscription data to a particular URL.
138  //
139  virtual pointer
140  findRpcSub(std::string const& strUrl) = 0;
141  virtual pointer
142  addRpcSub(std::string const& strUrl, ref rspEntry) = 0;
143  virtual bool
144  tryRemoveRpcSub(std::string const& strUrl) = 0;
145  };
146 
147 public:
148  InfoSub(Source& source);
149  InfoSub(Source& source, Consumer consumer);
150 
151  virtual ~InfoSub();
152 
153  Consumer&
154  getConsumer();
155 
156  virtual void
157  send(Json::Value const& jvObj, bool broadcast) = 0;
158 
160  getSeq();
161 
162  void
163  onSendEmpty();
164 
165  void
166  insertSubAccountInfo(AccountID const& account, bool rt);
167 
168  void
169  deleteSubAccountInfo(AccountID const& account, bool rt);
170 
171  void
173 
174  void
176 
178  getPathRequest();
179 
180 protected:
182 
183 private:
190 
191  static int
193  {
194  static std::atomic<std::uint64_t> id(0);
195  return ++id;
196  }
197 };
198 
199 } // namespace ripple
200 
201 #endif
ripple::InfoSub::m_consumer
Consumer m_consumer
Definition: InfoSub.h:184
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:186
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:39
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:83
ripple::InfoSub::normalSubscriptions_
hash_set< AccountID > normalSubscriptions_
Definition: InfoSub.h:187
std::function
ripple::InfoSub::assign_id
static int assign_id()
Definition: InfoSub.h:192
ripple::InfoSub::Source::subRTTransactions
virtual bool subRTTransactions(ref ispListener)=0
ripple::InfoSub::Source::subTransactions
virtual bool subTransactions(ref ispListener)=0
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::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:181
ripple::InfoSub::Source::subManifests
virtual bool subManifests(ref ispListener)=0
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:74
ripple::InfoSub::clearPathRequest
void clearPathRequest()
Definition: InfoSub.cpp:105
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::pubPeerStatus
virtual void pubPeerStatus(std::function< Json::Value(void)> const &)=0
ripple::InfoSub::Source
Abstracts the source of subscription data.
Definition: InfoSub.h:55
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:94
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:188
std::weak_ptr
STL class.
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::getSeq
std::uint64_t getSeq()
Definition: InfoSub.cpp:72
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:185
ripple::InfoSub::getPathRequest
std::shared_ptr< PathRequest > const & getPathRequest()
Definition: InfoSub.cpp:117
ripple::Resource::Consumer
An endpoint that consumes resources.
Definition: Consumer.h:33
ripple::InfoSub::mSeq
std::uint64_t mSeq
Definition: InfoSub.h:189
mutex
ripple::InfoSub::getConsumer
Consumer & getConsumer()
Definition: InfoSub.cpp:66
ripple::Book
Specifies an order book.
Definition: Book.h:32
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:111
ripple::InfoSub::onSendEmpty
void onSendEmpty()
Definition: InfoSub.cpp:78
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