blob: 68f339f279d4b76b32e0871e2850c6436b529e1c [file] [log] [blame]
Shuo Chen478204c2014-03-18 18:27:04 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyevc0e26582017-08-13 21:16:49 -04002/*
Davide Pesaventod8521aa2023-09-17 14:21:27 -04003 * Copyright (c) 2014-2023, Regents of the University of California.
Alexander Afanasyeve1e6f2a2014-04-25 11:28:12 -07004 *
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 Chen478204c2014-03-18 18:27:04 -070018 */
19
Alexander Afanasyev39d98072014-05-04 12:46:29 -070020#ifndef REPO_REPO_HPP
21#define REPO_REPO_HPP
Shuo Chen478204c2014-03-18 18:27:04 -070022
Weiqi Shif0330d52014-07-09 10:54:27 -070023#include "storage/repo-storage.hpp"
weijia yuan82cf9142018-10-21 12:25:02 -070024#include "storage/sqlite-storage.hpp"
Shuo Chen478204c2014-03-18 18:27:04 -070025
Alexander Afanasyev39d98072014-05-04 12:46:29 -070026#include "handles/delete-handle.hpp"
weijia yuan82cf9142018-10-21 12:25:02 -070027#include "handles/read-handle.hpp"
Alexander Afanasyev39d98072014-05-04 12:46:29 -070028#include "handles/tcp-bulk-insert-handle.hpp"
weijia yuan82cf9142018-10-21 12:25:02 -070029#include "handles/write-handle.hpp"
Alexander Afanasyev39d98072014-05-04 12:46:29 -070030
Shuo Chen028dcd32014-06-21 16:36:44 +080031#include "common.hpp"
Alexander Afanasyev39d98072014-05-04 12:46:29 -070032
weijia yuan82cf9142018-10-21 12:25:02 -070033#include <ndn-cxx/mgmt/dispatcher.hpp>
Davide Pesavento11904062022-04-14 22:33:28 -040034#include <ndn-cxx/security/key-chain.hpp>
Alexander Afanasyevc0e26582017-08-13 21:16:49 -040035#include <ndn-cxx/security/validator-config.hpp>
weijia yuan82cf9142018-10-21 12:25:02 -070036
Shuo Chen478204c2014-03-18 18:27:04 -070037#include <boost/property_tree/info_parser.hpp>
weijia yuan82cf9142018-10-21 12:25:02 -070038#include <boost/property_tree/ptree.hpp>
Shuo Chen478204c2014-03-18 18:27:04 -070039
40namespace repo {
41
Shuo Chen478204c2014-03-18 18:27:04 -070042struct RepoConfig
43{
Davide Pesavento11904062022-04-14 22:33:28 -040044 static constexpr size_t DISABLED_SUBSET_LENGTH = -1;
Nick Gordon190e4dc2017-10-04 16:54:10 -050045
Wentao Shanga8f3c402014-10-30 14:03:27 -070046 std::string repoConfigPath;
Shuo Chen478204c2014-03-18 18:27:04 -070047 std::string dbPath;
Wentao Shanga8f3c402014-10-30 14:03:27 -070048 std::vector<ndn::Name> dataPrefixes;
Nick Gordon190e4dc2017-10-04 16:54:10 -050049 size_t registrationSubset = DISABLED_SUBSET_LENGTH;
Wentao Shanga8f3c402014-10-30 14:03:27 -070050 std::vector<ndn::Name> repoPrefixes;
weijia yuan3aa8d2b2018-03-06 15:35:57 -080051 std::vector<std::pair<std::string, std::string>> tcpBulkInsertEndpoints;
Shuo Chen6e818122015-05-04 10:40:03 +080052 uint64_t nMaxPackets;
Shuo Chen478204c2014-03-18 18:27:04 -070053 boost::property_tree::ptree validatorNode;
54};
55
56RepoConfig
57parseConfig(const std::string& confPath);
58
59class Repo : noncopyable
60{
Shuo Chen478204c2014-03-18 18:27:04 -070061public:
62 class Error : public std::runtime_error
63 {
64 public:
Davide Pesavento11904062022-04-14 22:33:28 -040065 using std::runtime_error::runtime_error;
Shuo Chen478204c2014-03-18 18:27:04 -070066 };
67
68public:
Davide Pesaventod8521aa2023-09-17 14:21:27 -040069 Repo(boost::asio::io_context& io, const RepoConfig& config);
Shuo Chen478204c2014-03-18 18:27:04 -070070
Davide Pesaventod8521aa2023-09-17 14:21:27 -040071 /// @brief Rebuild index from storage file when repo starts.
Shuo Chena12f5282014-08-01 15:18:30 +080072 void
73 initializeStorage();
74
Shuo Chen478204c2014-03-18 18:27:04 -070075 void
76 enableListening();
77
Shuo Chen028dcd32014-06-21 16:36:44 +080078 void
79 enableValidation();
80
Shuo Chen478204c2014-03-18 18:27:04 -070081private:
Shuo Chen478204c2014-03-18 18:27:04 -070082 RepoConfig m_config;
Davide Pesavento9a8d7d82019-03-15 20:14:25 -040083 Scheduler m_scheduler;
84 Face m_face;
weijia yuan82cf9142018-10-21 12:25:02 -070085 ndn::mgmt::Dispatcher m_dispatcher;
Wentao Shanga8f3c402014-10-30 14:03:27 -070086 std::shared_ptr<Storage> m_store;
Weiqi Shif0330d52014-07-09 10:54:27 -070087 RepoStorage m_storageHandle;
Davide Pesavento11904062022-04-14 22:33:28 -040088 ndn::KeyChain m_keyChain;
89 ndn::security::ValidatorConfig m_validator;
weijia yuan82cf9142018-10-21 12:25:02 -070090
Shuo Chen478204c2014-03-18 18:27:04 -070091 ReadHandle m_readHandle;
92 WriteHandle m_writeHandle;
93 DeleteHandle m_deleteHandle;
94 TcpBulkInsertHandle m_tcpBulkInsertHandle;
95};
96
97} // namespace repo
98
Alexander Afanasyev39d98072014-05-04 12:46:29 -070099#endif // REPO_REPO_HPP