blob: a311ecf8395add33a2fdaec0ab9b4cb213f8a1da [file] [log] [blame]
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -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
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -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 *
Zhiyi Zhang19a11d22018-04-12 22:58:20 -070019 * @author Zhiyi Zhang <zhiyi@cs.ucla.edu>
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -070020 */
21
22#ifndef GEP_GROUP_MANAGER_DB_HPP
23#define GEP_GROUP_MANAGER_DB_HPP
24
25#include "schedule.hpp"
26
27namespace ndn {
28namespace gep {
29
30/**
31 * @brief GroupManagerDB is a class to manage the database of group manager.
32 *
33 * It contains two tables to store Schedules and Members
34 */
35class GroupManagerDB
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)
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -070042 : std::runtime_error(what)
43 {
44 }
45 };
46
47public:
Yingdi Yu8c43fcc2016-03-09 18:23:57 -080048 /**
49 * @brief Create the database of group manager at path @p dbPath.
50 */
Zhiyi Zhang19a11d22018-04-12 22:58:20 -070051 explicit GroupManagerDB(const std::string& dbPath);
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -070052
53 ~GroupManagerDB();
54
55public:
56 ////////////////////////////////////////////////////// schedule management
57
58 /**
59 * @brief Check if there is a schedule with @p name
60 */
61 bool
62 hasSchedule(const std::string& name) const;
63
64 /**
65 * @brief List all the names of the schedules
66 * @return A list of the name of all schedules.
67 */
68 std::list<std::string>
69 listAllScheduleNames() const;
70
71 /**
72 * @brief Get a schedule with @p name.
73 * @throw Error if the schedule does not exist
74 */
75 Schedule
76 getSchedule(const std::string& name) const;
77
78 /**
Zhiyi Zhang84986cc2015-09-21 00:26:07 +080079 * @brief Get member key name and public key buffer of a schedule with @p name.
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -070080 */
Zhiyi Zhang84986cc2015-09-21 00:26:07 +080081 std::map<Name, Buffer>
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -070082 getScheduleMembers(const std::string& name) const;
83
84 /**
85 * @brief Add a @p schedule with @p name
86 * @pre Name.length() != 0
87 *
88 * @throw Error if add operation fails, e.g., a schedule with the same name already exists
89 */
90 void
91 addSchedule(const std::string& name, const Schedule& schedule);
92
93 /**
Yingdi Yu8c43fcc2016-03-09 18:23:57 -080094 * @brief Delete the schedule with @p name.
95 * also delete members which reference the schedule.
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -070096 */
97 void
98 deleteSchedule(const std::string& name);
99
100 /**
101 * @brief Rename a schedule with @p oldName to @p newName
102 * @pre newName.length() != 0
103 *
104 * @throw Error if update operation fails, e.g., a schedule with @p newName already exists
105 */
106 void
107 renameSchedule(const std::string& oldName, const std::string& newName);
108
109 /**
110 * @brief Update the schedule with @p name and replace the old object with @p schedule
111 *
112 * if no schedule with @p name exists, a new schedule
113 * with @p name and @p schedule will be added to database
114 */
115 void
116 updateSchedule(const std::string& name, const Schedule& schedule);
117
118 ////////////////////////////////////////////////////// member management
119
120 /**
121 * @brief Check if there is a member with name @p identity
122 */
123 bool
124 hasMember(const Name& identity) const;
125
126 /**
127 * @brief List all the members
128 */
129 std::list<Name>
130 listAllMembers() const;
131
132 /**
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -0700133 * @brief Get the schedule name of a member with name @p identity
134 *
135 * @throw Error if there is no member with name @p identity in database
136 */
137 std::string
138 getMemberSchedule(const Name& identity) const;
139
140 /**
Zhiyi Zhang84986cc2015-09-21 00:26:07 +0800141 * @brief Add a new member with @p key of @p keyName
142 * into a schedule with name @p scheduleName.
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -0700143 *
144 * @throw Error when there's no schedule named @p scheduleName
Zhiyi Zhang84986cc2015-09-21 00:26:07 +0800145 * @throw Error if add operation fails, e.g., the added member exists
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -0700146 */
147 void
Zhiyi Zhang19a11d22018-04-12 22:58:20 -0700148 addMember(const std::string& scheduleName, const Name& keyName, const Buffer& key);
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -0700149
150 /**
151 * @brief Change the schedule of a member with name @p identity to a schedule with @p scheduleName
152 *
153 * @throw Error when there's no schedule named @p scheduleName
154 */
155 void
156 updateMemberSchedule(const Name& identity, const std::string& scheduleName);
157
158 /**
159 * @brief Delete a member with name @p identity from database
160 */
161 void
162 deleteMember(const Name& identity);
163
Zhiyi Zhang67f90aa2016-10-16 14:29:15 -0700164 /**
165 * @brief Check if there is a EKey with name @p eKeyName in database
166 */
167 bool
168 hasEKey(const Name& eKeyName);
169
170 /**
171 * @brief Add a EKey with name @p eKeyName to database
172 *
173 * @p pubKey The public Key of the group key pair
174 * @p priKey The private Key of the group key pair
175 */
176 void
177 addEKey(const Name& eKeyName, const Buffer& pubKey, const Buffer& priKey);
178
179 /**
180 * @brief Get the group key pair from database
181 */
182 std::tuple<Buffer, Buffer>
183 getEKey(const Name& eKeyName);
184
185 /**
186 * @brief Delete all the EKeys in the database
187 *
188 * The database will keep growing because EKeys will keep being added. The method
189 * should be called periodically
190 */
191 void
192 cleanEKeys();
193
194 /**
195 * @brief Delete a EKey with name @p eKeyName from database
196 */
197 void
198 deleteEKey(const Name& eKeyName);
199
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -0700200private:
201 class Impl;
202 unique_ptr<Impl> m_impl;
203};
204
205} // namespace gep
206} // namespace ndn
207
208#endif // GEP_GROUP_MANAGER_DB_HPP