rippled
PathRequest.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_PATHS_PATHREQUEST_H_INCLUDED
21 #define RIPPLE_APP_PATHS_PATHREQUEST_H_INCLUDED
22 
23 #include <ripple/app/ledger/Ledger.h>
24 #include <ripple/app/paths/Pathfinder.h>
25 #include <ripple/app/paths/RippleLineCache.h>
26 #include <ripple/json/json_value.h>
27 #include <ripple/net/InfoSub.h>
28 #include <ripple/protocol/UintTypes.h>
29 #include <boost/optional.hpp>
30 #include <map>
31 #include <mutex>
32 #include <set>
33 #include <utility>
34 
35 namespace ripple {
36 
37 // A pathfinding request submitted by a client
38 // The request issuer must maintain a strong pointer
39 
40 class RippleLineCache;
41 class PathRequests;
42 
43 // Return values from parseJson <0 = invalid, >0 = valid
44 #define PFR_PJ_INVALID -1
45 #define PFR_PJ_NOCHANGE 0
46 #define PFR_PJ_CHANGE 1
47 
48 class PathRequest : public std::enable_shared_from_this<PathRequest>,
49  public CountedObject<PathRequest>
50 {
51 public:
52  static char const*
54  {
55  return "PathRequest";
56  }
57 
60  using ref = const pointer&;
61  using wref = const wptr&;
62 
63 public:
64  // VFALCO TODO Break the cyclic dependency on InfoSub
65 
66  // path_find semantics
67  // Subscriber is updated
69  Application& app,
70  std::shared_ptr<InfoSub> const& subscriber,
71  int id,
72  PathRequests&,
73  beast::Journal journal);
74 
75  // ripple_path_find semantics
76  // Completion function is called after path update is complete
78  Application& app,
79  std::function<void(void)> const& completion,
80  Resource::Consumer& consumer,
81  int id,
82  PathRequests&,
83  beast::Journal journal);
84 
85  ~PathRequest();
86 
87  bool
88  isNew();
89  bool
90  needsUpdate(bool newOnly, LedgerIndex index);
91 
92  // Called when the PathRequest update is complete.
93  void
95 
98 
100  doClose(Json::Value const&);
102  doStatus(Json::Value const&);
103 
104  // update jvStatus
106  doUpdate(std::shared_ptr<RippleLineCache> const&, bool fast);
108  getSubscriber();
109  bool
110  hasCompletion();
111 
112 private:
113  bool
115  void
116  setValid();
117 
122  Currency const&,
123  STAmount const&,
124  int const);
125 
129  bool
131 
132  int
133  parseJson(Json::Value const&);
134 
137 
139 
141 
142  std::weak_ptr<InfoSub> wpSubscriber; // Who this request came from
144  Resource::Consumer& consumer_; // Charge according to source currencies
145 
147  Json::Value jvStatus; // Last result
148 
149  // Client request parameters
150  boost::optional<AccountID> raSrcAccount;
151  boost::optional<AccountID> raDstAccount;
153  boost::optional<STAmount> saSendMax;
154 
157 
159 
163 
164  int iLevel;
166 
168 
169  std::chrono::steady_clock::time_point const created_;
170  std::chrono::steady_clock::time_point quick_reply_;
171  std::chrono::steady_clock::time_point full_reply_;
172 
173  static unsigned int const max_paths_ = 4;
174 };
175 
176 } // namespace ripple
177 
178 #endif
ripple::PathRequest::doClose
Json::Value doClose(Json::Value const &)
Definition: PathRequest.cpp:442
ripple::Application
Definition: Application.h:94
ripple::PathRequest::getCountedObjectName
static char const * getCountedObjectName()
Definition: PathRequest.h:53
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:110
std::shared_ptr
STL class.
ripple::PathRequest::mContext
std::map< Issue, STPathSet > mContext
Definition: PathRequest.h:156
utility
ripple::PathRequest::getPathFinder
std::unique_ptr< Pathfinder > const & getPathFinder(std::shared_ptr< RippleLineCache > const &, hash_map< Currency, std::unique_ptr< Pathfinder >> &, Currency const &, STAmount const &, int const)
Definition: PathRequest.cpp:459
ripple::PathRequest::mLastIndex
LedgerIndex mLastIndex
Definition: PathRequest.h:161
std::pair
ripple::PathRequest::saDstAmount
STAmount saDstAmount
Definition: PathRequest.h:152
ripple::PathRequest::raDstAccount
boost::optional< AccountID > raDstAccount
Definition: PathRequest.h:151
ripple::PathRequest::jvStatus
Json::Value jvStatus
Definition: PathRequest.h:147
ripple::PathRequest::convert_all_
bool convert_all_
Definition: PathRequest.h:158
std::recursive_mutex
STL class.
ripple::PathRequest::full_reply_
std::chrono::steady_clock::time_point full_reply_
Definition: PathRequest.h:171
ripple::PathRequest::mIndexLock
std::recursive_mutex mIndexLock
Definition: PathRequest.h:160
std::function
ripple::PathRequest::consumer_
Resource::Consumer & consumer_
Definition: PathRequest.h:144
ripple::PathRequest::fCompletion
std::function< void(void)> fCompletion
Definition: PathRequest.h:143
ripple::PathRequest::quick_reply_
std::chrono::steady_clock::time_point quick_reply_
Definition: PathRequest.h:170
ripple::base_uint< 160, detail::CurrencyTag >
ripple::PathRequest::PathRequest
PathRequest(Application &app, std::shared_ptr< InfoSub > const &subscriber, int id, PathRequests &, beast::Journal journal)
Definition: PathRequest.cpp:40
ripple::PathRequest::max_paths_
static unsigned const int max_paths_
Definition: PathRequest.h:173
ripple::PathRequest::sciSourceCurrencies
std::set< Issue > sciSourceCurrencies
Definition: PathRequest.h:155
ripple::PathRequest::~PathRequest
~PathRequest()
Definition: PathRequest.cpp:85
ripple::PathRequest::getSubscriber
InfoSub::pointer getSubscriber()
Definition: PathRequest.cpp:731
ripple::PathRequest::bLastSuccess
bool bLastSuccess
Definition: PathRequest.h:165
std::enable_shared_from_this
ripple::STAmount
Definition: STAmount.h:42
ripple::PathRequest::findPaths
bool findPaths(std::shared_ptr< RippleLineCache > const &, int const, Json::Value &)
Finds and sets a PathSet in the JSON argument.
Definition: PathRequest.cpp:486
ripple::PathRequest::app_
Application & app_
Definition: PathRequest.h:135
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
map
ripple::PathRequest::isValid
bool isValid(std::shared_ptr< RippleLineCache > const &crCache)
Definition: PathRequest.cpp:170
ripple::PathRequest::updateComplete
void updateComplete()
Definition: PathRequest.cpp:155
std::weak_ptr
STL class.
ripple::PathRequest::doCreate
std::pair< bool, Json::Value > doCreate(std::shared_ptr< RippleLineCache > const &, Json::Value const &)
Definition: PathRequest.cpp:242
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::PathRequest::mLock
std::recursive_mutex mLock
Definition: PathRequest.h:138
ripple::PathRequest::created_
const std::chrono::steady_clock::time_point created_
Definition: PathRequest.h:169
ripple::PathRequest
Definition: PathRequest.h:48
ripple::PathRequest::doUpdate
Json::Value doUpdate(std::shared_ptr< RippleLineCache > const &, bool fast)
Definition: PathRequest.cpp:629
ripple::PathRequest::wpSubscriber
std::weak_ptr< InfoSub > wpSubscriber
Definition: PathRequest.h:142
ripple::PathRequest::doStatus
Json::Value doStatus(Json::Value const &)
Definition: PathRequest.cpp:451
ripple::PathRequest::iIdentifier
int iIdentifier
Definition: PathRequest.h:167
ripple::PathRequest::isNew
bool isNew()
Definition: PathRequest.cpp:114
ripple::Resource::Consumer
An endpoint that consumes resources.
Definition: Consumer.h:33
ripple::PathRequest::setValid
void setValid()
mutex
ripple::PathRequest::saSendMax
boost::optional< STAmount > saSendMax
Definition: PathRequest.h:153
ripple::PathRequests
Definition: PathRequests.h:33
ripple::PathRequest::hasCompletion
bool hasCompletion()
Definition: PathRequest.cpp:149
ripple::PathRequest::jvId
Json::Value jvId
Definition: PathRequest.h:146
ripple::PathRequest::mOwner
PathRequests & mOwner
Definition: PathRequest.h:140
std::unique_ptr
STL class.
ripple::PathRequest::needsUpdate
bool needsUpdate(bool newOnly, LedgerIndex index)
Definition: PathRequest.cpp:123
std::unordered_map
STL class.
ripple::PathRequest::m_journal
beast::Journal m_journal
Definition: PathRequest.h:136
ripple::PathRequest::parseJson
int parseJson(Json::Value const &)
Definition: PathRequest.cpp:272
set
ripple::PathRequest::iLevel
int iLevel
Definition: PathRequest.h:164
ripple::PathRequest::mInProgress
bool mInProgress
Definition: PathRequest.h:162
ripple::PathRequest::raSrcAccount
boost::optional< AccountID > raSrcAccount
Definition: PathRequest.h:150
Json::Value
Represents a JSON value.
Definition: json_value.h:145