rippled
LegacyPathFind.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012-2014 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 #include <ripple/app/main/Application.h>
21 #include <ripple/app/misc/LoadFeeTrack.h>
22 #include <ripple/core/Job.h>
23 #include <ripple/core/JobQueue.h>
24 #include <ripple/rpc/impl/LegacyPathFind.h>
25 #include <ripple/rpc/impl/Tuning.h>
26 
27 namespace ripple {
28 namespace RPC {
29 
31 {
32  if (isAdmin)
33  {
34  ++inProgress;
35  m_isOk = true;
36  return;
37  }
38 
39  auto const& jobCount = app.getJobQueue().getJobCountGE(jtCLIENT);
40  if (jobCount > Tuning::maxPathfindJobCount ||
41  app.getFeeTrack().isLoadedLocal())
42  return;
43 
44  while (true)
45  {
46  int prevVal = inProgress.load();
47  if (prevVal >= Tuning::maxPathfindsInProgress)
48  return;
49 
51  prevVal,
52  prevVal + 1,
53  std::memory_order_release,
54  std::memory_order_relaxed))
55  {
56  m_isOk = true;
57  return;
58  }
59  }
60 }
61 
63 {
64  if (m_isOk)
65  --inProgress;
66 }
67 
69 
70 } // namespace RPC
71 } // namespace ripple
ripple::isAdmin
bool isAdmin(Port const &port, Json::Value const &params, beast::IP::Address const &remoteIp)
Definition: Role.cpp:84
ripple::RPC::LegacyPathFind::LegacyPathFind
LegacyPathFind(bool isAdmin, Application &app)
Definition: LegacyPathFind.cpp:30
ripple::Application
Definition: Application.h:115
ripple::jtCLIENT
@ jtCLIENT
Definition: Job.h:45
ripple::RPC::LegacyPathFind::inProgress
static std::atomic< int > inProgress
Definition: LegacyPathFind.h:44
std::atomic::compare_exchange_strong
T compare_exchange_strong(T... args)
ripple::RPC::LegacyPathFind::~LegacyPathFind
~LegacyPathFind()
Definition: LegacyPathFind.cpp:62
ripple::Application::getFeeTrack
virtual LoadFeeTrack & getFeeTrack()=0
ripple::LoadFeeTrack::isLoadedLocal
bool isLoadedLocal() const
Definition: LoadFeeTrack.h:126
std::atomic::load
T load(T... args)
ripple::RPC::LegacyPathFind::m_isOk
bool m_isOk
Definition: LegacyPathFind.h:46
ripple::RPC::Tuning::maxPathfindJobCount
static constexpr int maxPathfindJobCount
Definition: rpc/impl/Tuning.h:63
ripple::Application::getJobQueue
virtual JobQueue & getJobQueue()=0
std::atomic< int >
ripple::JobQueue::getJobCountGE
int getJobCountGE(JobType t) const
All waiting jobs at or greater than this priority.
Definition: JobQueue.cpp:148
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::RPC::Tuning::maxPathfindsInProgress
static constexpr int maxPathfindsInProgress
Definition: rpc/impl/Tuning.h:62