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:
54  using ref = const pointer&;
55  using wref = const wptr&;
56 
57 public:
58  // VFALCO TODO Break the cyclic dependency on InfoSub
59 
60  // path_find semantics
61  // Subscriber is updated
63  Application& app,
64  std::shared_ptr<InfoSub> const& subscriber,
65  int id,
66  PathRequests&,
67  beast::Journal journal);
68 
69  // ripple_path_find semantics
70  // Completion function is called after path update is complete
72  Application& app,
73  std::function<void(void)> const& completion,
74  Resource::Consumer& consumer,
75  int id,
76  PathRequests&,
77  beast::Journal journal);
78 
79  ~PathRequest();
80 
81  bool
82  isNew();
83  bool
84  needsUpdate(bool newOnly, LedgerIndex index);
85 
86  // Called when the PathRequest update is complete.
87  void
89 
92 
94  doClose(Json::Value const&);
96  doStatus(Json::Value const&);
97 
98  // update jvStatus
100  doUpdate(std::shared_ptr<RippleLineCache> const&, bool fast);
102  getSubscriber();
103  bool
104  hasCompletion();
105 
106 private:
107  bool
109 
114  Currency const&,
115  STAmount const&,
116  int const);
117 
121  bool
123 
124  int
125  parseJson(Json::Value const&);
126 
129 
131 
133 
134  std::weak_ptr<InfoSub> wpSubscriber; // Who this request came from
136  Resource::Consumer& consumer_; // Charge according to source currencies
137 
139  Json::Value jvStatus; // Last result
140 
141  // Client request parameters
142  boost::optional<AccountID> raSrcAccount;
143  boost::optional<AccountID> raDstAccount;
145  boost::optional<STAmount> saSendMax;
146 
149 
151 
155 
156  int iLevel;
158 
160 
161  std::chrono::steady_clock::time_point const created_;
162  std::chrono::steady_clock::time_point quick_reply_;
163  std::chrono::steady_clock::time_point full_reply_;
164 
165  static unsigned int const max_paths_ = 4;
166 };
167 
168 } // namespace ripple
169 
170 #endif
ripple::PathRequest::doClose
Json::Value doClose(Json::Value const &)
Definition: PathRequest.cpp:442
ripple::Application
Definition: Application.h:101
ripple::CountedObject
Tracks the number of instances of an object.
Definition: CountedObject.h:124
std::shared_ptr
STL class.
ripple::PathRequest::mContext
std::map< Issue, STPathSet > mContext
Definition: PathRequest.h:148
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:153
std::pair
ripple::PathRequest::saDstAmount
STAmount saDstAmount
Definition: PathRequest.h:144
ripple::PathRequest::raDstAccount
boost::optional< AccountID > raDstAccount
Definition: PathRequest.h:143
ripple::PathRequest::jvStatus
Json::Value jvStatus
Definition: PathRequest.h:139
ripple::PathRequest::convert_all_
bool convert_all_
Definition: PathRequest.h:150
std::recursive_mutex
STL class.
ripple::PathRequest::full_reply_
std::chrono::steady_clock::time_point full_reply_
Definition: PathRequest.h:163
ripple::PathRequest::mIndexLock
std::recursive_mutex mIndexLock
Definition: PathRequest.h:152
std::function
ripple::PathRequest::consumer_
Resource::Consumer & consumer_
Definition: PathRequest.h:136
ripple::PathRequest::fCompletion
std::function< void(void)> fCompletion
Definition: PathRequest.h:135
ripple::PathRequest::quick_reply_
std::chrono::steady_clock::time_point quick_reply_
Definition: PathRequest.h:162
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:165
ripple::PathRequest::sciSourceCurrencies
std::set< Issue > sciSourceCurrencies
Definition: PathRequest.h:147
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:157
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:127
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:130
ripple::PathRequest::created_
const std::chrono::steady_clock::time_point created_
Definition: PathRequest.h:161
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:134
ripple::PathRequest::doStatus
Json::Value doStatus(Json::Value const &)
Definition: PathRequest.cpp:451
ripple::PathRequest::iIdentifier
int iIdentifier
Definition: PathRequest.h:159
ripple::PathRequest::isNew
bool isNew()
Definition: PathRequest.cpp:114
ripple::Resource::Consumer
An endpoint that consumes resources.
Definition: Consumer.h:33
mutex
ripple::PathRequest::saSendMax
boost::optional< STAmount > saSendMax
Definition: PathRequest.h:145
ripple::PathRequests
Definition: PathRequests.h:33
ripple::PathRequest::hasCompletion
bool hasCompletion()
Definition: PathRequest.cpp:149
ripple::PathRequest::jvId
Json::Value jvId
Definition: PathRequest.h:138
ripple::PathRequest::mOwner
PathRequests & mOwner
Definition: PathRequest.h:132
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:128
ripple::PathRequest::parseJson
int parseJson(Json::Value const &)
Definition: PathRequest.cpp:272
set
ripple::PathRequest::iLevel
int iLevel
Definition: PathRequest.h:156
ripple::PathRequest::mInProgress
bool mInProgress
Definition: PathRequest.h:154
ripple::PathRequest::raSrcAccount
boost::optional< AccountID > raSrcAccount
Definition: PathRequest.h:142
Json::Value
Represents a JSON value.
Definition: json_value.h:145