prefix-announcement.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2021 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
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.
20  */
21 
22 #ifndef NDN_CXX_PREFIX_ANNOUNCEMENT_HPP
23 #define NDN_CXX_PREFIX_ANNOUNCEMENT_HPP
24 
25 #include "ndn-cxx/data.hpp"
27 
28 namespace ndn {
29 
37 {
38 public:
39  class Error : public tlv::Error
40  {
41  public:
42  using tlv::Error::Error;
43  };
44 
51 
56  explicit
58 
61  const optional<Data>&
62  getData() const
63  {
64  return m_data;
65  }
66 
74  const Data&
75  toData(KeyChain& keyChain,
77  optional<uint64_t> version = nullopt) const;
78 
81  const Name&
83  {
84  return m_announcedName;
85  }
86 
91  setAnnouncedName(Name name);
92 
96  getExpiration() const
97  {
98  return m_expiration;
99  }
100 
106  setExpiration(time::milliseconds expiration);
107 
110  optional<security::ValidityPeriod>
112  {
113  return m_validity;
114  }
115 
120  setValidityPeriod(optional<security::ValidityPeriod> validity);
121 
122 public: // static methods
126  static const name::Component&
128 
129 private:
130  mutable optional<Data> m_data;
131  Name m_announcedName;
132  time::milliseconds m_expiration = 0_ms;
133  optional<security::ValidityPeriod> m_validity;
134 };
135 
140 bool
141 operator==(const PrefixAnnouncement& lhs, const PrefixAnnouncement& rhs);
142 
143 inline bool
145 {
146  return !(lhs == rhs);
147 }
148 
154 std::ostream&
155 operator<<(std::ostream& os, const PrefixAnnouncement& pa);
156 
157 } // namespace ndn
158 
159 #endif // NDN_CXX_PREFIX_ANNOUNCEMENT_HPP
Represents a Data packet.
Definition: data.hpp:39
Represents an absolute name.
Definition: name.hpp:44
A prefix announcement object that represents an application's intent of registering a prefix toward i...
const Name & getAnnouncedName() const
Return announced name.
optional< security::ValidityPeriod > getValidityPeriod() const
Return absolute validity period.
PrefixAnnouncement & setValidityPeriod(optional< security::ValidityPeriod > validity)
Set absolute validity period.
const optional< Data > & getData() const
Get the Data representing the prefix announcement, if available.
time::milliseconds getExpiration() const
Return relative expiration period.
PrefixAnnouncement & setExpiration(time::milliseconds expiration)
Set relative expiration period.
PrefixAnnouncement()
Construct an empty prefix announcement.
PrefixAnnouncement & setAnnouncedName(Name name)
Set announced name.
const Data & toData(KeyChain &keyChain, const ndn::security::SigningInfo &si=security::SigningInfo(), optional< uint64_t > version=nullopt) const
Create a Data packet representing the prefix announcement, if it does not exist.
static const name::Component & getKeywordComponent()
Returns the well-known keyword name component used for prefix announcements (32=PA)
Represents a name component.
Signing parameters passed to KeyChain.
Represents an error in TLV encoding or decoding.
Definition: tlv.hpp:54
Error(const char *expectedType, uint32_t actualType)
Definition: tlv.cpp:27
@ PrefixAnnouncement
Definition: tlv.hpp:52
boost::chrono::milliseconds milliseconds
Definition: time.hpp:48
Definition: data.cpp:25
bool operator!=(const Data &lhs, const Data &rhs)
Definition: data.hpp:364
bool operator==(const Data &lhs, const Data &rhs)
Definition: data.cpp:364
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:374