blob: 4a10d3f88a8372cb919deed270e484755c6f9f52 [file] [log] [blame]
Prashanth Swaminathanb2105902015-08-20 14:28:54 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, Regents of the University of California
4 *
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:
41 explicit
42 Error(const std::string& what)
43 : std::runtime_error(what)
44 {
45 }
46 };
47
48public:
49 explicit
50 ProducerDB(const std::string& dbPath);
51
52 ~ProducerDB();
53
54public:
55 /**
56 * @brief Check if content key exists for the hour covering @p timeslot
57 */
58 bool
59 hasContentKey(const time::system_clock::TimePoint& timeslot) const;
60
61 /**
62 * @brief Get content key for the hour covering @p timeslot
63 * @throws Error if the key does not exist
64 */
65 Buffer
66 getContentKey(const time::system_clock::TimePoint& timeslot) const;
67
68 /**
69 * @brief Add @p key as the content key for the hour covering @p timeslot
70 * @throws Error if a key for the same hour already exists
71 */
72 void
73 addContentKey(const time::system_clock::TimePoint& timeslot, const Buffer& key);
74
75 /**
76 * @brief Delete content key for the hour covering @p timeslot
77 */
78 void
79 deleteContentKey(const time::system_clock::TimePoint& timeslot);
80
81private:
82 class Impl;
83 unique_ptr<Impl> m_impl;
84};
85
86} // namespace gep
87} // namespace ndn
88
89#endif // NDN_GEP_PRODUCER_DB_HPP