Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -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 | cea58d5 | 2015-08-26 10:19:56 -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 | cea58d5 | 2015-08-26 10:19:56 -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 | cea58d5 | 2015-08-26 10:19:56 -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 | cea58d5 | 2015-08-26 10:19:56 -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 | cea58d5 | 2015-08-26 10:19:56 -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 | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 22 | #ifndef NDN_NAC_SCHEDULE_HPP |
| 23 | #define NDN_NAC_SCHEDULE_HPP |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 24 | |
| 25 | #include "common.hpp" |
| 26 | #include "repetitive-interval.hpp" |
| 27 | |
| 28 | namespace ndn { |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 29 | namespace nac { |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * @brief Schedule is used to manage the time, which contains two sets of RepetitiveIntervals |
| 33 | * |
| 34 | * whiteIntervalList is used to define the time allowing member's access to data |
| 35 | * blackIntervalList is used to define the time not allowing member's access to data |
| 36 | */ |
| 37 | class Schedule |
| 38 | { |
| 39 | public: |
| 40 | Schedule(); |
| 41 | |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 42 | explicit |
| 43 | Schedule(const Block& block); |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 44 | |
| 45 | public: |
| 46 | template<encoding::Tag TAG> |
| 47 | size_t |
| 48 | wireEncode(EncodingImpl<TAG>& encoder) const; |
| 49 | |
| 50 | const Block& |
| 51 | wireEncode() const; |
| 52 | |
| 53 | void |
| 54 | wireDecode(const Block& wire); |
| 55 | |
| 56 | ///@brief Add an RepetitiveInterval @p repetitiveInterval into white list |
| 57 | Schedule& |
| 58 | addWhiteInterval(const RepetitiveInterval& repetitiveInterval); |
| 59 | |
| 60 | ///@brief Add the RepetitiveInterval into black list |
| 61 | Schedule& |
| 62 | addBlackInterval(const RepetitiveInterval& repetitiveInterval); |
| 63 | |
| 64 | /** |
| 65 | * @brief Get the Interval that covers the @p ts |
| 66 | * |
| 67 | * Function iterates two repetitive interval sets and find out |
| 68 | * the shortest interval that allows group member to have the access to the data |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 69 | * if there's no interval covering the @p ts, function will return false and |
| 70 | * return a negative interval |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 71 | */ |
Zhiyi Zhang | 7cc09fc | 2015-09-01 13:40:32 -0700 | [diff] [blame] | 72 | std::tuple<bool, Interval> |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 73 | getCoveringInterval(const TimeStamp& ts) const; |
| 74 | |
| 75 | private: |
| 76 | std::set<RepetitiveInterval> m_whiteIntervalList; |
| 77 | std::set<RepetitiveInterval> m_blackIntervalList; |
| 78 | |
| 79 | mutable Block m_wire; |
| 80 | }; |
| 81 | |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 82 | } // namespace nac |
Zhiyi Zhang | cea58d5 | 2015-08-26 10:19:56 -0700 | [diff] [blame] | 83 | } // namespace ndn |
| 84 | |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 85 | #endif // NDN_NAC_SCHEDULE_HPP |