blob: 59c0e66eb263610333204ed0eb8dcd9fad730a86 [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 *
Alexander Afanasyev9091d832018-04-18 17:21:08 -04005 * This file is part of NAC (Name-Based Access Control for NDN).
6 * See AUTHORS.md for complete list of NAC authors and contributors.
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -07007 *
Alexander Afanasyev9091d832018-04-18 17:21:08 -04008 * NAC is free software: you can redistribute it and/or modify it under the terms
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -07009 * 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 *
Alexander Afanasyev9091d832018-04-18 17:21:08 -040012 * NAC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -070013 * 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
Alexander Afanasyev9091d832018-04-18 17:21:08 -040017 * NAC, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -070018 *
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 {
Alexander Afanasyev9091d832018-04-18 17:21:08 -040028namespace nac {
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -070029
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:
Alexander Afanasyev9091d832018-04-18 17:21:08 -040041 using std::runtime_error::runtime_error;
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -070042 };
43
44public:
Yingdi Yu8c43fcc2016-03-09 18:23:57 -080045 /**
46 * @brief Create the database of group manager at path @p dbPath.
47 */
Alexander Afanasyev9091d832018-04-18 17:21:08 -040048 explicit
49 GroupManagerDB(const std::string& dbPath);
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -070050
51 ~GroupManagerDB();
52
53public:
54 ////////////////////////////////////////////////////// schedule management
55
56 /**
57 * @brief Check if there is a schedule with @p name
58 */
59 bool
60 hasSchedule(const std::string& name) const;
61
62 /**
63 * @brief List all the names of the schedules
64 * @return A list of the name of all schedules.
65 */
66 std::list<std::string>
67 listAllScheduleNames() const;
68
69 /**
70 * @brief Get a schedule with @p name.
71 * @throw Error if the schedule does not exist
72 */
73 Schedule
74 getSchedule(const std::string& name) const;
75
76 /**
Zhiyi Zhang84986cc2015-09-21 00:26:07 +080077 * @brief Get member key name and public key buffer of a schedule with @p name.
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -070078 */
Zhiyi Zhang84986cc2015-09-21 00:26:07 +080079 std::map<Name, Buffer>
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -070080 getScheduleMembers(const std::string& name) const;
81
82 /**
83 * @brief Add a @p schedule with @p name
84 * @pre Name.length() != 0
85 *
86 * @throw Error if add operation fails, e.g., a schedule with the same name already exists
87 */
88 void
89 addSchedule(const std::string& name, const Schedule& schedule);
90
91 /**
Yingdi Yu8c43fcc2016-03-09 18:23:57 -080092 * @brief Delete the schedule with @p name.
93 * also delete members which reference the schedule.
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -070094 */
95 void
96 deleteSchedule(const std::string& name);
97
98 /**
99 * @brief Rename a schedule with @p oldName to @p newName
100 * @pre newName.length() != 0
101 *
102 * @throw Error if update operation fails, e.g., a schedule with @p newName already exists
103 */
104 void
105 renameSchedule(const std::string& oldName, const std::string& newName);
106
107 /**
108 * @brief Update the schedule with @p name and replace the old object with @p schedule
109 *
110 * if no schedule with @p name exists, a new schedule
111 * with @p name and @p schedule will be added to database
112 */
113 void
114 updateSchedule(const std::string& name, const Schedule& schedule);
115
116 ////////////////////////////////////////////////////// member management
117
118 /**
119 * @brief Check if there is a member with name @p identity
120 */
121 bool
122 hasMember(const Name& identity) const;
123
124 /**
125 * @brief List all the members
126 */
127 std::list<Name>
128 listAllMembers() const;
129
130 /**
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -0700131 * @brief Get the schedule name of a member with name @p identity
132 *
133 * @throw Error if there is no member with name @p identity in database
134 */
135 std::string
136 getMemberSchedule(const Name& identity) const;
137
138 /**
Zhiyi Zhang84986cc2015-09-21 00:26:07 +0800139 * @brief Add a new member with @p key of @p keyName
140 * into a schedule with name @p scheduleName.
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -0700141 *
142 * @throw Error when there's no schedule named @p scheduleName
Zhiyi Zhang84986cc2015-09-21 00:26:07 +0800143 * @throw Error if add operation fails, e.g., the added member exists
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -0700144 */
145 void
Zhiyi Zhang19a11d22018-04-12 22:58:20 -0700146 addMember(const std::string& scheduleName, const Name& keyName, const Buffer& key);
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -0700147
148 /**
149 * @brief Change the schedule of a member with name @p identity to a schedule with @p scheduleName
150 *
151 * @throw Error when there's no schedule named @p scheduleName
152 */
153 void
154 updateMemberSchedule(const Name& identity, const std::string& scheduleName);
155
156 /**
157 * @brief Delete a member with name @p identity from database
158 */
159 void
160 deleteMember(const Name& identity);
161
Zhiyi Zhang67f90aa2016-10-16 14:29:15 -0700162 /**
163 * @brief Check if there is a EKey with name @p eKeyName in database
164 */
165 bool
166 hasEKey(const Name& eKeyName);
167
168 /**
169 * @brief Add a EKey with name @p eKeyName to database
170 *
171 * @p pubKey The public Key of the group key pair
172 * @p priKey The private Key of the group key pair
173 */
174 void
175 addEKey(const Name& eKeyName, const Buffer& pubKey, const Buffer& priKey);
176
177 /**
178 * @brief Get the group key pair from database
179 */
180 std::tuple<Buffer, Buffer>
181 getEKey(const Name& eKeyName);
182
183 /**
184 * @brief Delete all the EKeys in the database
185 *
186 * The database will keep growing because EKeys will keep being added. The method
187 * should be called periodically
188 */
189 void
190 cleanEKeys();
191
192 /**
193 * @brief Delete a EKey with name @p eKeyName from database
194 */
195 void
196 deleteEKey(const Name& eKeyName);
197
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -0700198private:
199 class Impl;
200 unique_ptr<Impl> m_impl;
201};
202
Alexander Afanasyev9091d832018-04-18 17:21:08 -0400203} // namespace nac
Zhiyi Zhang7cc09fc2015-09-01 13:40:32 -0700204} // namespace ndn
205
206#endif // GEP_GROUP_MANAGER_DB_HPP