rippled
NetworkOPs.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_APP_MISC_NETWORKOPS_H_INCLUDED
21 #define RIPPLE_APP_MISC_NETWORKOPS_H_INCLUDED
22 
23 #include <ripple/app/consensus/RCLCxPeerPos.h>
24 #include <ripple/app/ledger/Ledger.h>
25 #include <ripple/core/JobQueue.h>
26 #include <ripple/ledger/ReadView.h>
27 #include <ripple/net/InfoSub.h>
28 #include <ripple/protocol/STValidation.h>
29 #include <ripple/protocol/messages.h>
30 #include <boost/asio.hpp>
31 #include <deque>
32 #include <memory>
33 #include <tuple>
34 
35 namespace ripple {
36 
37 // Operations that clients may wish to perform against the network
38 // Master operational handler, server sequencer, network tracker
39 
40 class Peer;
41 class LedgerMaster;
42 class Transaction;
43 class ValidatorKeys;
44 
45 // This is the primary interface into the "client" portion of the program.
46 // Code that wants to do normal operations on the network such as
47 // creating and monitoring accounts, creating transactions, and so on
48 // should use this interface. The RPC code will primarily be a light wrapper
49 // over this code.
50 //
51 // Eventually, it will check the node's operating mode (synched, unsynched,
52 // etectera) and defer to the correct means of processing. The current
53 // code assumes this node is synched (and will continue to do so until
54 // there's a functional network.
55 //
56 
66 enum class OperatingMode {
67  DISCONNECTED = 0,
68  CONNECTED = 1,
69  SYNCING = 2,
70  TRACKING = 3,
71  FULL = 4
72 };
73 
87 {
88 public:
90 
91  enum class FailHard : unsigned char { no, yes };
92  static inline FailHard
93  doFailHard(bool noMeansDont)
94  {
95  return noMeansDont ? FailHard::yes : FailHard::no;
96  }
97 
98 public:
99  ~NetworkOPs() override = default;
100 
101  virtual void
102  stop() = 0;
103 
104  //--------------------------------------------------------------------------
105  //
106  // Network information
107  //
108 
109  virtual OperatingMode
110  getOperatingMode() const = 0;
111  virtual std::string
112  strOperatingMode(OperatingMode const mode, bool const admin = false)
113  const = 0;
114  virtual std::string
115  strOperatingMode(bool const admin = false) const = 0;
116 
117  //--------------------------------------------------------------------------
118  //
119  // Transaction processing
120  //
121 
122  // must complete immediately
123  virtual void
125 
135  virtual void
137  std::shared_ptr<Transaction>& transaction,
138  bool bUnlimited,
139  bool bLocal,
140  FailHard failType) = 0;
141 
142  //--------------------------------------------------------------------------
143  //
144  // Owner functions
145  //
146 
147  virtual Json::Value
148  getOwnerInfo(
150  AccountID const& account) = 0;
151 
152  //--------------------------------------------------------------------------
153  //
154  // Book functions
155  //
156 
157  virtual void
158  getBookPage(
160  Book const& book,
161  AccountID const& uTakerID,
162  bool const bProof,
163  unsigned int iLimit,
164  Json::Value const& jvMarker,
165  Json::Value& jvResult) = 0;
166 
167  //--------------------------------------------------------------------------
168 
169  // ledger proposal/close functions
170  virtual bool
172 
173  virtual bool
176  std::string const& source) = 0;
177 
178  virtual void
179  mapComplete(std::shared_ptr<SHAMap> const& map, bool fromAcquire) = 0;
180 
181  // network state machine
182  virtual bool
183  beginConsensus(uint256 const& netLCL) = 0;
184  virtual void
185  endConsensus() = 0;
186  virtual void
187  setStandAlone() = 0;
188  virtual void
189  setStateTimer() = 0;
190 
191  virtual void
192  setNeedNetworkLedger() = 0;
193  virtual void
195  virtual bool
196  isNeedNetworkLedger() = 0;
197  virtual bool
198  isFull() = 0;
199  virtual void
200  setMode(OperatingMode om) = 0;
201  virtual bool
202  isBlocked() = 0;
203  virtual bool
204  isAmendmentBlocked() = 0;
205  virtual void
206  setAmendmentBlocked() = 0;
207  virtual bool
208  isAmendmentWarned() = 0;
209  virtual void
210  setAmendmentWarned() = 0;
211  virtual void
212  clearAmendmentWarned() = 0;
213  virtual bool
214  isUNLBlocked() = 0;
215  virtual void
216  setUNLBlocked() = 0;
217  virtual void
218  clearUNLBlocked() = 0;
219  virtual void
220  consensusViewChange() = 0;
221 
222  virtual Json::Value
223  getConsensusInfo() = 0;
224  virtual Json::Value
225  getServerInfo(bool human, bool admin, bool counters) = 0;
226  virtual void
227  clearLedgerFetch() = 0;
228  virtual Json::Value
229  getLedgerFetchInfo() = 0;
230 
237  virtual std::uint32_t
238  acceptLedger(
240  std::nullopt) = 0;
241 
242  virtual void
243  reportFeeChange() = 0;
244 
245  virtual void
246  updateLocalTx(ReadView const& newValidLedger) = 0;
247  virtual std::size_t
248  getLocalTxCount() = 0;
249 
250  //--------------------------------------------------------------------------
251  //
252  // Monitoring: publisher side
253  //
254  virtual void
255  pubLedger(std::shared_ptr<ReadView const> const& lpAccepted) = 0;
256  virtual void
258  std::shared_ptr<ReadView const> const& ledger,
259  std::shared_ptr<STTx const> const& transaction,
260  TER result) = 0;
261  virtual void
263 
264  virtual void
265  forwardValidation(Json::Value const& jvObj) = 0;
266  virtual void
267  forwardManifest(Json::Value const& jvObj) = 0;
268  virtual void
269  forwardProposedTransaction(Json::Value const& jvObj) = 0;
270  virtual void
272 
273  virtual void
274  stateAccounting(Json::Value& obj) = 0;
275 };
276 
277 //------------------------------------------------------------------------------
278 
281  Application& app,
282  NetworkOPs::clock_type& clock,
283  bool standalone,
284  std::size_t minPeerCount,
285  bool start_valid,
286  JobQueue& job_queue,
287  LedgerMaster& ledgerMaster,
288  ValidatorKeys const& validatorKeys,
289  boost::asio::io_service& io_svc,
290  beast::Journal journal,
291  beast::insight::Collector::ptr const& collector);
292 
293 } // namespace ripple
294 
295 #endif
ripple::NetworkOPs::pubLedger
virtual void pubLedger(std::shared_ptr< ReadView const > const &lpAccepted)=0
ripple::NetworkOPs
Provides server functionality for clients.
Definition: NetworkOPs.h:86
ripple::NetworkOPs::forwardProposedAccountTransaction
virtual void forwardProposedAccountTransaction(Json::Value const &jvObj)=0
ripple::RCLCxPeerPos
A peer's signed, proposed position for use in RCLConsensus.
Definition: RCLCxPeerPos.h:43
ripple::NetworkOPs::recvValidation
virtual bool recvValidation(std::shared_ptr< STValidation > const &val, std::string const &source)=0
ripple::NetworkOPs::getServerInfo
virtual Json::Value getServerInfo(bool human, bool admin, bool counters)=0
ripple::NetworkOPs::isUNLBlocked
virtual bool isUNLBlocked()=0
std::string
STL class.
std::shared_ptr
STL class.
ripple::NetworkOPs::forwardManifest
virtual void forwardManifest(Json::Value const &jvObj)=0
ripple::NetworkOPs::FailHard::no
@ no
ripple::NetworkOPs::consensusViewChange
virtual void consensusViewChange()=0
ripple::NetworkOPs::setAmendmentBlocked
virtual void setAmendmentBlocked()=0
ripple::NetworkOPs::isAmendmentWarned
virtual bool isAmendmentWarned()=0
ripple::NetworkOPs::getOperatingMode
virtual OperatingMode getOperatingMode() const =0
tuple
ripple::make_NetworkOPs
std::unique_ptr< NetworkOPs > make_NetworkOPs(Application &app, NetworkOPs::clock_type &clock, bool standalone, std::size_t minPeerCount, bool startvalid, JobQueue &job_queue, LedgerMaster &ledgerMaster, ValidatorKeys const &validatorKeys, boost::asio::io_service &io_svc, beast::Journal journal, beast::insight::Collector::ptr const &collector)
Definition: NetworkOPs.cpp:4579
ripple::NetworkOPs::~NetworkOPs
~NetworkOPs() override=default
ripple::NetworkOPs::isAmendmentBlocked
virtual bool isAmendmentBlocked()=0
ripple::NetworkOPs::pubProposedTransaction
virtual void pubProposedTransaction(std::shared_ptr< ReadView const > const &ledger, std::shared_ptr< STTx const > const &transaction, TER result)=0
ripple::NetworkOPs::mapComplete
virtual void mapComplete(std::shared_ptr< SHAMap > const &map, bool fromAcquire)=0
ripple::NetworkOPs::stateAccounting
virtual void stateAccounting(Json::Value &obj)=0
ripple::NetworkOPs::clearLedgerFetch
virtual void clearLedgerFetch()=0
ripple::OperatingMode::SYNCING
@ SYNCING
fallen slightly behind
ripple::NetworkOPs::setStandAlone
virtual void setStandAlone()=0
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:82
ripple::NetworkOPs::clearUNLBlocked
virtual void clearUNLBlocked()=0
ripple::OperatingMode::DISCONNECTED
@ DISCONNECTED
not ready to process requests
ripple::NetworkOPs::isNeedNetworkLedger
virtual bool isNeedNetworkLedger()=0
ripple::NetworkOPs::submitTransaction
virtual void submitTransaction(std::shared_ptr< STTx const > const &)=0
ripple::OperatingMode::CONNECTED
@ CONNECTED
convinced we are talking to the network
ripple::NetworkOPs::getOwnerInfo
virtual Json::Value getOwnerInfo(std::shared_ptr< ReadView const > lpLedger, AccountID const &account)=0
ripple::NetworkOPs::setAmendmentWarned
virtual void setAmendmentWarned()=0
ripple::OperatingMode::TRACKING
@ TRACKING
convinced we agree with the network
ripple::NetworkOPs::updateLocalTx
virtual void updateLocalTx(ReadView const &newValidLedger)=0
ripple::NetworkOPs::getBookPage
virtual void getBookPage(std::shared_ptr< ReadView const > &lpLedger, Book const &book, AccountID const &uTakerID, bool const bProof, unsigned int iLimit, Json::Value const &jvMarker, Json::Value &jvResult)=0
ripple::TERSubset< CanCvtToTER >
ripple::NetworkOPs::reportFeeChange
virtual void reportFeeChange()=0
ripple::NetworkOPs::pubValidation
virtual void pubValidation(std::shared_ptr< STValidation > const &val)=0
ripple::NetworkOPs::processTransaction
virtual void processTransaction(std::shared_ptr< Transaction > &transaction, bool bUnlimited, bool bLocal, FailHard failType)=0
Process transactions as they arrive from the network or which are submitted by clients.
ripple::InfoSub::Source
Abstracts the source of subscription data.
Definition: InfoSub.h:67
ripple::NetworkOPs::setStateTimer
virtual void setStateTimer()=0
ripple::NetworkOPs::getConsensusInfo
virtual Json::Value getConsensusInfo()=0
deque
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
ripple::NetworkOPs::setUNLBlocked
virtual void setUNLBlocked()=0
ripple::NetworkOPs::clearNeedNetworkLedger
virtual void clearNeedNetworkLedger()=0
ripple::NetworkOPs::getLocalTxCount
virtual std::size_t getLocalTxCount()=0
ripple::NetworkOPs::FailHard
FailHard
Definition: NetworkOPs.h:91
ripple::NetworkOPs::clock_type
beast::abstract_clock< std::chrono::steady_clock > clock_type
Definition: NetworkOPs.h:89
beast::abstract_clock< std::chrono::steady_clock >
memory
ripple::NetworkOPs::processTrustedProposal
virtual bool processTrustedProposal(RCLCxPeerPos peerPos)=0
ripple::ReadView
A view into a ledger.
Definition: ReadView.h:125
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::NetworkOPs::isBlocked
virtual bool isBlocked()=0
ripple::NetworkOPs::clearAmendmentWarned
virtual void clearAmendmentWarned()=0
ripple::NetworkOPs::acceptLedger
virtual std::uint32_t acceptLedger(std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)=0
Accepts the current transaction tree, return the new ledger's sequence.
ripple::NetworkOPs::stop
virtual void stop()=0
ripple::NetworkOPs::isFull
virtual bool isFull()=0
ripple::NetworkOPs::strOperatingMode
virtual std::string strOperatingMode(OperatingMode const mode, bool const admin=false) const =0
ripple::OperatingMode
OperatingMode
Specifies the mode under which the server believes it's operating.
Definition: NetworkOPs.h:66
ripple::NetworkOPs::setNeedNetworkLedger
virtual void setNeedNetworkLedger()=0
ripple::NetworkOPs::setMode
virtual void setMode(OperatingMode om)=0
std::optional< std::chrono::milliseconds >
ripple::NetworkOPs::FailHard::yes
@ yes
std::size_t
ripple::Book
Specifies an order book.
Definition: Book.h:33
ripple::NetworkOPs::doFailHard
static FailHard doFailHard(bool noMeansDont)
Definition: NetworkOPs.h:93
ripple::NetworkOPs::beginConsensus
virtual bool beginConsensus(uint256 const &netLCL)=0
ripple::NetworkOPs::forwardProposedTransaction
virtual void forwardProposedTransaction(Json::Value const &jvObj)=0
std::unique_ptr
STL class.
ripple::NetworkOPs::getLedgerFetchInfo
virtual Json::Value getLedgerFetchInfo()=0
ripple::NetworkOPs::endConsensus
virtual void endConsensus()=0
ripple::NetworkOPs::forwardValidation
virtual void forwardValidation(Json::Value const &jvObj)=0
Json::Value
Represents a JSON value.
Definition: json_value.h:145
ripple::OperatingMode::FULL
@ FULL
we have the ledger and can even validate