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