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