rippled
PathRequests.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_PATHREQUESTS_H_INCLUDED
21 #define RIPPLE_APP_PATHS_PATHREQUESTS_H_INCLUDED
22 
23 #include <ripple/app/main/Application.h>
24 #include <ripple/app/paths/PathRequest.h>
25 #include <ripple/app/paths/RippleLineCache.h>
26 #include <ripple/core/Job.h>
27 #include <atomic>
28 #include <mutex>
29 #include <vector>
30 
31 namespace ripple {
32 
34 {
35 public:
38  Application& app,
39  beast::Journal journal,
40  beast::insight::Collector::ptr const& collector)
41  : app_(app), mJournal(journal), mLastIdentifier(0)
42  {
43  mFast = collector->make_event("pathfind_fast");
44  mFull = collector->make_event("pathfind_full");
45  }
46 
51  void
53 
54  bool
55  requestsPending() const;
56 
59  std::shared_ptr<ReadView const> const& ledger,
60  bool authoritative);
61 
62  // Create a new-style path request that pushes
63  // updates to a subscriber
66  std::shared_ptr<InfoSub> const& subscriber,
67  std::shared_ptr<ReadView const> const& ledger,
68  Json::Value const& request);
69 
70  // Create an old-style path request that is
71  // managed by a coroutine and updated by
72  // the path engine
76  std::function<void(void)> completion,
77  Resource::Consumer& consumer,
78  std::shared_ptr<ReadView const> const& inLedger,
79  Json::Value const& request);
80 
81  // Execute an old-style path request immediately
82  // with the ledger specified by the caller
85  Resource::Consumer& consumer,
86  std::shared_ptr<ReadView const> const& inLedger,
87  Json::Value const& request);
88 
89  void
91  {
92  mFast.notify(ms);
93  }
94 
95  void
97  {
98  mFull.notify(ms);
99  }
100 
101 private:
102  void
104 
107 
110 
111  // Track all requests
113 
114  // Use a RippleLineCache
116 
118 
120 };
121 
122 } // namespace ripple
123 
124 #endif
ripple::Application
Definition: Application.h:115
ripple::PathRequests::doLegacyPathRequest
Json::Value doLegacyPathRequest(Resource::Consumer &consumer, std::shared_ptr< ReadView const > const &inLedger, Json::Value const &request)
Definition: PathRequests.cpp:300
ripple::PathRequests::PathRequests
PathRequests(Application &app, beast::Journal journal, beast::insight::Collector::ptr const &collector)
A collection of all PathRequest instances.
Definition: PathRequests.h:37
std::shared_ptr< Collector >
ripple::PathRequests::makePathRequest
Json::Value makePathRequest(std::shared_ptr< InfoSub > const &subscriber, std::shared_ptr< ReadView const > const &ledger, Json::Value const &request)
Definition: PathRequests.cpp:245
ripple::PathRequests::mFast
beast::insight::Event mFast
Definition: PathRequests.h:108
vector
std::chrono::milliseconds
ripple::PathRequests::makeLegacyPathRequest
Json::Value makeLegacyPathRequest(PathRequest::pointer &req, std::function< void(void)> completion, Resource::Consumer &consumer, std::shared_ptr< ReadView const > const &inLedger, Json::Value const &request)
Definition: PathRequests.cpp:267
std::recursive_mutex
STL class.
std::function
ripple::PathRequests::requestsPending
bool requestsPending() const
Definition: PathRequests.cpp:219
ripple::PathRequests::mLastIdentifier
std::atomic< int > mLastIdentifier
Definition: PathRequests.h:117
ripple::PathRequests::app_
Application & app_
Definition: PathRequests.h:105
ripple::PathRequests::insertPathRequest
void insertPathRequest(PathRequest::pointer const &)
Definition: PathRequests.cpp:226
ripple::PathRequests::getLineCache
std::shared_ptr< RippleLineCache > getLineCache(std::shared_ptr< ReadView const > const &ledger, bool authoritative)
Get the current RippleLineCache, updating it if necessary.
Definition: PathRequests.cpp:37
beast::insight::Event
A metric for reporting event timing.
Definition: Event.h:40
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::PathRequests::mJournal
beast::Journal mJournal
Definition: PathRequests.h:106
ripple::PathRequests::mFull
beast::insight::Event mFull
Definition: PathRequests.h:109
atomic
ripple::PathRequests::mLock
std::recursive_mutex mLock
Definition: PathRequests.h:119
ripple::PathRequests::lineCache_
std::weak_ptr< RippleLineCache > lineCache_
Definition: PathRequests.h:115
std::weak_ptr
STL class.
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::PathRequests::reportFast
void reportFast(std::chrono::milliseconds ms)
Definition: PathRequests.h:90
ripple::Resource::Consumer
An endpoint that consumes resources.
Definition: Consumer.h:34
ripple::PathRequests::reportFull
void reportFull(std::chrono::milliseconds ms)
Definition: PathRequests.h:96
ripple::PathRequests::updateAll
void updateAll(std::shared_ptr< ReadView const > const &ledger)
Update all of the contained PathRequest instances.
Definition: PathRequests.cpp:68
mutex
ripple::PathRequests
Definition: PathRequests.h:33
ripple::PathRequests::requests_
std::vector< PathRequest::wptr > requests_
Definition: PathRequests.h:112
Json::Value
Represents a JSON value.
Definition: json_value.h:145
beast::insight::Event::notify
void notify(std::chrono::duration< Rep, Period > const &value) const
Push an event notification.
Definition: Event.h:64