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 { class ShardArchiveHandler_test; }
33 namespace RPC {
34 
37  : public Stoppable
38  , public std::enable_shared_from_this <ShardArchiveHandler>
39 {
40 public:
41 
44 
45  static
46  boost::filesystem::path
47  getDownloadDirectory(Config const& config);
48 
49  static
50  pointer
51  getInstance();
52 
53  static
54  pointer
55  getInstance(Application& app, Stoppable& parent);
56 
57  static
58  pointer
59  recoverInstance(Application& app, Stoppable& parent);
60 
61  static
62  bool
63  hasInstance();
64 
65  bool
66  init();
67 
68  bool
69  initFromDB();
70 
71  ~ShardArchiveHandler() = default;
72 
73  bool
75 
77  bool
78  start();
79 
80  void
81  release();
82 
83 private:
84 
85  ShardArchiveHandler() = delete;
89 
91  Application& app,
92  Stoppable& parent,
93  bool recovery = false);
94 
95  void onStop () override;
96 
103  bool
104  add(std::uint32_t shardIndex, parsedURL&& url,
106 
107  // Begins the download and import of the next archive.
108  bool
110 
111  // Callback used by the downloader to notify completion of a download.
112  void
113  complete(boost::filesystem::path dstPath);
114 
115  // Extract a downloaded archive and import it into the shard store.
116  void
117  process(boost::filesystem::path const& dstPath);
118 
119  // Remove the archive being processed.
120  void
122 
123  void
125 
128 
129  std::mutex mutable m_;
134  boost::filesystem::path const downloadDir_;
135  boost::asio::basic_waitable_timer<std::chrono::steady_clock> timer_;
136  bool process_;
138 };
139 
140 } // RPC
141 } // ripple
142 
143 #endif
ripple::Application
Definition: Application.h:85
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:133
ripple::RPC::ShardArchiveHandler::downloadDir_
const boost::filesystem::path downloadDir_
Definition: ShardArchiveHandler.h:134
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:243
ripple::RPC::ShardArchiveHandler::add
bool add(std::uint32_t shardIndex, std::pair< parsedURL, std::string > &&url)
Definition: ShardArchiveHandler.cpp:202
ripple::parsedURL
Definition: StringUtilities.h:122
std::pair
ripple::RPC::ShardArchiveHandler::recoverInstance
static pointer recoverInstance(Application &app, Stoppable &parent)
Definition: ShardArchiveHandler.cpp:70
ripple::RPC::ShardArchiveHandler::onStop
void onStop() override
Override called when the stop notification is issued.
Definition: ShardArchiveHandler.cpp:188
ripple::RPC::ShardArchiveHandler::initFromDB
bool initFromDB()
Definition: ShardArchiveHandler.cpp:131
ripple::RPC::ShardArchiveHandler::doRelease
void doRelease(std::lock_guard< std::mutex > const &)
Definition: ShardArchiveHandler.cpp:472
std::lock_guard
STL class.
ripple::RPC::ShardArchiveHandler::timer_
boost::asio::basic_waitable_timer< std::chrono::steady_clock > timer_
Definition: ShardArchiveHandler.h:135
ripple::RPC::ShardArchiveHandler::instance_
static pointer instance_
Definition: ShardArchiveHandler.h:127
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:448
ripple::Config
Definition: Config.h:67
ripple::RPC::ShardArchiveHandler::~ShardArchiveHandler
~ShardArchiveHandler()=default
std::enable_shared_from_this
ripple::RPC::ShardArchiveHandler::sqliteDB_
std::unique_ptr< DatabaseCon > sqliteDB_
Definition: ShardArchiveHandler.h:132
ripple::RPC::ShardArchiveHandler::complete
void complete(boost::filesystem::path dstPath)
Definition: ShardArchiveHandler.cpp:346
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:60
std::uint32_t
std::map
STL class.
ripple::RPC::ShardArchiveHandler::j_
const beast::Journal j_
Definition: ShardArchiveHandler.h:131
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:137
ripple::RPC::ShardArchiveHandler::app_
Application & app_
Definition: ShardArchiveHandler.h:130
ripple::RPC::ShardArchiveHandler::hasInstance
static bool hasInstance()
Definition: ShardArchiveHandler.cpp:81
ripple::RPC::ShardArchiveHandler
Handles the download and import one or more shard archives.
Definition: ShardArchiveHandler.h:36
ripple::RPC::ShardArchiveHandler::ShardArchiveHandler
ShardArchiveHandler()=delete
std::mutex
STL class.
ripple::RPC::ShardArchiveHandler::instance_mutex_
static std::mutex instance_mutex_
Definition: ShardArchiveHandler.h:126
ripple::test::ShardArchiveHandler_test
Definition: ShardArchiveHandler_test.cpp:35
ripple::RPC::ShardArchiveHandler::m_
std::mutex m_
Definition: ShardArchiveHandler.h:129
std::unique_ptr
STL class.
ripple::RPC::ShardArchiveHandler::process_
bool process_
Definition: ShardArchiveHandler.h:136
ripple::RPC::ShardArchiveHandler::init
bool init()
Definition: ShardArchiveHandler.cpp:107
ripple::RPC::ShardArchiveHandler::getInstance
static pointer getInstance()
Definition: ShardArchiveHandler.cpp:50
ripple::RPC::ShardArchiveHandler::next
bool next(std::lock_guard< std::mutex > &l)
Definition: ShardArchiveHandler.cpp:295