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: |
| 49 | explicit |
| 50 | GroupManagerDB(const std::string& dbDir); |
| 51 | |
| 52 | ~GroupManagerDB(); |
| 53 | |
| 54 | public: |
| 55 | ////////////////////////////////////////////////////// schedule management |
| 56 | |
| 57 | /** |
| 58 | * @brief Check if there is a schedule with @p name |
| 59 | */ |
| 60 | bool |
| 61 | hasSchedule(const std::string& name) const; |
| 62 | |
| 63 | /** |
| 64 | * @brief List all the names of the schedules |
| 65 | * @return A list of the name of all schedules. |
| 66 | */ |
| 67 | std::list<std::string> |
| 68 | listAllScheduleNames() const; |
| 69 | |
| 70 | /** |
| 71 | * @brief Get a schedule with @p name. |
| 72 | * @throw Error if the schedule does not exist |
| 73 | */ |
| 74 | Schedule |
| 75 | getSchedule(const std::string& name) const; |
| 76 | |
| 77 | /** |
Zhiyi Zhang | 84986cc | 2015-09-21 00:26:07 +0800 | [diff] [blame] | 78 | * @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] | 79 | */ |
Zhiyi Zhang | 84986cc | 2015-09-21 00:26:07 +0800 | [diff] [blame] | 80 | std::map<Name, Buffer> |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 81 | getScheduleMembers(const std::string& name) const; |
| 82 | |
| 83 | /** |
| 84 | * @brief Add a @p schedule with @p name |
| 85 | * @pre Name.length() != 0 |
| 86 | * |
| 87 | * @throw Error if add operation fails, e.g., a schedule with the same name already exists |
| 88 | */ |
| 89 | void |
| 90 | addSchedule(const std::string& name, const Schedule& schedule); |
| 91 | |
| 92 | /** |
| 93 | * @brief Delete the schedule with @p name |
| 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 | 84986cc | 2015-09-21 00:26:07 +0800 | [diff] [blame] | 146 | addMember(const std::string& scheduleName, const Name& keyName, |
| 147 | const Buffer& key); |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * @brief Change the schedule of a member with name @p identity to a schedule with @p scheduleName |
| 151 | * |
| 152 | * @throw Error when there's no schedule named @p scheduleName |
| 153 | */ |
| 154 | void |
| 155 | updateMemberSchedule(const Name& identity, const std::string& scheduleName); |
| 156 | |
| 157 | /** |
| 158 | * @brief Delete a member with name @p identity from database |
| 159 | */ |
| 160 | void |
| 161 | deleteMember(const Name& identity); |
| 162 | |
| 163 | private: |
| 164 | class Impl; |
| 165 | unique_ptr<Impl> m_impl; |
| 166 | }; |
| 167 | |
| 168 | } // namespace gep |
| 169 | } // namespace ndn |
| 170 | |
| 171 | #endif // GEP_GROUP_MANAGER_DB_HPP |