rippled
InfoSub.cpp
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 #include <ripple/net/InfoSub.h>
21 #include <atomic>
22 
23 namespace ripple {
24 
25 // This is the primary interface into the "client" portion of the program.
26 // Code that wants to do normal operations on the network such as
27 // creating and monitoring accounts, creating transactions, and so on
28 // should use this interface. The RPC code will primarily be a light wrapper
29 // over this code.
30 
31 // Eventually, it will check the node's operating mode (synched, unsynched,
32 // etectera) and defer to the correct means of processing. The current
33 // code assumes this node is synched (and will continue to do so until
34 // there's a functional network.
35 
36 //------------------------------------------------------------------------------
37 
38 InfoSub::Source::Source (char const* name, Stoppable& parent)
39  : Stoppable (name, parent)
40 {
41 }
42 
43 //------------------------------------------------------------------------------
44 
46  : m_source(source)
47  , mSeq(assign_id())
48 {
49 }
50 
51 InfoSub::InfoSub(Source& source, Consumer consumer)
52  : m_consumer(consumer)
53  , m_source(source)
54  , mSeq(assign_id())
55 {
56 }
57 
59 {
68 
69  // Use the internal unsubscribe so that it won't call
70  // back to us and modify its own parameter
71  if (! realTimeSubscriptions_.empty ())
74 
75  if (! normalSubscriptions_.empty ())
77  (mSeq, normalSubscriptions_, false);
78 }
79 
81 {
82  return m_consumer;
83 }
84 
86 {
87  return mSeq;
88 }
89 
91 {
92 }
93 
94 void InfoSub::insertSubAccountInfo (AccountID const& account, bool rt)
95 {
97 
98  if (rt)
99  realTimeSubscriptions_.insert (account);
100  else
101  normalSubscriptions_.insert (account);
102 }
103 
104 void InfoSub::deleteSubAccountInfo (AccountID const& account, bool rt)
105 {
106  std::lock_guard sl (mLock);
107 
108  if (rt)
109  realTimeSubscriptions_.erase (account);
110  else
111  normalSubscriptions_.erase (account);
112 }
113 
115 {
116  mPathRequest.reset ();
117 }
118 
120 {
121  mPathRequest = req;
122 }
123 
125 {
126  return mPathRequest;
127 }
128 
129 } // ripple
ripple::InfoSub::m_consumer
Consumer m_consumer
Definition: InfoSub.h:156
ripple::InfoSub::~InfoSub
virtual ~InfoSub()
Definition: InfoSub.cpp:58
std::shared_ptr
STL class.
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::unsubConsensus
virtual bool unsubConsensus(std::uint64_t uListener)=0
ripple::InfoSub::insertSubAccountInfo
void insertSubAccountInfo(AccountID const &account, bool rt)
Definition: InfoSub.cpp:94
std::lock_guard
STL class.
ripple::InfoSub::normalSubscriptions_
hash_set< AccountID > normalSubscriptions_
Definition: InfoSub.h:159
ripple::InfoSub::assign_id
static int assign_id()
Definition: InfoSub.h:165
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::mLock
std::mutex mLock
Definition: InfoSub.h:153
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
Abstracts the source of subscription data.
Definition: InfoSub.h:58
ripple::InfoSub::deleteSubAccountInfo
void deleteSubAccountInfo(AccountID const &account, bool rt)
Definition: InfoSub.cpp:104
std::uint64_t
ripple::InfoSub::Source::unsubRTTransactions
virtual bool unsubRTTransactions(std::uint64_t uListener)=0
atomic
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::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::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
ripple::InfoSub::getConsumer
Consumer & getConsumer()
Definition: InfoSub.cpp:80
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::InfoSub
InfoSub(Source &source)
Definition: InfoSub.cpp:45
ripple::InfoSub::Source::unsubLedger
virtual bool unsubLedger(std::uint64_t uListener)=0