Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Lijing Wang | 9f77a8c | 2016-12-25 14:44:04 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2013-2017, Regents of the University of California. |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 5 | * This file is part of ChronoShare, a decentralized file sharing application over NDN. |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 6 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 7 | * ChronoShare is free software: you can redistribute it and/or modify it under the terms |
| 8 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 9 | * version 3 of the License, or (at your option) any later version. |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 10 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 11 | * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 14 | * |
Alexander Afanasyev | fa2f662 | 2016-12-25 12:28:00 -0800 | [diff] [blame] | 15 | * You should have received copies of the GNU General Public License along with |
| 16 | * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * See AUTHORS.md for complete list of ChronoShare authors and contributors. |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
Lijing Wang | 9f77a8c | 2016-12-25 14:44:04 -0800 | [diff] [blame^] | 21 | #ifndef CHRONOSHARE_SRC_OBJECT_MANAGER_HPP |
| 22 | #define CHRONOSHARE_SRC_OBJECT_MANAGER_HPP |
| 23 | |
| 24 | #include "core/chronoshare-common.hpp" |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 25 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 26 | #include <boost/filesystem.hpp> |
Lijing Wang | 9f77a8c | 2016-12-25 14:44:04 -0800 | [diff] [blame^] | 27 | |
| 28 | #include <ndn-cxx/face.hpp> |
| 29 | #include <ndn-cxx/security/key-chain.hpp> |
| 30 | #include <ndn-cxx/util/digest.hpp> |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 31 | |
| 32 | // everything related to managing object files |
| 33 | |
Lijing Wang | 9f77a8c | 2016-12-25 14:44:04 -0800 | [diff] [blame^] | 34 | namespace ndn { |
| 35 | namespace chronoshare { |
| 36 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 37 | class ObjectManager |
| 38 | { |
| 39 | public: |
Lijing Wang | 9f77a8c | 2016-12-25 14:44:04 -0800 | [diff] [blame^] | 40 | ObjectManager(Face& face, KeyChain& keyChain, |
| 41 | const boost::filesystem::path& folder, const std::string& appName); |
| 42 | |
| 43 | virtual |
| 44 | ~ObjectManager(); |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 45 | |
Alexander Afanasyev | 1d1cc83 | 2013-02-05 20:03:36 -0800 | [diff] [blame] | 46 | /** |
| 47 | * @brief Creates and saves local file in a local database file |
| 48 | * |
| 49 | * Format: /<appname>/file/<hash>/<devicename>/<segment> |
| 50 | */ |
Lijing Wang | 9f77a8c | 2016-12-25 14:44:04 -0800 | [diff] [blame^] | 51 | std::tuple<ConstBufferPtr /*object-db name*/, size_t /* number of segments*/> |
| 52 | localFileToObjects(const boost::filesystem::path& file, const Name& deviceName); |
Alexander Afanasyev | dbc0671 | 2013-01-08 18:30:28 -0800 | [diff] [blame] | 53 | |
| 54 | bool |
Lijing Wang | 9f77a8c | 2016-12-25 14:44:04 -0800 | [diff] [blame^] | 55 | objectsToLocalFile(/*in*/ const Name& deviceName, /*in*/ const Buffer& hash, |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 56 | /*out*/ const boost::filesystem::path& file); |
Alexander Afanasyev | a35756b | 2013-01-22 16:59:11 -0800 | [diff] [blame] | 57 | |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 58 | private: |
Lijing Wang | 9f77a8c | 2016-12-25 14:44:04 -0800 | [diff] [blame^] | 59 | Face& m_face; |
| 60 | KeyChain& m_keyChain; |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 61 | boost::filesystem::path m_folder; |
Alexander Afanasyev | 1d1cc83 | 2013-02-05 20:03:36 -0800 | [diff] [blame] | 62 | std::string m_appName; |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 63 | }; |
| 64 | |
Lijing Wang | 9f77a8c | 2016-12-25 14:44:04 -0800 | [diff] [blame^] | 65 | typedef shared_ptr<ObjectManager> ObjectManagerPtr; |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 66 | |
Lijing Wang | 9f77a8c | 2016-12-25 14:44:04 -0800 | [diff] [blame^] | 67 | namespace error { |
Alexander Afanasyev | eda3b7a | 2016-12-25 11:26:40 -0800 | [diff] [blame] | 68 | struct ObjectManager : virtual boost::exception, virtual std::exception |
| 69 | { |
| 70 | }; |
Lijing Wang | 9f77a8c | 2016-12-25 14:44:04 -0800 | [diff] [blame^] | 71 | } // namespace error |
Alexander Afanasyev | 68f2a95 | 2013-01-08 14:34:16 -0800 | [diff] [blame] | 72 | |
Lijing Wang | 9f77a8c | 2016-12-25 14:44:04 -0800 | [diff] [blame^] | 73 | } // namespace chronoshare |
| 74 | } // namespace ndn |
| 75 | |
| 76 | #endif // CHRONOSHARE_SRC_OBJECT_MANAGER_HPP |