160 lines
4.4 KiB
C++
160 lines
4.4 KiB
C++
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
/*
|
|
* Copyright (c) 2013-2023 Regents of the University of California.
|
|
*
|
|
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
|
|
*
|
|
* ndn-cxx library is free software: you can redistribute it and/or modify it under the
|
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
|
* Foundation, either version 3 of the License, or (at your option) any later version.
|
|
*
|
|
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
|
*
|
|
* You should have received copies of the GNU General Public License and GNU Lesser
|
|
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
|
|
* <http://www.gnu.org/licenses/>.
|
|
*
|
|
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
|
|
*/
|
|
|
|
#ifndef NDN_CXX_PREFIX_ANNOUNCEMENT_HPP
|
|
#define NDN_CXX_PREFIX_ANNOUNCEMENT_HPP
|
|
|
|
#include "ndn-cxx/data.hpp"
|
|
#include "ndn-cxx/security/key-chain.hpp"
|
|
|
|
namespace ndn {
|
|
|
|
/**
|
|
* \brief A prefix announcement object that represents an application's intent
|
|
* of registering a prefix toward itself.
|
|
*
|
|
* \sa https://redmine.named-data.net/projects/nfd/wiki/PrefixAnnouncement
|
|
*/
|
|
class PrefixAnnouncement
|
|
{
|
|
public:
|
|
class Error : public tlv::Error
|
|
{
|
|
public:
|
|
using tlv::Error::Error;
|
|
};
|
|
|
|
/** \brief Construct an empty prefix announcement.
|
|
* \post getData() == nullopt
|
|
* \post getAnnouncedName() == "/"
|
|
* \post getExpiration() == 0_ms
|
|
*/
|
|
PrefixAnnouncement();
|
|
|
|
/** \brief Decode a prefix announcement from Data.
|
|
* \throw tlv::Error the Data is not a prefix announcement.
|
|
* \post getData() == data
|
|
*/
|
|
explicit
|
|
PrefixAnnouncement(Data data);
|
|
|
|
/** \brief Get the Data representing the prefix announcement, if available.
|
|
*/
|
|
const std::optional<Data>&
|
|
getData() const
|
|
{
|
|
return m_data;
|
|
}
|
|
|
|
/** \brief Create a Data packet representing the prefix announcement, if it does not exist.
|
|
* \param keyChain KeyChain to sign the Data.
|
|
* \param si signing parameters.
|
|
* \param version version number in Data name; if nullopt, use current Unix timestamp (in
|
|
* milliseconds) as the version number.
|
|
* \post getData() == the returned Data
|
|
*/
|
|
const Data&
|
|
toData(KeyChain& keyChain,
|
|
const ndn::security::SigningInfo& si = security::SigningInfo(),
|
|
std::optional<uint64_t> version = std::nullopt) const;
|
|
|
|
/** \brief Return announced name.
|
|
*/
|
|
const Name&
|
|
getAnnouncedName() const
|
|
{
|
|
return m_announcedName;
|
|
}
|
|
|
|
/** \brief Set announced name.
|
|
* \post getData() == nullopt
|
|
*/
|
|
PrefixAnnouncement&
|
|
setAnnouncedName(Name name);
|
|
|
|
/** \brief Return relative expiration period.
|
|
*/
|
|
time::milliseconds
|
|
getExpiration() const
|
|
{
|
|
return m_expiration;
|
|
}
|
|
|
|
/** \brief Set relative expiration period.
|
|
* \throw std::invalid_argument expiration period is negative.
|
|
* \post getData() == nullopt
|
|
*/
|
|
PrefixAnnouncement&
|
|
setExpiration(time::milliseconds expiration);
|
|
|
|
/** \brief Return absolute validity period.
|
|
*/
|
|
std::optional<security::ValidityPeriod>
|
|
getValidityPeriod() const
|
|
{
|
|
return m_validity;
|
|
}
|
|
|
|
/** \brief Set absolute validity period.
|
|
* \post getData() == nullopt
|
|
*/
|
|
PrefixAnnouncement&
|
|
setValidityPeriod(std::optional<security::ValidityPeriod> validity);
|
|
|
|
public: // static methods
|
|
/**
|
|
* @brief Returns the well-known keyword name component used for prefix announcements (`32=PA`)
|
|
*/
|
|
static const name::Component&
|
|
getKeywordComponent();
|
|
|
|
private:
|
|
mutable std::optional<Data> m_data;
|
|
Name m_announcedName;
|
|
time::milliseconds m_expiration = 0_ms;
|
|
std::optional<security::ValidityPeriod> m_validity;
|
|
};
|
|
|
|
/**
|
|
* \brief Test whether two prefix announcements have the same name, expiration period,
|
|
* and validity period.
|
|
*/
|
|
bool
|
|
operator==(const PrefixAnnouncement& lhs, const PrefixAnnouncement& rhs);
|
|
|
|
inline bool
|
|
operator!=(const PrefixAnnouncement& lhs, const PrefixAnnouncement& rhs)
|
|
{
|
|
return !(lhs == rhs);
|
|
}
|
|
|
|
/**
|
|
* \brief Print prefix announcement to a stream.
|
|
*
|
|
* The output is for debugging purposes only. The format may change at any time without notice.
|
|
*/
|
|
std::ostream&
|
|
operator<<(std::ostream& os, const PrefixAnnouncement& pa);
|
|
|
|
} // namespace ndn
|
|
|
|
#endif // NDN_CXX_PREFIX_ANNOUNCEMENT_HPP
|