rippled
Loading...
Searching...
No Matches
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 <xrpld/net/InfoSub.h>
21#include <atomic>
22
23namespace 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
36InfoSub::InfoSub(Source& source) : m_source(source), mSeq(assign_id())
37{
38}
39
41 : m_consumer(consumer), m_source(source), mSeq(assign_id())
42{
43}
44
46{
55
56 // Use the internal unsubscribe so that it won't call
57 // back to us and modify its own parameter
58 if (!realTimeSubscriptions_.empty())
60
61 if (!normalSubscriptions_.empty())
63
64 for (auto const& account : accountHistorySubscriptions_)
66}
67
70{
71 return m_consumer;
72}
73
76{
77 return mSeq;
78}
79
80void
82{
83}
84
85void
87{
89
90 if (rt)
91 realTimeSubscriptions_.insert(account);
92 else
93 normalSubscriptions_.insert(account);
94}
95
96void
98{
100
101 if (rt)
102 realTimeSubscriptions_.erase(account);
103 else
104 normalSubscriptions_.erase(account);
105}
106
107bool
109{
111 return accountHistorySubscriptions_.insert(account).second;
112}
113
114void
116{
118 accountHistorySubscriptions_.erase(account);
119}
120
121void
123{
124 request_.reset();
125}
126
127void
129{
130 request_ = req;
131}
132
135{
136 return request_;
137}
138
139void
140InfoSub::setApiVersion(unsigned int apiVersion)
141{
142 apiVersion_ = apiVersion;
143}
144
145unsigned int
147{
148 XRPL_ASSERT(
149 apiVersion_ > 0, "ripple::InfoSub::getApiVersion : valid API version");
150 return apiVersion_;
151}
152
153} // namespace ripple
Abstracts the source of subscription data.
Definition: InfoSub.h:68
virtual bool unsubValidations(std::uint64_t uListener)=0
virtual bool unsubServer(std::uint64_t uListener)=0
virtual bool unsubPeerStatus(std::uint64_t uListener)=0
virtual bool unsubConsensus(std::uint64_t uListener)=0
virtual void unsubAccountInternal(std::uint64_t uListener, hash_set< AccountID > const &vnaAccountIDs, bool realTime)=0
virtual bool unsubLedger(std::uint64_t uListener)=0
virtual bool unsubTransactions(std::uint64_t uListener)=0
virtual bool unsubManifests(std::uint64_t uListener)=0
virtual void unsubAccountHistoryInternal(std::uint64_t uListener, AccountID const &account, bool historyOnly)=0
virtual bool unsubRTTransactions(std::uint64_t uListener)=0
std::uint64_t getSeq()
Definition: InfoSub.cpp:75
Source & m_source
Definition: InfoSub.h:243
std::mutex mLock
Definition: InfoSub.h:239
hash_set< AccountID > realTimeSubscriptions_
Definition: InfoSub.h:244
unsigned int getApiVersion() const noexcept
Definition: InfoSub.cpp:146
Consumer m_consumer
Definition: InfoSub.h:242
bool insertSubAccountHistory(AccountID const &account)
Definition: InfoSub.cpp:108
hash_set< AccountID > normalSubscriptions_
Definition: InfoSub.h:245
void deleteSubAccountInfo(AccountID const &account, bool rt)
Definition: InfoSub.cpp:97
hash_set< AccountID > accountHistorySubscriptions_
Definition: InfoSub.h:248
void setApiVersion(unsigned int apiVersion)
Definition: InfoSub.cpp:140
InfoSub(Source &source)
Definition: InfoSub.cpp:36
std::shared_ptr< InfoSubRequest > const & getRequest()
Definition: InfoSub.cpp:134
void onSendEmpty()
Definition: InfoSub.cpp:81
void insertSubAccountInfo(AccountID const &account, bool rt)
Definition: InfoSub.cpp:86
void setRequest(const std::shared_ptr< InfoSubRequest > &req)
Definition: InfoSub.cpp:128
void deleteSubAccountHistory(AccountID const &account)
Definition: InfoSub.cpp:115
std::uint64_t mSeq
Definition: InfoSub.h:247
void clearRequest()
Definition: InfoSub.cpp:122
unsigned int apiVersion_
Definition: InfoSub.h:249
std::shared_ptr< InfoSubRequest > request_
Definition: InfoSub.h:246
virtual ~InfoSub()
Definition: InfoSub.cpp:45
Consumer & getConsumer()
Definition: InfoSub.cpp:69
An endpoint that consumes resources.
Definition: Consumer.h:35
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26