blob: 9958ba31f1748baba8ad6e72e44aed0f3eccdb92 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev2ba8f662014-01-05 22:53:18 -08002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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 Afanasyev2ba8f662014-01-05 22:53:18 -080020 */
21
22#ifndef NDN_META_INFO_HPP
23#define NDN_META_INFO_HPP
24
Alexander Afanasyev15f67312014-07-22 15:11:09 -070025#include "common.hpp"
Alexander Afanasyev01065fb2014-10-02 13:01:46 -070026#include "encoding/block.hpp"
Alexander Afanasyev95b0e342014-02-12 21:34:44 -080027#include "encoding/encoding-buffer.hpp"
Alexander Afanasyev15f67312014-07-22 15:11:09 -070028#include "util/time.hpp"
Alexander Afanasyev01065fb2014-10-02 13:01:46 -070029#include "name-component.hpp"
Alexander Afanasyev95b0e342014-02-12 21:34:44 -080030
Alexander Afanasyev2ba8f662014-01-05 22:53:18 -080031namespace ndn {
32
33/**
34 * An MetaInfo holds the meta info which is signed inside the data packet.
35 */
Alexander Afanasyev2a7f7202014-04-23 14:25:29 -070036class MetaInfo
37{
Alexander Afanasyev2ba8f662014-01-05 22:53:18 -080038public:
39 enum {
40 TYPE_DEFAULT = 0,
41 TYPE_LINK = 1,
42 TYPE_KEY = 2
43 };
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070044
Alexander Afanasyev01065fb2014-10-02 13:01:46 -070045 MetaInfo();
Alexander Afanasyev95b0e342014-02-12 21:34:44 -080046
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070047 /**
48 * @brief Create from wire encoding
49 */
Alexander Afanasyev01065fb2014-10-02 13:01:46 -070050 explicit
51 MetaInfo(const Block& block);
Alexander Afanasyevc348f832014-02-17 16:35:17 -080052
53 template<bool T>
54 size_t
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070055 wireEncode(EncodingImpl<T>& block) const;
Alexander Afanasyevc348f832014-02-17 16:35:17 -080056
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070057 const Block&
Alexander Afanasyevc348f832014-02-17 16:35:17 -080058 wireEncode() const;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070059
Alexander Afanasyevc348f832014-02-17 16:35:17 -080060 void
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070061 wireDecode(const Block& wire);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070062
Alexander Afanasyevc348f832014-02-17 16:35:17 -080063 ///////////////////////////////////////////////////////////////////////////////
Alexander Afanasyev5964fb72014-02-18 12:42:45 -080064 // Getters/setters
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070065
66 uint32_t
Alexander Afanasyev01065fb2014-10-02 13:01:46 -070067 getType() const;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070068
Alexander Afanasyev95b0e342014-02-12 21:34:44 -080069 MetaInfo&
Alexander Afanasyev01065fb2014-10-02 13:01:46 -070070 setType(uint32_t type);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070071
72 const time::milliseconds&
Alexander Afanasyev01065fb2014-10-02 13:01:46 -070073 getFreshnessPeriod() const;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070074
Alexander Afanasyev95b0e342014-02-12 21:34:44 -080075 MetaInfo&
Alexander Afanasyev01065fb2014-10-02 13:01:46 -070076 setFreshnessPeriod(const time::milliseconds& freshnessPeriod);
Alexander Afanasyev2ba8f662014-01-05 22:53:18 -080077
Alexander Afanasyev95b0e342014-02-12 21:34:44 -080078 const name::Component&
Alexander Afanasyev01065fb2014-10-02 13:01:46 -070079 getFinalBlockId() const;
Alexander Afanasyev95b0e342014-02-12 21:34:44 -080080
81 MetaInfo&
Alexander Afanasyev01065fb2014-10-02 13:01:46 -070082 setFinalBlockId(const name::Component& finalBlockId);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070083
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070084public: // EqualityComparable concept
85 bool
Alexander Afanasyev01065fb2014-10-02 13:01:46 -070086 operator==(const MetaInfo& other) const;
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070087
88 bool
Alexander Afanasyev01065fb2014-10-02 13:01:46 -070089 operator!=(const MetaInfo& other) const;
Alexander Afanasyevff2d08f2014-04-07 18:28:25 -070090
Alexander Afanasyev2ba8f662014-01-05 22:53:18 -080091private:
Alexander Afanasyev95b0e342014-02-12 21:34:44 -080092 uint32_t m_type;
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070093 time::milliseconds m_freshnessPeriod;
Alexander Afanasyev95b0e342014-02-12 21:34:44 -080094 name::Component m_finalBlockId;
Alexander Afanasyev2ba8f662014-01-05 22:53:18 -080095
Alexander Afanasyev95b0e342014-02-12 21:34:44 -080096 mutable Block m_wire;
Alexander Afanasyev2ba8f662014-01-05 22:53:18 -080097};
98
Alexander Afanasyev01065fb2014-10-02 13:01:46 -070099std::ostream&
100operator<<(std::ostream& os, const MetaInfo& info);
101
102/////////////////////////////////////////////////////////////////////////
103
104inline uint32_t
105MetaInfo::getType() const
Alexander Afanasyev95b0e342014-02-12 21:34:44 -0800106{
Alexander Afanasyev01065fb2014-10-02 13:01:46 -0700107 return m_type;
Alexander Afanasyev95b0e342014-02-12 21:34:44 -0800108}
109
Alexander Afanasyev01065fb2014-10-02 13:01:46 -0700110inline const time::milliseconds&
111MetaInfo::getFreshnessPeriod() const
Alexander Afanasyev2ba8f662014-01-05 22:53:18 -0800112{
Alexander Afanasyev01065fb2014-10-02 13:01:46 -0700113 return m_freshnessPeriod;
Alexander Afanasyev2ba8f662014-01-05 22:53:18 -0800114}
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -0700115
Alexander Afanasyev01065fb2014-10-02 13:01:46 -0700116inline const name::Component&
117MetaInfo::getFinalBlockId() const
Alexander Afanasyev2ba8f662014-01-05 22:53:18 -0800118{
Alexander Afanasyev01065fb2014-10-02 13:01:46 -0700119 return m_finalBlockId;
Alexander Afanasyev2ba8f662014-01-05 22:53:18 -0800120}
121
Alexander Afanasyev01065fb2014-10-02 13:01:46 -0700122inline bool
123MetaInfo::operator==(const MetaInfo& other) const
Alexander Afanasyev4ff3c912014-01-03 15:25:02 -0800124{
Alexander Afanasyev01065fb2014-10-02 13:01:46 -0700125 return wireEncode() == other.wireEncode();
126}
Alexander Afanasyev4ff3c912014-01-03 15:25:02 -0800127
Alexander Afanasyev01065fb2014-10-02 13:01:46 -0700128inline bool
129MetaInfo::operator!=(const MetaInfo& other) const
130{
131 return !(*this == other);
Alexander Afanasyev4ff3c912014-01-03 15:25:02 -0800132}
133
Alexander Afanasyev2ba8f662014-01-05 22:53:18 -0800134} // namespace ndn
135
136#endif // NDN_META_INFO_HPP