20 #include <ripple/app/main/Application.h>
21 #include <ripple/basics/BasicConfig.h>
22 #include <ripple/net/RPCErr.h>
23 #include <ripple/nodestore/DatabaseShard.h>
24 #include <ripple/protocol/ErrorCodes.h>
25 #include <ripple/protocol/jss.h>
26 #include <ripple/rpc/Context.h>
27 #include <ripple/rpc/ShardArchiveHandler.h>
28 #include <ripple/rpc/impl/Handler.h>
30 #include <boost/algorithm/string.hpp>
63 auto preShards{shardStore->getPreShards()};
64 if (!preShards.empty())
66 std::string s{
"Download already in progress. Shard"};
67 if (!
std::all_of(preShards.begin(), preShards.end(), ::isdigit))
83 for (
auto& it : context.
params[jss::shards])
86 if (!it.isMember(jss::index))
88 auto& jv{it[jss::index]};
89 if (!(jv.isUInt() || (jv.isInt() && jv.asInt() >= 0)))
96 if (!it.isMember(jss::url))
99 auto unparsedURL = it[jss::url].asString();
111 if (archiveName.empty() || archiveName.size() <= ext.size())
115 "', invalid archive name");
117 if (!boost::iends_with(archiveName, ext))
121 "', invalid archive extension");
132 "', duplicate shard ids.");
144 rpcINTERNAL,
"Failed to create ShardArchiveHandler.");
152 for (
auto& [index, url] : archives)
154 if (!handler->
add(index, std::move(url)))
157 "Invalid field '" +
std::string(jss::index) +
"', shard id " +
163 if (!handler->
start())
170 preShards = shardStore->getPreShards();
171 if (!
std::all_of(preShards.begin(), preShards.end(), ::isdigit))
bool start()
Starts downloading and importing archives.
Json::Value doDownloadShard(RPC::JsonContext &context)
RPC command that downloads and import shard archives.
Json::Value rpcError(int iError)
bool add(std::uint32_t shardIndex, std::pair< parsedURL, std::string > &&url)
virtual NodeStore::DatabaseShard * getShardStore()=0
@ rpcREPORTING_UNSUPPORTED
Json::Value expected_field_error(std::string const &name, std::string const &type)
Json::Value missing_field_error(std::string const &name)
virtual Config & config()=0
T find_last_of(T... args)
bool parseUrl(parsedURL &pUrl, std::string const &strUrl)
UInt size() const
Number of values in array or object.
bool isMember(const char *key) const
Return true if the object has a member named key.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Handles the download and import of one or more shard archives.
Json::Value makeObjectValue(Value const &value, Json::StaticString const &field=jss::message)
Return a Json::objectValue with a single entry.
Json::Value make_param_error(std::string const &message)
Returns a new json object that indicates invalid parameters.
Json::Value invalid_field_error(std::string const &name)
Json::Value make_error(error_code_i code)
Returns a new json object that reflects the error code.
virtual RPC::ShardArchiveHandler * getShardArchiveHandler(bool tryRecovery=false)=0