Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 1 | /* -*- 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 Zhiyi Zhang <dreamerbarrychang@gmail.com> |
| 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 { |
| 28 | namespace 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 | */ |
| 35 | class GroupManagerDB |
| 36 | { |
| 37 | public: |
| 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 | |
| 48 | public: |
Yingdi Yu | 8c43fcc | 2016-03-09 18:23:57 -0800 | [diff] [blame] | 49 | /** |
| 50 | * @brief Create the database of group manager at path @p dbPath. |
| 51 | */ |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 52 | explicit |
Yingdi Yu | 8c43fcc | 2016-03-09 18:23:57 -0800 | [diff] [blame] | 53 | GroupManagerDB(const std::string& dbPath); |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 54 | |
| 55 | ~GroupManagerDB(); |
| 56 | |
| 57 | public: |
| 58 | ////////////////////////////////////////////////////// schedule management |
| 59 | |
| 60 | /** |
| 61 | * @brief Check if there is a schedule with @p name |
| 62 | */ |
| 63 | bool |
| 64 | hasSchedule(const std::string& name) const; |
| 65 | |
| 66 | /** |
| 67 | * @brief List all the names of the schedules |
| 68 | * @return A list of the name of all schedules. |
| 69 | */ |
| 70 | std::list<std::string> |
| 71 | listAllScheduleNames() const; |
| 72 | |
| 73 | /** |
| 74 | * @brief Get a schedule with @p name. |
| 75 | * @throw Error if the schedule does not exist |
| 76 | */ |
| 77 | Schedule |
| 78 | getSchedule(const std::string& name) const; |
| 79 | |
| 80 | /** |
Zhiyi Zhang | 84986cc | 2015-09-21 00:26:07 +0800 | [diff] [blame] | 81 | * @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] | 82 | */ |
Zhiyi Zhang | 84986cc | 2015-09-21 00:26:07 +0800 | [diff] [blame] | 83 | std::map<Name, Buffer> |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 84 | getScheduleMembers(const std::string& name) const; |
| 85 | |
| 86 | /** |
| 87 | * @brief Add a @p schedule with @p name |
| 88 | * @pre Name.length() != 0 |
| 89 | * |
| 90 | * @throw Error if add operation fails, e.g., a schedule with the same name already exists |
| 91 | */ |
| 92 | void |
| 93 | addSchedule(const std::string& name, const Schedule& schedule); |
| 94 | |
| 95 | /** |
Yingdi Yu | 8c43fcc | 2016-03-09 18:23:57 -0800 | [diff] [blame] | 96 | * @brief Delete the schedule with @p name. |
| 97 | * also delete members which reference the schedule. |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 98 | */ |
| 99 | void |
| 100 | deleteSchedule(const std::string& name); |
| 101 | |
| 102 | /** |
| 103 | * @brief Rename a schedule with @p oldName to @p newName |
| 104 | * @pre newName.length() != 0 |
| 105 | * |
| 106 | * @throw Error if update operation fails, e.g., a schedule with @p newName already exists |
| 107 | */ |
| 108 | void |
| 109 | renameSchedule(const std::string& oldName, const std::string& newName); |
| 110 | |
| 111 | /** |
| 112 | * @brief Update the schedule with @p name and replace the old object with @p schedule |
| 113 | * |
| 114 | * if no schedule with @p name exists, a new schedule |
| 115 | * with @p name and @p schedule will be added to database |
| 116 | */ |
| 117 | void |
| 118 | updateSchedule(const std::string& name, const Schedule& schedule); |
| 119 | |
| 120 | ////////////////////////////////////////////////////// member management |
| 121 | |
| 122 | /** |
| 123 | * @brief Check if there is a member with name @p identity |
| 124 | */ |
| 125 | bool |
| 126 | hasMember(const Name& identity) const; |
| 127 | |
| 128 | /** |
| 129 | * @brief List all the members |
| 130 | */ |
| 131 | std::list<Name> |
| 132 | listAllMembers() const; |
| 133 | |
| 134 | /** |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 135 | * @brief Get the schedule name of a member with name @p identity |
| 136 | * |
| 137 | * @throw Error if there is no member with name @p identity in database |
| 138 | */ |
| 139 | std::string |
| 140 | getMemberSchedule(const Name& identity) const; |
| 141 | |
| 142 | /** |
Zhiyi Zhang | 84986cc | 2015-09-21 00:26:07 +0800 | [diff] [blame] | 143 | * @brief Add a new member with @p key of @p keyName |
| 144 | * into a schedule with name @p scheduleName. |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 145 | * |
| 146 | * @throw Error when there's no schedule named @p scheduleName |
Zhiyi Zhang | 84986cc | 2015-09-21 00:26:07 +0800 | [diff] [blame] | 147 | * @throw Error if add operation fails, e.g., the added member exists |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 148 | */ |
| 149 | void |
Zhiyi Zhang | 84986cc | 2015-09-21 00:26:07 +0800 | [diff] [blame] | 150 | addMember(const std::string& scheduleName, const Name& keyName, |
| 151 | const Buffer& key); |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 152 | |
| 153 | /** |
| 154 | * @brief Change the schedule of a member with name @p identity to a schedule with @p scheduleName |
| 155 | * |
| 156 | * @throw Error when there's no schedule named @p scheduleName |
| 157 | */ |
| 158 | void |
| 159 | updateMemberSchedule(const Name& identity, const std::string& scheduleName); |
| 160 | |
| 161 | /** |
| 162 | * @brief Delete a member with name @p identity from database |
| 163 | */ |
| 164 | void |
| 165 | deleteMember(const Name& identity); |
| 166 | |
| 167 | private: |
| 168 | class Impl; |
| 169 | unique_ptr<Impl> m_impl; |
| 170 | }; |
| 171 | |
| 172 | } // namespace gep |
| 173 | } // namespace ndn |
| 174 | |
| 175 | #endif // GEP_GROUP_MANAGER_DB_HPP |