Shuo Chen | 478204c | 2014-03-18 18:27:04 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | c0e2658 | 2017-08-13 21:16:49 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | d8521aa | 2023-09-17 14:21:27 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2023, Regents of the University of California. |
Alexander Afanasyev | e1e6f2a | 2014-04-25 11:28:12 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of NDN repo-ng (Next generation of NDN repository). |
| 6 | * See AUTHORS.md for complete list of repo-ng authors and contributors. |
| 7 | * |
| 8 | * repo-ng is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Shuo Chen | 478204c | 2014-03-18 18:27:04 -0700 | [diff] [blame] | 18 | */ |
| 19 | |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 20 | #ifndef REPO_REPO_HPP |
| 21 | #define REPO_REPO_HPP |
Shuo Chen | 478204c | 2014-03-18 18:27:04 -0700 | [diff] [blame] | 22 | |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 23 | #include "storage/repo-storage.hpp" |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 24 | #include "storage/sqlite-storage.hpp" |
Shuo Chen | 478204c | 2014-03-18 18:27:04 -0700 | [diff] [blame] | 25 | |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 26 | #include "handles/delete-handle.hpp" |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 27 | #include "handles/read-handle.hpp" |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 28 | #include "handles/tcp-bulk-insert-handle.hpp" |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 29 | #include "handles/write-handle.hpp" |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 30 | |
Shuo Chen | 028dcd3 | 2014-06-21 16:36:44 +0800 | [diff] [blame] | 31 | #include "common.hpp" |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 32 | |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 33 | #include <ndn-cxx/mgmt/dispatcher.hpp> |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 34 | #include <ndn-cxx/security/key-chain.hpp> |
Alexander Afanasyev | c0e2658 | 2017-08-13 21:16:49 -0400 | [diff] [blame] | 35 | #include <ndn-cxx/security/validator-config.hpp> |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 36 | |
Shuo Chen | 478204c | 2014-03-18 18:27:04 -0700 | [diff] [blame] | 37 | #include <boost/property_tree/info_parser.hpp> |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 38 | #include <boost/property_tree/ptree.hpp> |
Shuo Chen | 478204c | 2014-03-18 18:27:04 -0700 | [diff] [blame] | 39 | |
| 40 | namespace repo { |
| 41 | |
Shuo Chen | 478204c | 2014-03-18 18:27:04 -0700 | [diff] [blame] | 42 | struct RepoConfig |
| 43 | { |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 44 | static constexpr size_t DISABLED_SUBSET_LENGTH = -1; |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 45 | |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 46 | std::string repoConfigPath; |
Shuo Chen | 478204c | 2014-03-18 18:27:04 -0700 | [diff] [blame] | 47 | std::string dbPath; |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 48 | std::vector<ndn::Name> dataPrefixes; |
Nick Gordon | 190e4dc | 2017-10-04 16:54:10 -0500 | [diff] [blame] | 49 | size_t registrationSubset = DISABLED_SUBSET_LENGTH; |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 50 | std::vector<ndn::Name> repoPrefixes; |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 51 | std::vector<std::pair<std::string, std::string>> tcpBulkInsertEndpoints; |
Shuo Chen | 6e81812 | 2015-05-04 10:40:03 +0800 | [diff] [blame] | 52 | uint64_t nMaxPackets; |
Shuo Chen | 478204c | 2014-03-18 18:27:04 -0700 | [diff] [blame] | 53 | boost::property_tree::ptree validatorNode; |
| 54 | }; |
| 55 | |
| 56 | RepoConfig |
| 57 | parseConfig(const std::string& confPath); |
| 58 | |
| 59 | class Repo : noncopyable |
| 60 | { |
Shuo Chen | 478204c | 2014-03-18 18:27:04 -0700 | [diff] [blame] | 61 | public: |
| 62 | class Error : public std::runtime_error |
| 63 | { |
| 64 | public: |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 65 | using std::runtime_error::runtime_error; |
Shuo Chen | 478204c | 2014-03-18 18:27:04 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | public: |
Davide Pesavento | d8521aa | 2023-09-17 14:21:27 -0400 | [diff] [blame^] | 69 | Repo(boost::asio::io_context& io, const RepoConfig& config); |
Shuo Chen | 478204c | 2014-03-18 18:27:04 -0700 | [diff] [blame] | 70 | |
Davide Pesavento | d8521aa | 2023-09-17 14:21:27 -0400 | [diff] [blame^] | 71 | /// @brief Rebuild index from storage file when repo starts. |
Shuo Chen | a12f528 | 2014-08-01 15:18:30 +0800 | [diff] [blame] | 72 | void |
| 73 | initializeStorage(); |
| 74 | |
Shuo Chen | 478204c | 2014-03-18 18:27:04 -0700 | [diff] [blame] | 75 | void |
| 76 | enableListening(); |
| 77 | |
Shuo Chen | 028dcd3 | 2014-06-21 16:36:44 +0800 | [diff] [blame] | 78 | void |
| 79 | enableValidation(); |
| 80 | |
Shuo Chen | 478204c | 2014-03-18 18:27:04 -0700 | [diff] [blame] | 81 | private: |
Shuo Chen | 478204c | 2014-03-18 18:27:04 -0700 | [diff] [blame] | 82 | RepoConfig m_config; |
Davide Pesavento | 9a8d7d8 | 2019-03-15 20:14:25 -0400 | [diff] [blame] | 83 | Scheduler m_scheduler; |
| 84 | Face m_face; |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 85 | ndn::mgmt::Dispatcher m_dispatcher; |
Wentao Shang | a8f3c40 | 2014-10-30 14:03:27 -0700 | [diff] [blame] | 86 | std::shared_ptr<Storage> m_store; |
Weiqi Shi | f0330d5 | 2014-07-09 10:54:27 -0700 | [diff] [blame] | 87 | RepoStorage m_storageHandle; |
Davide Pesavento | 1190406 | 2022-04-14 22:33:28 -0400 | [diff] [blame] | 88 | ndn::KeyChain m_keyChain; |
| 89 | ndn::security::ValidatorConfig m_validator; |
weijia yuan | 82cf914 | 2018-10-21 12:25:02 -0700 | [diff] [blame] | 90 | |
Shuo Chen | 478204c | 2014-03-18 18:27:04 -0700 | [diff] [blame] | 91 | ReadHandle m_readHandle; |
| 92 | WriteHandle m_writeHandle; |
| 93 | DeleteHandle m_deleteHandle; |
| 94 | TcpBulkInsertHandle m_tcpBulkInsertHandle; |
| 95 | }; |
| 96 | |
| 97 | } // namespace repo |
| 98 | |
Alexander Afanasyev | 39d9807 | 2014-05-04 12:46:29 -0700 | [diff] [blame] | 99 | #endif // REPO_REPO_HPP |