rippled
CrawlShards.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2018 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/basics/RangeSet.h>
22 #include <ripple/net/RPCErr.h>
23 #include <ripple/nodestore/DatabaseShard.h>
24 #include <ripple/overlay/Overlay.h>
25 #include <ripple/protocol/ErrorCodes.h>
26 #include <ripple/protocol/jss.h>
27 #include <ripple/resource/Fees.h>
28 #include <ripple/rpc/Context.h>
29 
30 namespace ripple {
31 
45 {
46  if (context.app.config().reporting())
48 
49  if (context.role != Role::ADMIN)
50  return rpcError(rpcNO_PERMISSION);
51 
52  std::uint32_t relays{0};
53  if (auto const& jv = context.params[jss::limit])
54  {
55  if (!(jv.isUInt() || (jv.isInt() && jv.asInt() >= 0)))
56  return RPC::expected_field_error(jss::limit, "unsigned integer");
57  relays = std::min(jv.asUInt(), relayLimit);
59  }
60  else
62 
63  // Collect shard info from server and peers
64  bool const includePublicKey{
65  context.params.isMember(jss::public_key) &&
66  context.params[jss::public_key].asBool()};
67  Json::Value jvResult{
68  context.app.overlay().crawlShards(includePublicKey, relays)};
69 
70  return jvResult;
71 }
72 
73 } // namespace ripple
ripple::RPC::JsonContext
Definition: Context.h:53
ripple::rpcError
Json::Value rpcError(int iError)
Definition: RPCErr.cpp:29
ripple::Resource::feeMediumBurdenRPC
const Charge feeMediumBurdenRPC
ripple::relayLimit
static constexpr std::uint32_t relayLimit
Definition: ripple/overlay/Peer.h:36
ripple::RPC::Context::loadType
Resource::Charge & loadType
Definition: Context.h:43
ripple::RPC::Context::role
Role role
Definition: Context.h:47
ripple::rpcREPORTING_UNSUPPORTED
@ rpcREPORTING_UNSUPPORTED
Definition: ErrorCodes.h:141
ripple::RPC::expected_field_error
Json::Value expected_field_error(std::string const &name, std::string const &type)
Definition: ErrorCodes.h:328
Json::Value::asBool
bool asBool() const
Definition: json_value.cpp:619
ripple::doCrawlShards
Json::Value doCrawlShards(RPC::JsonContext &context)
RPC command that reports stored shards by nodes.
Definition: CrawlShards.cpp:44
ripple::Config::reporting
bool reporting() const
Definition: Config.h:337
ripple::Role::ADMIN
@ ADMIN
ripple::Application::config
virtual Config & config()=0
ripple::RPC::Context::app
Application & app
Definition: Context.h:42
Json::Value::isMember
bool isMember(const char *key) const
Return true if the object has a member named key.
Definition: json_value.cpp:932
std::uint32_t
std::min
T min(T... args)
ripple::Overlay::crawlShards
virtual Json::Value crawlShards(bool includePublicKey, std::uint32_t hops)=0
Returns information reported to the crawl shard RPC command.
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::rpcNO_PERMISSION
@ rpcNO_PERMISSION
Definition: ErrorCodes.h:53
ripple::Application::overlay
virtual Overlay & overlay()=0
ripple::RPC::JsonContext::params
Json::Value params
Definition: Context.h:64
ripple::Resource::feeHighBurdenRPC
const Charge feeHighBurdenRPC
Json::Value
Represents a JSON value.
Definition: json_value.h:145