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/rpc/InfoSub.h>
27
28#include <xrpl/basics/base_uint.h>
29#include <xrpl/json/json_value.h>
30#include <xrpl/protocol/UintTypes.h>
31
32#include <map>
33#include <mutex>
34#include <optional>
35#include <set>
36
37namespace ripple {
38
39// A pathfinding request submitted by a client
40// The request issuer must maintain a strong pointer
41
42class RippleLineCache;
43class PathRequests;
44
45// Return values from parseJson <0 = invalid, >0 = valid
46#define PFR_PJ_INVALID -1
47#define PFR_PJ_NOCHANGE 0
48
49class PathRequest final : public InfoSubRequest,
50 public std::enable_shared_from_this<PathRequest>,
51 public CountedObject<PathRequest>
52{
53public:
56 using ref = pointer const&;
57 using wref = wptr const&;
58
59public:
60 // path_find semantics
61 // Subscriber is updated
63 Application& app,
64 std::shared_ptr<InfoSub> const& subscriber,
65 int id,
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,
77 beast::Journal journal);
78
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() override;
96 doStatus(Json::Value const&) override;
97 void
98 doAborting() const;
99
100 // update jvStatus
102 doUpdate(
104 bool fast,
105 std::function<bool(void)> const& continueCallback = {});
107 getSubscriber() const;
108 bool
110
111private:
112 bool
114
119 Currency const&,
120 STAmount const&,
121 int const,
122 std::function<bool(void)> const&);
123
127 bool
128 findPaths(
130 int const,
132 std::function<bool(void)> const&);
133
134 int
135 parseJson(Json::Value const&);
136
139
141
143
144 std::weak_ptr<InfoSub> wpSubscriber; // Who this request came from
146 Resource::Consumer& consumer_; // Charge according to source currencies
147
149 Json::Value jvStatus; // Last result
150
151 // Client request parameters
156
159
161
163
167
170
171 int const iIdentifier;
172
173 std::chrono::steady_clock::time_point const created_;
174 std::chrono::steady_clock::time_point quick_reply_;
175 std::chrono::steady_clock::time_point full_reply_;
176
177 static unsigned int const max_paths_ = 4;
178};
179
180} // namespace ripple
181
182#endif
Represents a JSON value.
Definition json_value.h:149
A generic endpoint for log messages.
Definition Journal.h:60
Tracks the number of instances of an object.
std::optional< STAmount > saSendMax
pointer const & ref
Definition PathRequest.h:56
std::function< void(void)> fCompletion
static unsigned int const max_paths_
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
wptr const & wref
Definition PathRequest.h:57
Json::Value doStatus(Json::Value const &) override
std::set< Issue > sciSourceCurrencies
int parseJson(Json::Value const &)
bool needsUpdate(bool newOnly, LedgerIndex index)
std::recursive_mutex mLock
std::recursive_mutex mIndexLock
Resource::Consumer & consumer_
std::optional< AccountID > raSrcAccount
InfoSub::pointer getSubscriber() const
std::optional< uint256 > domain
Json::Value doUpdate(std::shared_ptr< RippleLineCache > const &, bool fast, std::function< bool(void)> const &continueCallback={})
PathRequests & mOwner
std::chrono::steady_clock::time_point full_reply_
LedgerIndex mLastIndex
std::pair< bool, Json::Value > doCreate(std::shared_ptr< RippleLineCache > const &, Json::Value const &)
Application & app_
Json::Value jvStatus
void doAborting() const
std::chrono::steady_clock::time_point quick_reply_
std::map< Issue, STPathSet > mContext
std::optional< AccountID > raDstAccount
std::chrono::steady_clock::time_point const created_
beast::Journal m_journal
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:25