blob: ef506a7ce93927304b3b991659dea344a9e0e7f3 [file] [log] [blame]
Shuo Chen478204c2014-03-18 18:27:04 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi047a6fb2017-06-08 16:16:05 +00003 * Copyright (c) 2014-2017, 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"
24#include "storage/sqlite-storage.hpp"
25#include "storage/repo-storage.hpp"
Shuo Chen478204c2014-03-18 18:27:04 -070026
Alexander Afanasyev39d98072014-05-04 12:46:29 -070027#include "handles/read-handle.hpp"
28#include "handles/write-handle.hpp"
Weiqi Shi098f91c2014-07-23 17:41:35 -070029#include "handles/watch-handle.hpp"
Alexander Afanasyev39d98072014-05-04 12:46:29 -070030#include "handles/delete-handle.hpp"
31#include "handles/tcp-bulk-insert-handle.hpp"
32
Shuo Chen028dcd32014-06-21 16:36:44 +080033#include "common.hpp"
Alexander Afanasyev39d98072014-05-04 12:46:29 -070034
Junxiao Shi047a6fb2017-06-08 16:16:05 +000035#include <ndn-cxx/security/validator-null.hpp>
Shuo Chen478204c2014-03-18 18:27:04 -070036#include <boost/property_tree/ptree.hpp>
37#include <boost/property_tree/info_parser.hpp>
38
39namespace repo {
40
Shuo Chen478204c2014-03-18 18:27:04 -070041struct RepoConfig
42{
Wentao Shanga8f3c402014-10-30 14:03:27 -070043 std::string repoConfigPath;
Shuo Chen478204c2014-03-18 18:27:04 -070044 //StorageMethod storageMethod; This will be implemtented if there is other method.
45 std::string dbPath;
Wentao Shanga8f3c402014-10-30 14:03:27 -070046 std::vector<ndn::Name> dataPrefixes;
47 std::vector<ndn::Name> repoPrefixes;
48 std::vector<std::pair<std::string, std::string> > tcpBulkInsertEndpoints;
Shuo Chen6e818122015-05-04 10:40:03 +080049 uint64_t nMaxPackets;
Shuo Chen478204c2014-03-18 18:27:04 -070050 boost::property_tree::ptree validatorNode;
51};
52
53RepoConfig
54parseConfig(const std::string& confPath);
55
56class Repo : noncopyable
57{
Shuo Chen478204c2014-03-18 18:27:04 -070058public:
59 class Error : public std::runtime_error
60 {
61 public:
62 explicit
63 Error(const std::string& what)
64 : std::runtime_error(what)
65 {
66 }
67 };
68
69public:
70 Repo(boost::asio::io_service& ioService, const RepoConfig& config);
71
Shuo Chena12f5282014-08-01 15:18:30 +080072 //@brief rebuild index from storage file when repo starts.
73 void
74 initializeStorage();
75
Shuo Chen478204c2014-03-18 18:27:04 -070076 void
77 enableListening();
78
Shuo Chen028dcd32014-06-21 16:36:44 +080079 void
80 enableValidation();
81
Shuo Chen478204c2014-03-18 18:27:04 -070082private:
Shuo Chen478204c2014-03-18 18:27:04 -070083 RepoConfig m_config;
84 ndn::Scheduler m_scheduler;
85 ndn::Face m_face;
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;
Shuo Chen478204c2014-03-18 18:27:04 -070088 KeyChain m_keyChain;
Junxiao Shi047a6fb2017-06-08 16:16:05 +000089 ndn::ValidatorNull m_validator;
Shuo Chen478204c2014-03-18 18:27:04 -070090 ReadHandle m_readHandle;
91 WriteHandle m_writeHandle;
Weiqi Shi098f91c2014-07-23 17:41:35 -070092 WatchHandle m_watchHandle;
Shuo Chen478204c2014-03-18 18:27:04 -070093 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