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-2023 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 
36 class PrefixAnnouncement : private boost::equality_comparable<PrefixAnnouncement>
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 std::optional<Data>&
62  getData() const
63  {
64  return m_data;
65  }
66 
74  const Data&
75  toData(KeyChain& keyChain,
77  std::optional<uint64_t> version = std::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  std::optional<security::ValidityPeriod>
112  {
113  return m_validity;
114  }
115 
120  setValidityPeriod(std::optional<security::ValidityPeriod> validity);
121 
122 public: // static methods
126  static const name::Component&
128 
129 private: // non-member operators
130  // NOTE: the following "hidden friend" operators are available via
131  // argument-dependent lookup only and must be defined inline.
132  // boost::equality_comparable provides != operator.
133 
138  friend bool
140  {
141  return lhs.m_announcedName == rhs.m_announcedName &&
142  lhs.m_expiration == rhs.m_expiration &&
143  lhs.m_validity == rhs.m_validity;
144  }
145 
146 private:
147  Name m_announcedName;
148  time::milliseconds m_expiration = 0_ms;
149  std::optional<security::ValidityPeriod> m_validity;
150 
151  mutable std::optional<Data> m_data;
152 };
153 
159 std::ostream&
160 operator<<(std::ostream& os, const PrefixAnnouncement& pa);
161 
162 } // namespace ndn
163 
164 #endif // NDN_CXX_PREFIX_ANNOUNCEMENT_HPP
Represents a Data packet.
Definition: data.hpp:39
Represents an absolute name.
Definition: name.hpp:45
A prefix announcement object that represents an application's intent of registering a prefix toward i...
friend bool operator==(const PrefixAnnouncement &lhs, const PrefixAnnouncement &rhs)
Test whether two prefix announcements have the same name, expiration period, and validity period.
const Name & getAnnouncedName() const
Return announced name.
std::optional< security::ValidityPeriod > getValidityPeriod() const
Return absolute validity period.
const std::optional< Data > & getData() const
Get the Data representing the prefix announcement, if available.
PrefixAnnouncement & setValidityPeriod(std::optional< security::ValidityPeriod > validity)
Set absolute validity period.
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(), std::optional< uint64_t > version=std::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.
The main interface for signing key management.
Definition: key-chain.hpp:87
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:28
@ PrefixAnnouncement
Definition: tlv.hpp:53
::boost::chrono::milliseconds milliseconds
Definition: time.hpp:52
Definition: data.cpp:25
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:377