Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #ifndef NDN_META_INFO_HPP |
| 23 | #define NDN_META_INFO_HPP |
| 24 | |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 25 | #include "common.hpp" |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 26 | #include "encoding/block.hpp" |
Alexander Afanasyev | 95b0e34 | 2014-02-12 21:34:44 -0800 | [diff] [blame] | 27 | #include "encoding/encoding-buffer.hpp" |
Alexander Afanasyev | 15f6731 | 2014-07-22 15:11:09 -0700 | [diff] [blame] | 28 | #include "util/time.hpp" |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 29 | #include "name-component.hpp" |
Alexander Afanasyev | 95b0e34 | 2014-02-12 21:34:44 -0800 | [diff] [blame] | 30 | |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 31 | namespace ndn { |
| 32 | |
| 33 | /** |
| 34 | * An MetaInfo holds the meta info which is signed inside the data packet. |
| 35 | */ |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 36 | class MetaInfo |
| 37 | { |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 38 | public: |
| 39 | enum { |
| 40 | TYPE_DEFAULT = 0, |
| 41 | TYPE_LINK = 1, |
| 42 | TYPE_KEY = 2 |
| 43 | }; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 44 | |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 45 | MetaInfo(); |
Alexander Afanasyev | 95b0e34 | 2014-02-12 21:34:44 -0800 | [diff] [blame] | 46 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 47 | /** |
| 48 | * @brief Create from wire encoding |
| 49 | */ |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 50 | explicit |
| 51 | MetaInfo(const Block& block); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 52 | |
| 53 | template<bool T> |
| 54 | size_t |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 55 | wireEncode(EncodingImpl<T>& block) const; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 56 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 57 | const Block& |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 58 | wireEncode() const; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 59 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 60 | void |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 61 | wireDecode(const Block& wire); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 62 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 63 | /////////////////////////////////////////////////////////////////////////////// |
Alexander Afanasyev | 5964fb7 | 2014-02-18 12:42:45 -0800 | [diff] [blame] | 64 | // Getters/setters |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 65 | |
| 66 | uint32_t |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 67 | getType() const; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 68 | |
Alexander Afanasyev | 95b0e34 | 2014-02-12 21:34:44 -0800 | [diff] [blame] | 69 | MetaInfo& |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 70 | setType(uint32_t type); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 71 | |
| 72 | const time::milliseconds& |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 73 | getFreshnessPeriod() const; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 74 | |
Alexander Afanasyev | 95b0e34 | 2014-02-12 21:34:44 -0800 | [diff] [blame] | 75 | MetaInfo& |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 76 | setFreshnessPeriod(const time::milliseconds& freshnessPeriod); |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 77 | |
Alexander Afanasyev | 95b0e34 | 2014-02-12 21:34:44 -0800 | [diff] [blame] | 78 | const name::Component& |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 79 | getFinalBlockId() const; |
Alexander Afanasyev | 95b0e34 | 2014-02-12 21:34:44 -0800 | [diff] [blame] | 80 | |
| 81 | MetaInfo& |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 82 | setFinalBlockId(const name::Component& finalBlockId); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 83 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 84 | public: // EqualityComparable concept |
| 85 | bool |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 86 | operator==(const MetaInfo& other) const; |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 87 | |
| 88 | bool |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 89 | operator!=(const MetaInfo& other) const; |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 90 | |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 91 | private: |
Alexander Afanasyev | 95b0e34 | 2014-02-12 21:34:44 -0800 | [diff] [blame] | 92 | uint32_t m_type; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 93 | time::milliseconds m_freshnessPeriod; |
Alexander Afanasyev | 95b0e34 | 2014-02-12 21:34:44 -0800 | [diff] [blame] | 94 | name::Component m_finalBlockId; |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 95 | |
Alexander Afanasyev | 95b0e34 | 2014-02-12 21:34:44 -0800 | [diff] [blame] | 96 | mutable Block m_wire; |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 97 | }; |
| 98 | |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 99 | std::ostream& |
| 100 | operator<<(std::ostream& os, const MetaInfo& info); |
| 101 | |
| 102 | ///////////////////////////////////////////////////////////////////////// |
| 103 | |
| 104 | inline uint32_t |
| 105 | MetaInfo::getType() const |
Alexander Afanasyev | 95b0e34 | 2014-02-12 21:34:44 -0800 | [diff] [blame] | 106 | { |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 107 | return m_type; |
Alexander Afanasyev | 95b0e34 | 2014-02-12 21:34:44 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 110 | inline const time::milliseconds& |
| 111 | MetaInfo::getFreshnessPeriod() const |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 112 | { |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 113 | return m_freshnessPeriod; |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 114 | } |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 115 | |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 116 | inline const name::Component& |
| 117 | MetaInfo::getFinalBlockId() const |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 118 | { |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 119 | return m_finalBlockId; |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 120 | } |
| 121 | |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 122 | inline bool |
| 123 | MetaInfo::operator==(const MetaInfo& other) const |
Alexander Afanasyev | 4ff3c91 | 2014-01-03 15:25:02 -0800 | [diff] [blame] | 124 | { |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 125 | return wireEncode() == other.wireEncode(); |
| 126 | } |
Alexander Afanasyev | 4ff3c91 | 2014-01-03 15:25:02 -0800 | [diff] [blame] | 127 | |
Alexander Afanasyev | 01065fb | 2014-10-02 13:01:46 -0700 | [diff] [blame] | 128 | inline bool |
| 129 | MetaInfo::operator!=(const MetaInfo& other) const |
| 130 | { |
| 131 | return !(*this == other); |
Alexander Afanasyev | 4ff3c91 | 2014-01-03 15:25:02 -0800 | [diff] [blame] | 132 | } |
| 133 | |
Alexander Afanasyev | 2ba8f66 | 2014-01-05 22:53:18 -0800 | [diff] [blame] | 134 | } // namespace ndn |
| 135 | |
| 136 | #endif // NDN_META_INFO_HPP |