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/core/Stoppable.h>
26 #include <ripple/json/json_value.h>
27 #include <ripple/protocol/Book.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:
43  static char const*
45  {
46  return "InfoSub";
47  }
48 
50 
51  // VFALCO TODO Standardize on the names of weak / strong pointer type
52  // aliases.
54 
55  using ref = const std::shared_ptr<InfoSub>&;
56 
58 
59 public:
62  class Source : public Stoppable
63  {
64  protected:
65  Source(char const* name, Stoppable& parent);
66 
67  public:
68  // For some reason, these were originally called "rt"
69  // for "real time". They actually refer to whether
70  // you get transactions as they occur or once their
71  // results are confirmed
72  virtual void
73  subAccount(
74  ref ispListener,
75  hash_set<AccountID> const& vnaAccountIDs,
76  bool realTime) = 0;
77 
78  // for normal use, removes from InfoSub and server
79  virtual void
81  ref isplistener,
82  hash_set<AccountID> const& vnaAccountIDs,
83  bool realTime) = 0;
84 
85  // for use during InfoSub destruction
86  // Removes only from the server
87  virtual void
89  std::uint64_t uListener,
90  hash_set<AccountID> const& vnaAccountIDs,
91  bool realTime) = 0;
92 
93  // VFALCO TODO Document the bool return value
94  virtual bool
95  subLedger(ref ispListener, Json::Value& jvResult) = 0;
96  virtual bool
97  unsubLedger(std::uint64_t uListener) = 0;
98 
99  virtual bool
100  subManifests(ref ispListener) = 0;
101  virtual bool
102  unsubManifests(std::uint64_t uListener) = 0;
103  virtual void
104  pubManifest(Manifest const&) = 0;
105 
106  virtual bool
107  subServer(ref ispListener, Json::Value& jvResult, bool admin) = 0;
108  virtual bool
109  unsubServer(std::uint64_t uListener) = 0;
110 
111  virtual bool
112  subBook(ref ispListener, Book const&) = 0;
113  virtual bool
114  unsubBook(std::uint64_t uListener, Book const&) = 0;
115 
116  virtual bool
117  subTransactions(ref ispListener) = 0;
118  virtual bool
119  unsubTransactions(std::uint64_t uListener) = 0;
120 
121  virtual bool
122  subRTTransactions(ref ispListener) = 0;
123  virtual bool
124  unsubRTTransactions(std::uint64_t uListener) = 0;
125 
126  virtual bool
127  subValidations(ref ispListener) = 0;
128  virtual bool
129  unsubValidations(std::uint64_t uListener) = 0;
130 
131  virtual bool
132  subPeerStatus(ref ispListener) = 0;
133  virtual bool
134  unsubPeerStatus(std::uint64_t uListener) = 0;
135  virtual void
136  pubPeerStatus(std::function<Json::Value(void)> const&) = 0;
137 
138  virtual bool
139  subConsensus(ref ispListener) = 0;
140  virtual bool
141  unsubConsensus(std::uint64_t uListener) = 0;
142 
143  // VFALCO TODO Remove
144  // This was added for one particular partner, it
145  // "pushes" subscription data to a particular URL.
146  //
147  virtual pointer
148  findRpcSub(std::string const& strUrl) = 0;
149  virtual pointer
150  addRpcSub(std::string const& strUrl, ref rspEntry) = 0;
151  virtual bool
152  tryRemoveRpcSub(std::string const& strUrl) = 0;
153  };
154 
155 public:
156  InfoSub(Source& source);
157  InfoSub(Source& source, Consumer consumer);
158 
159  virtual ~InfoSub();
160 
161  Consumer&
162  getConsumer();
163 
164  virtual void
165  send(Json::Value const& jvObj, bool broadcast) = 0;
166 
168  getSeq();
169 
170  void
171  onSendEmpty();
172 
173  void
174  insertSubAccountInfo(AccountID const& account, bool rt);
175 
176  void
177  deleteSubAccountInfo(AccountID const& account, bool rt);
178 
179  void
181 
182  void
184 
186  getPathRequest();
187 
188 protected:
190 
191 private:
198 
199  static int
201  {
202  static std::atomic<std::uint64_t> id(0);
203  return ++id;
204  }
205 };
206 
207 } // namespace ripple
208 
209 #endif
ripple::InfoSub::m_consumer
Consumer m_consumer
Definition: InfoSub.h:192
ripple::InfoSub::~InfoSub
virtual ~InfoSub()
Definition: InfoSub.cpp:54
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:110
std::string
STL class.
std::shared_ptr< InfoSub >
ripple::InfoSub::realTimeSubscriptions_
hash_set< AccountID > realTimeSubscriptions_
Definition: InfoSub.h:194
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:92
ripple::InfoSub::normalSubscriptions_
hash_set< AccountID > normalSubscriptions_
Definition: InfoSub.h:195
std::function
ripple::InfoSub::assign_id
static int assign_id()
Definition: InfoSub.h:200
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:189
ripple::InfoSub::Source::subManifests
virtual bool subManifests(ref ispListener)=0
ripple::base_uint
Definition: base_uint.h:63
ripple::InfoSub::clearPathRequest
void clearPathRequest()
Definition: InfoSub.cpp:114
ripple::Stoppable
Provides an interface for starting and stopping.
Definition: Stoppable.h:200
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:62
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:103
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
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:196
ripple::InfoSub::getCountedObjectName
static char const * getCountedObjectName()
Definition: InfoSub.h:44
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:81
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:193
ripple::InfoSub::getPathRequest
std::shared_ptr< PathRequest > const & getPathRequest()
Definition: InfoSub.cpp:126
ripple::Resource::Consumer
An endpoint that consumes resources.
Definition: Consumer.h:33
ripple::InfoSub::mSeq
std::uint64_t mSeq
Definition: InfoSub.h:197
ripple::InfoSub::Source::Source
Source(char const *name, Stoppable &parent)
Definition: InfoSub.cpp:38
mutex
ripple::InfoSub::getConsumer
Consumer & getConsumer()
Definition: InfoSub.cpp:75
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:120
ripple::InfoSub::onSendEmpty
void onSendEmpty()
Definition: InfoSub.cpp:87
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:45
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::InfoSub::Source::unsubLedger
virtual bool unsubLedger(std::uint64_t uListener)=0