blob: a8469016df2c65804e082ae3b7046ee88a486ac3 [file] [log] [blame]
Prashanth Swaminathanb2105902015-08-20 14:28:54 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhang19a11d22018-04-12 22:58:20 -07003 * Copyright (c) 2014-2018, Regents of the University of California
Prashanth Swaminathanb2105902015-08-20 14:28:54 -07004 *
5 * This file is part of ndn-group-encrypt (Group-based Encryption Protocol for NDN).
6 * See AUTHORS.md for complete list of ndn-group-encrypt authors and contributors.
7 *
8 * ndn-group-encrypt 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 * ndn-group-encrypt 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 * ndn-group-encrypt, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @author Prashanth Swaminathan <prashanthsw@gmail.com>
20 */
21
22#ifndef NDN_GEP_PRODUCER_DB_HPP
23#define NDN_GEP_PRODUCER_DB_HPP
24
25#include "common.hpp"
26
27namespace ndn {
28namespace gep {
29
30/**
31 * @brief ProducerDB is a class to manage the database of data producer.
32 * It contains one table that maps timeslots (to the nearest hour) to the
33 * content key created for that timeslot.
34 */
35class ProducerDB
36{
37public:
38 class Error : public std::runtime_error
39 {
40 public:
Zhiyi Zhang19a11d22018-04-12 22:58:20 -070041 explicit Error(const std::string& what)
Prashanth Swaminathanb2105902015-08-20 14:28:54 -070042 : std::runtime_error(what)
43 {
44 }
45 };
46
47public:
Zhiyi Zhang19a11d22018-04-12 22:58:20 -070048 explicit ProducerDB(const std::string& dbPath);
Prashanth Swaminathanb2105902015-08-20 14:28:54 -070049
50 ~ProducerDB();
51
52public:
53 /**
54 * @brief Check if content key exists for the hour covering @p timeslot
55 */
56 bool
57 hasContentKey(const time::system_clock::TimePoint& timeslot) const;
58
59 /**
60 * @brief Get content key for the hour covering @p timeslot
61 * @throws Error if the key does not exist
62 */
63 Buffer
64 getContentKey(const time::system_clock::TimePoint& timeslot) const;
65
66 /**
67 * @brief Add @p key as the content key for the hour covering @p timeslot
68 * @throws Error if a key for the same hour already exists
69 */
70 void
71 addContentKey(const time::system_clock::TimePoint& timeslot, const Buffer& key);
72
73 /**
74 * @brief Delete content key for the hour covering @p timeslot
75 */
76 void
77 deleteContentKey(const time::system_clock::TimePoint& timeslot);
78
79private:
80 class Impl;
81 unique_ptr<Impl> m_impl;
82};
83
84} // namespace gep
85} // namespace ndn
86
87#endif // NDN_GEP_PRODUCER_DB_HPP