NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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 ()
 Create an empty Data object. More...
 
 Data (const Name &name)
 Create a new Data object with the given name. More...
 
 Data (const Block &wire)
 Create a new Data object from wire encoding. More...
 
template<encoding::Tag TAG>
size_t wireEncode (EncodingImpl< TAG > &encoder, bool wantUnsignedPortionOnly=false) const
 Fast encoding or block size estimation. More...
 
const BlockwireEncode () const
 Encode to a wire format. More...
 
const BlockwireEncode (EncodingBuffer &encoder, const Block &signatureValue) const
 Finalize Data packet encoding with the specified SignatureValue. More...
 
void wireDecode (const Block &wire)
 Decode from the wire format. More...
 
bool hasWire () const
 Check if Data is already has wire encoding. More...
 
const NamegetName () const
 Get name of the Data packet. More...
 
DatasetName (const Name &name)
 Set name to a copy of the given Name. More...
 
const NamegetFullName () const
 Get full name of Data packet, including the implicit digest. More...
 
const MetaInfogetMetaInfo () const
 Get MetaInfo block from Data packet. More...
 
DatasetMetaInfo (const MetaInfo &metaInfo)
 Set metaInfo to a copy of the given MetaInfo. More...
 
uint32_t getContentType () const
 
DatasetContentType (uint32_t type)
 
const time::milliseconds & getFreshnessPeriod () const
 
DatasetFreshnessPeriod (const time::milliseconds &freshnessPeriod)
 
const name::ComponentgetFinalBlockId () const
 
DatasetFinalBlockId (const name::Component &finalBlockId)
 
const BlockgetContent () const
 Get content Block. More...
 
DatasetContent (const uint8_t *buffer, size_t bufferSize)
 Set the content from the buffer (buffer will be copied) More...
 
DatasetContent (const Block &block)
 Set the content from the block. More...
 
DatasetContent (const ConstBufferPtr &contentValue)
 Set the content from the pointer to immutable buffer. More...
 
const SignaturegetSignature () const
 
DatasetSignature (const Signature &signature)
 Set the signature to a copy of the given signature. More...
 
DatasetSignatureValue (const Block &value)
 
bool operator== (const Data &other) const
 
bool operator!= (const Data &other) const
 
- 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 onChanged ()
 Clear the wire encoding. More...
 

Detailed Description

represents a Data packet

Definition at line 37 of file data.hpp.

Constructor & Destructor Documentation

◆ Data() [1/3]

ndn::Data::Data ( )

Create an empty Data object.

Note that in certain contexts that use Data::shared_from_this(), Data must be created using make_shared:

shared_ptr<Data> data = make_shared<Data>();

Otherwise, Data::shared_from_this() will throw an exception.

Definition at line 35 of file data.cpp.

Referenced by ndn::Data::Error::Error().

◆ Data() [2/3]

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

Create a new Data object with the given name.

Parameters
nameA reference to the name

Note that in certain contexts that use Data::shared_from_this(), Data must be created using make_shared:

shared_ptr<Data> data = make_shared<Data>(name);

Otherwise, Data::shared_from_this() will throw an exception.

Definition at line 40 of file data.cpp.

◆ Data() [3/3]

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

Create a new Data object from wire encoding.

Note that in certain contexts that use Data::shared_from_this(), Data must be created using make_shared:

shared_ptr<Data> data = make_shared<Data>(wire);

Otherwise, Data::shared_from_this() will throw an exception.

Definition at line 45 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

Fast encoding or block size estimation.

Parameters
encoderEncodingEstimator or EncodingBuffer instance
wantUnsignedPortionOnlyRequest only unsigned portion to be encoded in block. If true, only Name, MetaInfo, Content, and SignatureInfo blocks will be encoded into the block. Note that there will be no outer TLV header of the Data packet.

Definition at line 52 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::SecPublicInfoSqlite3::addCertificate(), ndn::security::PibSqlite3::addCertificate(), nfd::face::GenericLinkService::GenericLinkService(), ndn::security::KeyChain::getDefaultKeyParamsForIdentity(), ndn::Face::put(), ndn::security::SecuredBag::SecuredBag(), ndn::security::Validator::verifySignature(), and ndn::security::SafeBag::wireEncode().

◆ wireEncode() [2/3]

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

Encode to a wire format.

Definition at line 119 of file data.cpp.

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

Referenced by ndn::Link::encodeContent(), and ndn::Data::Error::Error().

◆ wireEncode() [3/3]

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

Finalize Data packet encoding with the specified SignatureValue.

Parameters
encoderEncodingBuffer instance, containing Name, MetaInfo, Content, and SignatureInfo (without outer TLV header of the Data packet).
signatureValueSignatureValue block to be added to Data packet to finalize the wire encoding

This method is intended to be used in concert with Data::wireEncode(EncodingBuffer&, true) method to optimize Data packet wire format creation:

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 106 of file data.cpp.

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

◆ wireDecode()

◆ hasWire()

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

Check if Data is already has wire encoding.

Definition at line 312 of file data.hpp.

Referenced by ndn::Data::Error::Error().

◆ getName()

const Name & ndn::Data::getName ( ) const
inline

Get name of the Data packet.

Definition at line 318 of file data.hpp.

Referenced by ndn::security::SecPublicInfoSqlite3::addCertificate(), ndn::security::PibMemory::addCertificate(), ndn::security::PibSqlite3::addCertificate(), ndn::security::SecPublicInfo::addCertificateAsIdentityDefault(), ndn::security::SecPublicInfo::addCertificateAsKeyDefault(), ndn::security::SecPublicInfo::addCertificateAsSystemDefault(), nfd::fw::asf::AsfStrategy::beforeSatisfyInterest(), nfd::fw::AccessStrategy::beforeSatisfyInterest(), nfd::fw::Strategy::beforeSatisfyInterest(), ndn::security::conf::KeyLocatorChecker::check(), ndn::security::ValidatorRegex::checkPolicy(), nfd::cs::compareDataWithData(), nfd::cs::compareQueryWithData(), ndn::Data::Error::Error(), nfd::pit::Pit::findAllDataMatches(), ndn::security::Key::getPublicKey(), ndn::security::KeyChain::importIdentity(), nfd::cs::Cs::insert(), ndn::security::conf::Filter::match(), ndn::SecRuleSpecific::matchDataName(), ndn::SecRuleRelative::matchDataName(), ndn::Interest::matchesData(), ndn::security::Validator::onData(), ndn::operator<<(), operator==(), ndn::security::v1::Certificate::printCertificate(), ndn::Face::registerPrefix(), ndn::security::Key::removeCertificate(), ndn::SecRuleRelative::satisfy(), ndn::security::KeyChain::selfSign(), ndn::security::Key::setDefaultCertificate(), ndn::Face::setInterestFilter(), ndn::security::v1::IdentityCertificate::setName(), ndn::nfd::CommandOptions::setSigningInfo(), nfd::Forwarder::startProcessNack(), and wireEncode().

◆ setName()

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

Set name to a copy of the given Name.

Returns
This Data so that you can chain calls to update values

Definition at line 170 of file data.cpp.

References onChanged().

Referenced by ndn::Data::Error::Error(), and ndn::security::v1::IdentityCertificate::setName().

◆ getFullName()

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

Get full name of Data packet, including the implicit digest.

Exceptions
Errorif Data packet doesn't have a full name yet (wire encoding has not been yet created)

Definition at line 179 of file data.cpp.

References ndn::Name::appendImplicitSha256Digest(), ndn::crypto::computeSha256Digest(), ndn::Name::empty(), ndn::Block::hasWire(), ndn::Block::size(), and ndn::Block::wire().

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

◆ getMetaInfo()

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

Get MetaInfo block from Data packet.

Definition at line 324 of file data.hpp.

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

◆ setMetaInfo()

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

Set metaInfo to a copy of the given MetaInfo.

Returns
This Data so that you can chain calls to update values.

Definition at line 194 of file data.cpp.

References onChanged().

Referenced by ndn::Data::Error::Error().

◆ getContentType()

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

Definition at line 330 of file data.hpp.

Referenced by ndn::Link::decodeContent(), and ndn::Data::Error::Error().

◆ setContentType()

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

◆ getFreshnessPeriod()

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

Definition at line 336 of file data.hpp.

Referenced by ndn::Data::Error::Error(), and nfd::Forwarder::startProcessNack().

◆ setFreshnessPeriod()

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

◆ getFinalBlockId()

const name::Component & ndn::Data::getFinalBlockId ( ) const
inline

Definition at line 342 of file data.hpp.

Referenced by ndn::Data::Error::Error().

◆ setFinalBlockId()

Data & ndn::Data::setFinalBlockId ( const name::Component finalBlockId)

Definition at line 221 of file data.cpp.

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

Referenced by ndn::Data::Error::Error().

◆ getContent()

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

Get content Block.

To access content value, one can use value()/value_size() or value_begin()/value_end() methods of the Block class

Definition at line 230 of file data.cpp.

References ndn::tlv::Content, ndn::Block::empty(), ndn::Block::encode(), ndn::Block::hasWire(), and ndn::encoding::makeEmptyBlock().

Referenced by ndn::nfd::Controller::Controller(), ndn::security::v1::Certificate::decode(), ndn::Link::decodeContent(), ndn::Data::Error::Error(), ndn::operator<<(), operator==(), and wireEncode().

◆ setContent() [1/3]

Data & ndn::Data::setContent ( const uint8_t *  buffer,
size_t  bufferSize 
)

Set the content from the buffer (buffer will be copied)

Parameters
bufferPointer to first byte of the buffer
bufferSizeSize of the buffer
Returns
This Data so that you can chain calls to update values.

Definition at line 241 of file data.cpp.

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

Referenced by ndn::security::v1::Certificate::encode(), ndn::Link::encodeContent(), and ndn::Data::Error::Error().

◆ setContent() [2/3]

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

Set the content from the block.

Depending on type of the supplied block, there are two cases:

  • if block.type() == tlv::Content, then block will be used directly as Data packet's content (no extra copying)
  • if block.type() != tlv::Content, then this method will create a new Block with type tlv::Content and put block as a nested element in the content Block.
Parameters
blockThe Block containing the content to assign
Returns
This Data so that you can chain calls to update values.

Definition at line 261 of file data.cpp.

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

◆ setContent() [3/3]

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

Set the content from the pointer to immutable buffer.

This method will create a Block with tlv::Content and set contentValue as a payload for this block. Note that this method is very different from setContent(const Block&), since it does not require that payload should be a valid TLV element.

Parameters
contentValueThe pointer to immutable buffer containing the content to assign
Returns
This Data so that you can chain calls to update values.

Definition at line 251 of file data.cpp.

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

◆ getSignature()

◆ setSignature()

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

Set the signature to a copy of the given signature.

Parameters
signatureThe signature object which is cloned.

Definition at line 275 of file data.cpp.

References onChanged().

Referenced by ndn::Data::Error::Error(), and ndn::security::KeyChain::getDefaultKeyParamsForIdentity().

◆ setSignatureValue()

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

Definition at line 284 of file data.cpp.

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

Referenced by ndn::Data::Error::Error().

◆ operator==()

bool ndn::Data::operator== ( const Data other) const

Definition at line 305 of file data.cpp.

References getContent(), getMetaInfo(), getName(), and getSignature().

Referenced by ndn::Data::Error::Error().

◆ operator!=()

bool ndn::Data::operator!= ( const Data other) const

Definition at line 314 of file data.cpp.

Referenced by ndn::Data::Error::Error().

◆ onChanged()

void ndn::Data::onChanged ( )
protected

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