rippled
ShardArchiveHandler.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_RPC_SHARDARCHIVEHANDLER_H_INCLUDED
21 #define RIPPLE_RPC_SHARDARCHIVEHANDLER_H_INCLUDED
22 
23 #include <ripple/app/main/Application.h>
24 #include <ripple/basics/BasicConfig.h>
25 #include <ripple/basics/StringUtilities.h>
26 #include <ripple/net/DatabaseDownloader.h>
27 
28 #include <boost/asio/basic_waitable_timer.hpp>
29 #include <boost/filesystem.hpp>
30 
31 namespace ripple {
32 namespace test {
33 class ShardArchiveHandler_test;
34 }
35 namespace RPC {
36 
39  : public Stoppable,
40  public std::enable_shared_from_this<ShardArchiveHandler>
41 {
42 public:
45 
46  static boost::filesystem::path
47  getDownloadDirectory(Config const& config);
48 
49  static pointer
50  getInstance();
51 
52  static pointer
53  getInstance(Application& app, Stoppable& parent);
54 
55  static pointer
56  recoverInstance(Application& app, Stoppable& parent);
57 
58  static bool
59  hasInstance();
60 
61  bool
62  init();
63 
64  bool
65  initFromDB();
66 
67  ~ShardArchiveHandler() = default;
68 
69  bool
71 
73  bool
74  start();
75 
76  void
77  release();
78 
79 private:
80  ShardArchiveHandler() = delete;
83  operator=(ShardArchiveHandler&&) = delete;
85  operator=(ShardArchiveHandler const&) = delete;
86 
88  Application& app,
89  Stoppable& parent,
90  bool recovery = false);
91 
92  void
93  onStop() override;
94 
101  bool
102  add(std::uint32_t shardIndex,
103  parsedURL&& url,
105 
106  // Begins the download and import of the next archive.
107  bool
109 
110  // Callback used by the downloader to notify completion of a download.
111  void
112  complete(boost::filesystem::path dstPath);
113 
114  // Extract a downloaded archive and import it into the shard store.
115  void
116  process(boost::filesystem::path const& dstPath);
117 
118  // Remove the archive being processed.
119  void
121 
122  void
124 
127 
128  std::mutex mutable m_;
133  boost::filesystem::path const downloadDir_;
134  boost::asio::basic_waitable_timer<std::chrono::steady_clock> timer_;
135  bool process_;
137 };
138 
139 } // namespace RPC
140 } // namespace ripple
141 
142 #endif
ripple::Application
Definition: Application.h:94
ripple::RPC::ShardArchiveHandler::getDownloadDirectory
static boost::filesystem::path getDownloadDirectory(Config const &config)
Definition: ShardArchiveHandler.cpp:41
ripple::RPC::ShardArchiveHandler::downloader_
std::shared_ptr< DatabaseDownloader > downloader_
Definition: ShardArchiveHandler.h:132
ripple::RPC::ShardArchiveHandler::downloadDir_
const boost::filesystem::path downloadDir_
Definition: ShardArchiveHandler.h:133
ripple::RPC::ShardArchiveHandler::operator=
ShardArchiveHandler & operator=(ShardArchiveHandler &&)=delete
std::shared_ptr
STL class.
ripple::RPC::ShardArchiveHandler::start
bool start()
Starts downloading and importing archives.
Definition: ShardArchiveHandler.cpp:247
ripple::RPC::ShardArchiveHandler::add
bool add(std::uint32_t shardIndex, std::pair< parsedURL, std::string > &&url)
Definition: ShardArchiveHandler.cpp:205
ripple::parsedURL
Definition: StringUtilities.h:123
std::pair
ripple::RPC::ShardArchiveHandler::recoverInstance
static pointer recoverInstance(Application &app, Stoppable &parent)
Definition: ShardArchiveHandler.cpp:71
ripple::RPC::ShardArchiveHandler::onStop
void onStop() override
Override called when the stop notification is issued.
Definition: ShardArchiveHandler.cpp:191
ripple::RPC::ShardArchiveHandler::initFromDB
bool initFromDB()
Definition: ShardArchiveHandler.cpp:133
ripple::RPC::ShardArchiveHandler::doRelease
void doRelease(std::lock_guard< std::mutex > const &)
Definition: ShardArchiveHandler.cpp:467
std::lock_guard
STL class.
ripple::RPC::ShardArchiveHandler::timer_
boost::asio::basic_waitable_timer< std::chrono::steady_clock > timer_
Definition: ShardArchiveHandler.h:134
ripple::RPC::ShardArchiveHandler::instance_
static pointer instance_
Definition: ShardArchiveHandler.h:126
ripple::Stoppable
Provides an interface for starting and stopping.
Definition: Stoppable.h:200
ripple::RPC::ShardArchiveHandler::release
void release()
Definition: ShardArchiveHandler.cpp:288
ripple::RPC::ShardArchiveHandler::process
void process(boost::filesystem::path const &dstPath)
Definition: ShardArchiveHandler.cpp:405
ripple::RPC::ShardArchiveHandler::remove
void remove(std::lock_guard< std::mutex > &)
Definition: ShardArchiveHandler.cpp:444
ripple::Config
Definition: Config.h:66
ripple::RPC::ShardArchiveHandler::~ShardArchiveHandler
~ShardArchiveHandler()=default
std::enable_shared_from_this
ripple::RPC::ShardArchiveHandler::sqliteDB_
std::unique_ptr< DatabaseCon > sqliteDB_
Definition: ShardArchiveHandler.h:131
ripple::RPC::ShardArchiveHandler::complete
void complete(boost::filesystem::path dstPath)
Definition: ShardArchiveHandler.cpp:347
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
std::map
STL class.
ripple::RPC::ShardArchiveHandler::j_
const beast::Journal j_
Definition: ShardArchiveHandler.h:130
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::RPC::ShardArchiveHandler::archives_
std::map< std::uint32_t, parsedURL > archives_
Definition: ShardArchiveHandler.h:136
ripple::RPC::ShardArchiveHandler::app_
Application & app_
Definition: ShardArchiveHandler.h:129
ripple::RPC::ShardArchiveHandler::hasInstance
static bool hasInstance()
Definition: ShardArchiveHandler.cpp:83
ripple::RPC::ShardArchiveHandler
Handles the download and import one or more shard archives.
Definition: ShardArchiveHandler.h:38
ripple::RPC::ShardArchiveHandler::ShardArchiveHandler
ShardArchiveHandler()=delete
std::mutex
STL class.
ripple::RPC::ShardArchiveHandler::instance_mutex_
static std::mutex instance_mutex_
Definition: ShardArchiveHandler.h:125
ripple::test::ShardArchiveHandler_test
Definition: ShardArchiveHandler_test.cpp:35
ripple::RPC::ShardArchiveHandler::m_
std::mutex m_
Definition: ShardArchiveHandler.h:128
std::unique_ptr
STL class.
ripple::RPC::ShardArchiveHandler::process_
bool process_
Definition: ShardArchiveHandler.h:135
ripple::RPC::ShardArchiveHandler::init
bool init()
Definition: ShardArchiveHandler.cpp:109
ripple::RPC::ShardArchiveHandler::getInstance
static pointer getInstance()
Definition: ShardArchiveHandler.cpp:52
ripple::RPC::ShardArchiveHandler::next
bool next(std::lock_guard< std::mutex > &l)
Definition: ShardArchiveHandler.cpp:295