NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
ndn::Data Class Reference

Represents a Data packet. More...

#include <data.hpp>

Inheritance diagram for ndn::Data:
Collaboration diagram for ndn::Data:

Classes

class  Error
 

Public Member Functions

 Data (const Name &name=Name())
 Construct an unsigned Data packet with given name and empty Content. More...
 
 Data (const Block &wire)
 Construct a Data packet by decoding from wire. More...
 
template<encoding::Tag TAG>
size_t wireEncode (EncodingImpl< TAG > &encoder, bool wantUnsignedPortionOnly=false) const
 Prepend wire encoding to encoder in NDN Packet Format v0.2. More...
 
const BlockwireEncode (EncodingBuffer &encoder, const Block &signatureValue) const
 Finalize Data packet encoding with the specified SignatureValue. More...
 
const BlockwireEncode () const
 Encode to a Block. More...
 
void wireDecode (const Block &wire)
 Decode from wire in NDN Packet Format v0.2 or v0.3. More...
 
bool hasWire () const
 Check if this instance has cached wire encoding. More...
 
const NamegetFullName () const
 Get full name including implicit digest. More...
 
const NamegetName () const
 Get name. More...
 
DatasetName (const Name &name)
 Set name. More...
 
const MetaInfogetMetaInfo () const
 Get MetaInfo. More...
 
DatasetMetaInfo (const MetaInfo &metaInfo)
 Set MetaInfo. More...
 
const BlockgetContent () const
 Get Content. More...
 
DatasetContent (const Block &block)
 Set Content from a block. More...
 
DatasetContent (const uint8_t *value, size_t valueSize)
 Copy Content value from raw buffer. More...
 
DatasetContent (const ConstBufferPtr &value)
 Set Content from wire buffer. More...
 
const SignaturegetSignature () const
 Get Signature. More...
 
DatasetSignature (const Signature &signature)
 Set Signature. More...
 
DatasetSignatureValue (const Block &value)
 Set SignatureValue. More...
 
uint32_t getContentType () const
 
DatasetContentType (uint32_t type)
 
time::milliseconds getFreshnessPeriod () const
 
DatasetFreshnessPeriod (time::milliseconds freshnessPeriod)
 
const optional< name::Component > & getFinalBlock () const
 
DatasetFinalBlock (optional< name::Component > finalBlockId)
 
NDN_CXX_DEPRECATED name::Component getFinalBlockId () const
 
NDN_CXX_DEPRECATED DatasetFinalBlockId (const name::Component &finalBlockId)
 
- Public Member Functions inherited from ndn::PacketBase
uint64_t getCongestionMark () const
 get the value of the CongestionMark tag More...
 
void setCongestionMark (uint64_t mark)
 set the CongestionMark tag to the specified value More...
 
- Public Member Functions inherited from ndn::TagHost
template<typename T >
shared_ptr< T > getTag () const
 get a tag item More...
 
template<typename T >
void setTag (shared_ptr< T > tag) const
 set a tag item More...
 
template<typename T >
void removeTag () const
 remove tag item More...
 

Protected Member Functions

void resetWire ()
 Clear wire encoding and cached FullName. More...
 

Detailed Description

Represents a Data packet.

Definition at line 35 of file data.hpp.

Constructor & Destructor Documentation

◆ Data() [1/2]

ndn::Data::Data ( const Name name = Name())
explicit

Construct an unsigned Data packet with given name and empty Content.

Warning
In certain contexts that use Data::shared_from_this(), Data must be created using make_shared. Otherwise, shared_from_this() will trigger undefined behavior.

Definition at line 35 of file data.cpp.

◆ Data() [2/2]

ndn::Data::Data ( const Block wire)
explicit

Construct a Data packet by decoding from wire.

Parameters
wiretlv::Data element as defined in NDN Packet Format v0.2 or v0.3. It may be signed or unsigned.
Warning
In certain contexts that use Data::shared_from_this(), Data must be created using make_shared. Otherwise, shared_from_this() will trigger undefined behavior.

Definition at line 41 of file data.cpp.

References wireDecode().

Member Function Documentation

◆ wireEncode() [1/3]

template<encoding::Tag TAG>
size_t ndn::Data::wireEncode ( EncodingImpl< TAG > &  encoder,
bool  wantUnsignedPortionOnly = false 
) const

Prepend wire encoding to encoder in NDN Packet Format v0.2.

Parameters
encoderEncodingEstimator or EncodingBuffer instance
wantUnsignedPortionOnlyIf true, only prepends Name, MetaInfo, Content, and SignatureInfo to encoder, but omit SignatureValue and outmost Type-Length of Data element. This is intended to be used with wireEncode(encoder, signatureValue).
Exceptions
ErrorSignatureBits are not provided and wantUnsignedPortionOnly is false.

Definition at line 48 of file data.cpp.

References ndn::tlv::Data, getContent(), ndn::Signature::getInfo(), getMetaInfo(), getName(), ndn::Signature::getValue(), ndn::MetaInfo::wireEncode(), and ndn::Name::wireEncode().

Referenced by ndn::security::pib::PibSqlite3::addCertificate(), ndn::security::pib::detail::KeyImpl::getDefaultCertificate(), ndn::security::parse(), ndn::util::DummyClientFace::receive(), ndn::security::v2::KeyChain::sign(), and ndn::security::SafeBag::wireEncode().

◆ wireEncode() [2/3]

const Block & ndn::Data::wireEncode ( EncodingBuffer &  encoder,
const Block signatureValue 
) const

Finalize Data packet encoding with the specified SignatureValue.

Parameters
encoderEncodingBuffer containing Name, MetaInfo, Content, and SignatureInfo, but without SignatureValue or outmost Type-Length of Data element
signatureValueSignatureValue element

This method is intended to be used in concert with Data::wireEncode(encoder, true)

Data data;
...
EncodingBuffer encoder;
data.wireEncode(encoder, true);
...
Block signatureValue = <sign_over_unsigned_portion>(encoder.buf(), encoder.size());
data.wireEncode(encoder, signatureValue)

Definition at line 93 of file data.cpp.

References ndn::tlv::Data, ndn::Block::size(), and wireDecode().

◆ wireEncode() [3/3]

const Block & ndn::Data::wireEncode ( ) const

Encode to a Block.

Precondition
Data is signed.

Normally, this function encodes to NDN Packet Format v0.2. However, if this instance has cached wire encoding (hasWire() is true), the cached encoding is returned and it might be in v0.3 format.

Definition at line 106 of file data.cpp.

References ndn::Block::hasWire(), and wireDecode().

◆ wireDecode()

◆ hasWire()

bool ndn::Data::hasWire ( ) const
inline

Check if this instance has cached wire encoding.

Definition at line 112 of file data.hpp.

References ndn::Block::hasWire().

◆ getFullName()

const Name & ndn::Data::getFullName ( ) const

Get full name including implicit digest.

Precondition
hasWire() == true; i.e. wireEncode() must have been called
Exceptions
ErrorData has no wire encoding

Definition at line 197 of file data.cpp.

References ndn::Name::appendImplicitSha256Digest(), ndn::util::Sha256::computeDigest(), ndn::Name::empty(), ndn::Block::hasWire(), ndn::Block::size(), and ndn::Block::wire().

Referenced by nfd::cs::compareDataWithData(), nfd::cs::compareQueryWithData(), ndn::InMemoryStorage::insert(), and ndn::Interest::matchesData().

◆ getName()

◆ setName()

Data & ndn::Data::setName ( const Name name)

Set name.

Returns
a reference to this Data, to allow chaining

Definition at line 218 of file data.cpp.

References resetWire().

◆ getMetaInfo()

const MetaInfo& ndn::Data::getMetaInfo ( ) const
inline

Get MetaInfo.

Definition at line 142 of file data.hpp.

Referenced by ndn::operator<<(), ndn::operator==(), and wireEncode().

◆ setMetaInfo()

Data & ndn::Data::setMetaInfo ( const MetaInfo metaInfo)

Set MetaInfo.

Returns
a reference to this Data, to allow chaining

Definition at line 226 of file data.cpp.

References resetWire().

◆ getContent()

◆ setContent() [1/3]

Data & ndn::Data::setContent ( const Block block)

Set Content from a block.

If block's TLV-TYPE is Content, it will be used directly as Data's Content element. If block's TLV-TYPE is not Content, it will be nested into a Content element.

Returns
a reference to this Data, to allow chaining

Definition at line 243 of file data.cpp.

References ndn::tlv::Content, resetWire(), and ndn::Block::type().

◆ setContent() [2/3]

Data & ndn::Data::setContent ( const uint8_t *  value,
size_t  valueSize 
)

Copy Content value from raw buffer.

Parameters
valuepointer to the first octet of the value
valueSizesize of the raw buffer
Returns
a reference to this Data, to allow chaining

Definition at line 258 of file data.cpp.

References ndn::tlv::Content, ndn::encoding::makeBinaryBlock(), and resetWire().

◆ setContent() [3/3]

Data & ndn::Data::setContent ( const ConstBufferPtr value)

Set Content from wire buffer.

Parameters
valueContent value, which does not need to be a TLV element
Returns
a reference to this Data, to allow chaining

Definition at line 266 of file data.cpp.

References ndn::tlv::Content, and resetWire().

◆ getSignature()

◆ setSignature()

Data & ndn::Data::setSignature ( const Signature signature)

Set Signature.

Returns
a reference to this Data, to allow chaining

Definition at line 274 of file data.cpp.

References resetWire().

Referenced by ndn::security::v2::KeyChain::sign().

◆ setSignatureValue()

Data & ndn::Data::setSignatureValue ( const Block value)

Set SignatureValue.

Returns
a reference to this Data, to allow chaining

Definition at line 282 of file data.cpp.

References resetWire(), and ndn::Signature::setValue().

◆ getContentType()

uint32_t ndn::Data::getContentType ( ) const
inline

◆ setContentType()

Data & ndn::Data::setContentType ( uint32_t  type)

Definition at line 290 of file data.cpp.

References resetWire(), and ndn::MetaInfo::setType().

Referenced by ndn::security::v2::Certificate::Certificate().

◆ getFreshnessPeriod()

time::milliseconds ndn::Data::getFreshnessPeriod ( ) const
inline

◆ setFreshnessPeriod()

Data & ndn::Data::setFreshnessPeriod ( time::milliseconds  freshnessPeriod)

Definition at line 298 of file data.cpp.

References resetWire(), and ndn::MetaInfo::setFreshnessPeriod().

◆ getFinalBlock()

const optional<name::Component>& ndn::Data::getFinalBlock ( ) const
inline

Definition at line 226 of file data.hpp.

References ndn::MetaInfo::getFinalBlock().

◆ setFinalBlock()

Data & ndn::Data::setFinalBlock ( optional< name::Component finalBlockId)

Definition at line 306 of file data.cpp.

References resetWire(), and ndn::MetaInfo::setFinalBlock().

◆ getFinalBlockId()

name::Component ndn::Data::getFinalBlockId ( ) const
Deprecated:
Use getFinalBlock
See also
MetaInfo::getFinalBlockId

Definition at line 314 of file data.cpp.

References ndn::MetaInfo::getFinalBlockId().

◆ setFinalBlockId()

Data & ndn::Data::setFinalBlockId ( const name::Component finalBlockId)
Deprecated:
Use setFinalBlock
See also
MetaInfo::setFinalBlockId

Definition at line 320 of file data.cpp.

References resetWire(), and ndn::MetaInfo::setFinalBlockId().

◆ resetWire()

void ndn::Data::resetWire ( )
protected

Clear wire encoding and cached FullName.

Note
This does not clear the SignatureValue.

Definition at line 211 of file data.cpp.

References ndn::Name::clear(), and ndn::Block::reset().

Referenced by setContent(), setContentType(), setFinalBlock(), setFinalBlockId(), setFreshnessPeriod(), setMetaInfo(), setName(), setSignature(), and setSignatureValue().


The documentation for this class was generated from the following files: