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#include <xrpl/json/json_value.h>
28#include <xrpl/protocol/UintTypes.h>
29#include <map>
30#include <mutex>
31#include <optional>
32#include <set>
33#include <utility>
34
35namespace ripple {
36
37// A pathfinding request submitted by a client
38// The request issuer must maintain a strong pointer
39
40class RippleLineCache;
41class PathRequests;
42
43// Return values from parseJson <0 = invalid, >0 = valid
44#define PFR_PJ_INVALID -1
45#define PFR_PJ_NOCHANGE 0
46
47class PathRequest final : public InfoSubRequest,
48 public std::enable_shared_from_this<PathRequest>,
49 public CountedObject<PathRequest>
50{
51public:
54 using ref = const pointer&;
55 using wref = const wptr&;
56
57public:
58 // path_find semantics
59 // Subscriber is updated
61 Application& app,
62 std::shared_ptr<InfoSub> const& subscriber,
63 int id,
65 beast::Journal journal);
66
67 // ripple_path_find semantics
68 // Completion function is called after path update is complete
70 Application& app,
71 std::function<void(void)> const& completion,
72 Resource::Consumer& consumer,
73 int id,
75 beast::Journal journal);
76
78
79 bool
80 isNew();
81 bool
82 needsUpdate(bool newOnly, LedgerIndex index);
83
84 // Called when the PathRequest update is complete.
85 void
87
90
92 doClose() override;
94 doStatus(Json::Value const&) override;
95 void
96 doAborting() const;
97
98 // update jvStatus
100 doUpdate(
102 bool fast,
103 std::function<bool(void)> const& continueCallback = {});
105 getSubscriber() const;
106 bool
108
109private:
110 bool
112
117 Currency const&,
118 STAmount const&,
119 int const,
120 std::function<bool(void)> const&);
121
125 bool
126 findPaths(
128 int const,
130 std::function<bool(void)> const&);
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
154
157
159
163
166
167 int const iIdentifier;
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
Represents a JSON value.
Definition: json_value.h:147
A generic endpoint for log messages.
Definition: Journal.h:59
Tracks the number of instances of an object.
std::optional< STAmount > saSendMax
Definition: PathRequest.h:153
std::function< void(void)> fCompletion
Definition: PathRequest.h:143
static unsigned int const max_paths_
Definition: PathRequest.h:173
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:142
Json::Value doStatus(Json::Value const &) override
std::set< Issue > sciSourceCurrencies
Definition: PathRequest.h:155
int parseJson(Json::Value const &)
bool needsUpdate(bool newOnly, LedgerIndex index)
std::recursive_mutex mLock
Definition: PathRequest.h:138
int const iIdentifier
Definition: PathRequest.h:167
std::recursive_mutex mIndexLock
Definition: PathRequest.h:160
Resource::Consumer & consumer_
Definition: PathRequest.h:144
std::optional< AccountID > raSrcAccount
Definition: PathRequest.h:150
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:140
std::chrono::steady_clock::time_point full_reply_
Definition: PathRequest.h:171
LedgerIndex mLastIndex
Definition: PathRequest.h:161
std::pair< bool, Json::Value > doCreate(std::shared_ptr< RippleLineCache > const &, Json::Value const &)
Application & app_
Definition: PathRequest.h:135
Json::Value jvStatus
Definition: PathRequest.h:147
void doAborting() const
std::chrono::steady_clock::time_point quick_reply_
Definition: PathRequest.h:170
Json::Value jvId
Definition: PathRequest.h:146
std::map< Issue, STPathSet > mContext
Definition: PathRequest.h:156
std::optional< AccountID > raDstAccount
Definition: PathRequest.h:151
std::chrono::steady_clock::time_point const created_
Definition: PathRequest.h:169
beast::Journal m_journal
Definition: PathRequest.h:136
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