Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, Regents of the University of California |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 5 | * 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 Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 8 | * NAC is free software: you can redistribute it and/or modify it under the terms |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 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 | * |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 12 | * NAC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 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 |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 17 | * NAC, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 18 | * |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 19 | * @author Zhiyi Zhang <zhiyi@cs.ucla.edu> |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #ifndef GEP_GROUP_MANAGER_DB_HPP |
| 23 | #define GEP_GROUP_MANAGER_DB_HPP |
| 24 | |
| 25 | #include "schedule.hpp" |
| 26 | |
| 27 | namespace ndn { |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 28 | namespace nac { |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 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 | */ |
| 35 | class GroupManagerDB |
| 36 | { |
| 37 | public: |
| 38 | class Error : public std::runtime_error |
| 39 | { |
| 40 | public: |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 41 | using std::runtime_error::runtime_error; |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | public: |
Yingdi Yu | 8c43fcc | 2016-03-09 18:23:57 -0800 | [diff] [blame] | 45 | /** |
| 46 | * @brief Create the database of group manager at path @p dbPath. |
| 47 | */ |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 48 | explicit |
| 49 | GroupManagerDB(const std::string& dbPath); |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 50 | |
| 51 | ~GroupManagerDB(); |
| 52 | |
| 53 | public: |
| 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 Zhang | 84986cc | 2015-09-21 00:26:07 +0800 | [diff] [blame] | 77 | * @brief Get member key name and public key buffer of a schedule with @p name. |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 78 | */ |
Zhiyi Zhang | 84986cc | 2015-09-21 00:26:07 +0800 | [diff] [blame] | 79 | std::map<Name, Buffer> |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 80 | 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 Yu | 8c43fcc | 2016-03-09 18:23:57 -0800 | [diff] [blame] | 92 | * @brief Delete the schedule with @p name. |
| 93 | * also delete members which reference the schedule. |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 94 | */ |
| 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 Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 131 | * @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 Zhang | 84986cc | 2015-09-21 00:26:07 +0800 | [diff] [blame] | 139 | * @brief Add a new member with @p key of @p keyName |
| 140 | * into a schedule with name @p scheduleName. |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 141 | * |
| 142 | * @throw Error when there's no schedule named @p scheduleName |
Zhiyi Zhang | 84986cc | 2015-09-21 00:26:07 +0800 | [diff] [blame] | 143 | * @throw Error if add operation fails, e.g., the added member exists |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 144 | */ |
| 145 | void |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 146 | addMember(const std::string& scheduleName, const Name& keyName, const Buffer& key); |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 147 | |
| 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 Zhang | 67f90aa | 2016-10-16 14:29:15 -0700 | [diff] [blame] | 162 | /** |
| 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 Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 198 | private: |
| 199 | class Impl; |
| 200 | unique_ptr<Impl> m_impl; |
| 201 | }; |
| 202 | |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 203 | } // namespace nac |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 204 | } // namespace ndn |
| 205 | |
| 206 | #endif // GEP_GROUP_MANAGER_DB_HPP |