35 NDN_THROW(
Error(
"Data is not a prefix announcement: ContentType is " +
39 const Name& dataName = m_data->getName();
40 if (dataName.size() < 3 || dataName[-3] != KEYWORD_PA_COMP ||
41 !dataName[-2].
isVersion() || !dataName[-1].isSegment()) {
42 NDN_THROW(
Error(
"Data is not a prefix announcement: wrong name structure"));
46 const Block& payload = m_data->getContent();
53 m_validity.emplace(*validityElement);
66 optional<uint64_t> version)
const 69 Name dataName = m_announcedName;
70 dataName.
append(KEYWORD_PA_COMP);
73 m_data.emplace(dataName);
78 m_expiration.count()));
80 content.
push_back(m_validity->wireEncode());
83 m_data->setContent(content);
85 keyChain.sign(*m_data, si);
101 if (expiration < 0_ms) {
102 NDN_THROW(std::invalid_argument(
"expiration period is negative"));
105 m_expiration = expiration;
const Name & getAnnouncedName() const
Return announced name.
const element_container & elements() const
Get container of sub-elements.
const Data & toData(KeyChain &keyChain, const ndn::security::SigningInfo &si=KeyChain::getDefaultSigningInfo(), optional< uint64_t > version=nullopt) const
Create a Data packet representing the prefix announcement, if it does not exist.
constexpr bool isCriticalType(uint32_t type)
Determine whether a TLV-TYPE is "critical" for evolvability purpose.
element_const_iterator find(uint32_t type) const
Find the first sub-element of the specified TLV-TYPE.
std::ostream & operator<<(std::ostream &os, const Data &data)
time::milliseconds getExpiration() const
Return relative expiration period.
PrefixAnnouncement & setValidityPeriod(optional< security::ValidityPeriod > validity)
Set absolute validity period.
Represents a TLV element of NDN packet format.
static time_point now() noexcept
Block makeNonNegativeIntegerBlock(uint32_t type, uint64_t value)
Create a TLV block containing a non-negative integer.
Name & append(const Component &component)
Append a component.
Signing parameters passed to KeyChain.
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
Name & appendVersion(optional< uint64_t > version=nullopt)
Append a version component.
A prefix announcement object that represents an application's intent of registering a prefix toward i...
bool isVersion() const
Check if the component is a version per NDN naming conventions.
static const name::Component KEYWORD_PA_COMP
PrefixAnnouncement & setExpiration(time::milliseconds expiration)
Set relative expiration period.
const Block & get(uint32_t type) const
Return the first sub-element of the specified TLV-TYPE.
Represents an absolute name.
void push_back(const Block &element)
Append a sub-element.
void parse() const
Parse TLV-VALUE into sub-elements.
PrefixAnnouncement & setAnnouncedName(Name name)
Set announced name.
Represents a name component.
void encode()
Encode sub-elements into TLV-VALUE.
milliseconds toUnixTimestamp(const system_clock::TimePoint &point)
Convert system_clock::TimePoint to UNIX timestamp.
optional< security::ValidityPeriod > getValidityPeriod() const
Return absolute validity period.
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix of the name.
bool operator==(const Data &lhs, const Data &rhs)
PrefixAnnouncement()
Construct an empty prefix announcement.
std::string to_string(const V &v)
element_const_iterator elements_end() const
Equivalent to elements().end()
Represents a Data packet.
Name & appendSegment(uint64_t segmentNo)
Append a segment number (sequential) component.