rippled
Loading...
Searching...
No Matches
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 <xrpld/app/ledger/Ledger.h>
24#include <xrpld/app/paths/Pathfinder.h>
25#include <xrpld/app/paths/RippleLineCache.h>
26#include <xrpld/net/InfoSub.h>
27
28#include <xrpl/json/json_value.h>
29#include <xrpl/protocol/UintTypes.h>
30
31#include <map>
32#include <mutex>
33#include <optional>
34#include <set>
35
36namespace ripple {
37
38// A pathfinding request submitted by a client
39// The request issuer must maintain a strong pointer
40
41class RippleLineCache;
42class PathRequests;
43
44// Return values from parseJson <0 = invalid, >0 = valid
45#define PFR_PJ_INVALID -1
46#define PFR_PJ_NOCHANGE 0
47
48class PathRequest final : public InfoSubRequest,
49 public std::enable_shared_from_this<PathRequest>,
50 public CountedObject<PathRequest>
51{
52public:
55 using ref = pointer const&;
56 using wref = wptr const&;
57
58public:
59 // path_find semantics
60 // Subscriber is updated
62 Application& app,
63 std::shared_ptr<InfoSub> const& subscriber,
64 int id,
66 beast::Journal journal);
67
68 // ripple_path_find semantics
69 // Completion function is called after path update is complete
71 Application& app,
72 std::function<void(void)> const& completion,
73 Resource::Consumer& consumer,
74 int id,
76 beast::Journal journal);
77
79
80 bool
81 isNew();
82 bool
83 needsUpdate(bool newOnly, LedgerIndex index);
84
85 // Called when the PathRequest update is complete.
86 void
88
91
93 doClose() override;
95 doStatus(Json::Value const&) override;
96 void
97 doAborting() const;
98
99 // update jvStatus
101 doUpdate(
103 bool fast,
104 std::function<bool(void)> const& continueCallback = {});
106 getSubscriber() const;
107 bool
109
110private:
111 bool
113
118 Currency const&,
119 STAmount const&,
120 int const,
121 std::function<bool(void)> const&);
122
126 bool
127 findPaths(
129 int const,
131 std::function<bool(void)> const&);
132
133 int
134 parseJson(Json::Value const&);
135
138
140
142
143 std::weak_ptr<InfoSub> wpSubscriber; // Who this request came from
145 Resource::Consumer& consumer_; // Charge according to source currencies
146
148 Json::Value jvStatus; // Last result
149
150 // Client request parameters
155
158
160
164
167
168 int const iIdentifier;
169
170 std::chrono::steady_clock::time_point const created_;
171 std::chrono::steady_clock::time_point quick_reply_;
172 std::chrono::steady_clock::time_point full_reply_;
173
174 static unsigned int const max_paths_ = 4;
175};
176
177} // namespace ripple
178
179#endif
Represents a JSON value.
Definition: json_value.h:148
A generic endpoint for log messages.
Definition: Journal.h:60
Tracks the number of instances of an object.
std::optional< STAmount > saSendMax
Definition: PathRequest.h:154
pointer const & ref
Definition: PathRequest.h:55
std::function< void(void)> fCompletion
Definition: PathRequest.h:144
static unsigned int const max_paths_
Definition: PathRequest.h:174
bool findPaths(std::shared_ptr< RippleLineCache > const &, int const, Json::Value &, std::function< bool(void)> const &)
Finds and sets a PathSet in the JSON argument.
Json::Value doClose() override
std::weak_ptr< InfoSub > wpSubscriber
Definition: PathRequest.h:143
wptr const & wref
Definition: PathRequest.h:56
Json::Value doStatus(Json::Value const &) override
std::set< Issue > sciSourceCurrencies
Definition: PathRequest.h:156
int parseJson(Json::Value const &)
bool needsUpdate(bool newOnly, LedgerIndex index)
std::recursive_mutex mLock
Definition: PathRequest.h:139
int const iIdentifier
Definition: PathRequest.h:168
std::recursive_mutex mIndexLock
Definition: PathRequest.h:161
Resource::Consumer & consumer_
Definition: PathRequest.h:145
std::optional< AccountID > raSrcAccount
Definition: PathRequest.h:151
InfoSub::pointer getSubscriber() const
Json::Value doUpdate(std::shared_ptr< RippleLineCache > const &, bool fast, std::function< bool(void)> const &continueCallback={})
PathRequests & mOwner
Definition: PathRequest.h:141
std::chrono::steady_clock::time_point full_reply_
Definition: PathRequest.h:172
LedgerIndex mLastIndex
Definition: PathRequest.h:162
std::pair< bool, Json::Value > doCreate(std::shared_ptr< RippleLineCache > const &, Json::Value const &)
Application & app_
Definition: PathRequest.h:136
Json::Value jvStatus
Definition: PathRequest.h:148
void doAborting() const
std::chrono::steady_clock::time_point quick_reply_
Definition: PathRequest.h:171
Json::Value jvId
Definition: PathRequest.h:147
std::map< Issue, STPathSet > mContext
Definition: PathRequest.h:157
std::optional< AccountID > raDstAccount
Definition: PathRequest.h:152
std::chrono::steady_clock::time_point const created_
Definition: PathRequest.h:170
beast::Journal m_journal
Definition: PathRequest.h:137
std::unique_ptr< Pathfinder > const & getPathFinder(std::shared_ptr< RippleLineCache > const &, hash_map< Currency, std::unique_ptr< Pathfinder > > &, Currency const &, STAmount const &, int const, std::function< bool(void)> const &)
bool isValid(std::shared_ptr< RippleLineCache > const &crCache)
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