Classes | Public Member Functions | Static Public Member Functions | List of all members
ndn::Node Class Reference
Inheritance diagram for ndn::Node:
ndn::ElementListener ndn_ElementListener

Public Member Functions

 Node (const ptr_lib::shared_ptr< Transport > &transport, const ptr_lib::shared_ptr< const Transport::ConnectionInfo > &connectionInfo)
 Create a new Node for communication with an NDN hub with the given Transport object and connectionInfo. More...
 
void expressInterest (uint64_t pendingInterestId, const ptr_lib::shared_ptr< const Interest > &interestCopy, const OnData &onData, const OnTimeout &onTimeout, const OnNetworkNack &onNetworkNack, WireFormat &wireFormat, Face *face)
 Send the Interest through the transport, read the entire response and call onData, onTimeout or onNetworkNack as described below. More...
 
void removePendingInterest (uint64_t pendingInterestId)
 Remove the pending interest entry with the pendingInterestId from the pending interest table. More...
 
void makeCommandInterest (Interest &interest, KeyChain &keyChain, const Name &certificateName, WireFormat &wireFormat)
 Append a timestamp component and a random value component to interest's name. More...
 
void registerPrefix (uint64_t registeredPrefixId, const ptr_lib::shared_ptr< const Name > &prefixCopy, const OnInterestCallback &onInterest, const OnRegisterFailed &onRegisterFailed, const OnRegisterSuccess &onRegisterSuccess, const ForwardingFlags &flags, WireFormat &wireFormat, KeyChain &commandKeyChain, const Name &commandCertificateName, Face *face)
 Register prefix with the connected NDN hub and call onInterest when a matching interest is received. More...
 
void registerPrefix (uint64_t registeredPrefixId, const ptr_lib::shared_ptr< const Name > &prefixCopy, const OnInterestCallback &onInterest, const OnRegisterFailed &onRegisterFailed, const OnRegisterSuccess &onRegisterSuccess, const ForwardingFlags &flags, WireFormat &wireFormat, Face *face)
 This is the same as registerPrefix above except get the commandKeyChain and commandCertificateName directly from face.
 
void removeRegisteredPrefix (uint64_t registeredPrefixId)
 Remove the registered prefix entry with the registeredPrefixId from the registered prefix table. More...
 
void setInterestFilter (uint64_t interestFilterId, const ptr_lib::shared_ptr< const InterestFilter > &filterCopy, const OnInterestCallback &onInterest, Face *face)
 Add an entry to the local interest filter table to call the onInterest callback for a matching incoming Interest. More...
 
void unsetInterestFilter (uint64_t interestFilterId)
 Remove the interest filter entry which has the interestFilterId from the interest filter table. More...
 
void send (const uint8_t *encoding, size_t encodingLength)
 Send the encoded packet out through the face. More...
 
void processEvents ()
 Process any packets to receive and call callbacks such as onData, onInterest or onTimeout. More...
 
const ptr_lib::shared_ptr< Transport > & getTransport ()
 
const ptr_lib::shared_ptr< const Transport::ConnectionInfo > & getConnectionInfo ()
 
void onReceivedElement (const uint8_t *element, size_t elementLength)
 This is called when an entire element is received. More...
 
bool isLocal ()
 Check if the face is local based on the current connection through the Transport; some Transport may cause network I/O (e.g. More...
 
void shutdown ()
 
void callLater (Milliseconds delayMilliseconds, const Face::Callback &callback)
 Call callback() after the given delay. More...
 
uint64_t getNextEntryId ()
 Get the next unique entry ID for the pending interest table, interest filter table, etc. More...
 

Static Public Member Functions

static size_t getMaxNdnPacketSize ()
 Get the practical limit of the size of a network-layer packet. More...
 

Additional Inherited Members

- Public Attributes inherited from ndn_ElementListener
ndn_OnReceivedElement onReceivedElement
 see ndn_ElementListener_initialize
 

Constructor & Destructor Documentation

ndn::Node::Node ( const ptr_lib::shared_ptr< Transport > &  transport,
const ptr_lib::shared_ptr< const Transport::ConnectionInfo > &  connectionInfo 
)

Create a new Node for communication with an NDN hub with the given Transport object and connectionInfo.

Parameters
transportA shared_ptr to a Transport object used for communication.
transportA shared_ptr to a Transport::ConnectionInfo to be used to connect to the transport.

Member Function Documentation

void ndn::Node::callLater ( Milliseconds  delayMilliseconds,
const Face::Callback callback 
)
inline

Call callback() after the given delay.

This adds to delayedCallTable_ which is used by processEvents().

Parameters
delayMillisecondsThe delay in milliseconds.
callbackThis calls callback() after the delay.
void ndn::Node::expressInterest ( uint64_t  pendingInterestId,
const ptr_lib::shared_ptr< const Interest > &  interestCopy,
const OnData onData,
const OnTimeout onTimeout,
const OnNetworkNack onNetworkNack,
WireFormat wireFormat,
Face face 
)

Send the Interest through the transport, read the entire response and call onData, onTimeout or onNetworkNack as described below.

Parameters
pendingInterestIdThe getNextEntryId() for the pending interest ID which Face got so it could return it to the caller.
interestCopyThe Interest which is NOT copied for this internal Node method. The Face expressInterest is responsible for making a copy and passing a shared_ptr for Node to use.
onDataWhen a matching data packet is received, this calls onData(interest, data) where interest is the interest given to expressInterest and data is the received Data object. This copies the function object, so you may need to use func_lib::ref() as appropriate.
onTimeoutIf the interest times out according to the interest lifetime, this calls onTimeout(interest) where interest is the interest given to expressInterest. If onTimeout is an empty OnTimeout(), this does not use it. This copies the function object, so you may need to use func_lib::ref() as appropriate.
onNetworkNackWhen a network Nack packet for the interest is received and onNetworkNack is not null, this calls onNetworkNack(interest, networkNack) and does not call onTimeout. However, if a network Nack is received and onNetworkNack is an empty OnNetworkNack(), do nothing and wait for the interest to time out. This copies the function object, so you may need to use func_lib::ref() as appropriate.
wireFormatA WireFormat object used to encode the message.
faceThe face which has the callLater method, used for interest timeouts. The callLater method may be overridden in a subclass of Face.
Exceptions
runtime_errorIf the encoded interest size exceeds getMaxNdnPacketSize().
static size_t ndn::Node::getMaxNdnPacketSize ( )
inlinestatic

Get the practical limit of the size of a network-layer packet.

If a packet is larger than this, the library or application MAY drop it. This is a static inline method wrapping a const, so you can to use as a constant, e.g.: uint8_t buffer[Face::getMaxNdnPacketSize()].

Returns
The maximum NDN packet size.
uint64_t ndn::Node::getNextEntryId ( )

Get the next unique entry ID for the pending interest table, interest filter table, etc.

This uses an atomic_uint64_t to be thread safe. Most entry IDs are for the pending interest table (there usually are not many interest filter table entries) so we use a common pool to only have to do the thread safe operation in one method which is called by Face.

Returns
The next entry ID.
bool ndn::Node::isLocal ( )
inline

Check if the face is local based on the current connection through the Transport; some Transport may cause network I/O (e.g.

an IP host name lookup).

Returns
True if the face is local, false if not.
void ndn::Node::makeCommandInterest ( Interest interest,
KeyChain keyChain,
const Name certificateName,
WireFormat wireFormat 
)
inline

Append a timestamp component and a random value component to interest's name.

Then use the keyChain and certificateName to sign the interest. If the interest lifetime is not set, this sets it.

Parameters
interestThe interest whose name is append with components.
keyChainThe KeyChain object for signing interests.
certificateNameThe certificate name for signing interests.
wireFormatA WireFormat object used to encode the SignatureInfo and to encode interest name for signing.
void ndn::Node::onReceivedElement ( const uint8_t *  element,
size_t  elementLength 
)
virtual

This is called when an entire element is received.

You must extend this class to override this method.

Parameters
elementpointer to the element. This buffer is only valid during this call. If you need the data later, you must copy.
elementLengthlength of element

Implements ndn::ElementListener.

void ndn::Node::processEvents ( )

Process any packets to receive and call callbacks such as onData, onInterest or onTimeout.

This returns immediately if there is no data to receive. This blocks while calling the callbacks. You should repeatedly call this from an event loop, with calls to sleep as needed so that the loop doesn’t use 100% of the CPU. Since processEvents modifies the pending interest table, your application should make sure that it calls processEvents in the same thread as expressInterest (which also modifies the pending interest table).

Exceptions
Thismay throw an exception for reading data or in the callback for processing the data. If you call this from an main event loop, you may want to catch and log/disregard all exceptions.
void ndn::Node::registerPrefix ( uint64_t  registeredPrefixId,
const ptr_lib::shared_ptr< const Name > &  prefixCopy,
const OnInterestCallback onInterest,
const OnRegisterFailed onRegisterFailed,
const OnRegisterSuccess onRegisterSuccess,
const ForwardingFlags flags,
WireFormat wireFormat,
KeyChain commandKeyChain,
const Name commandCertificateName,
Face face 
)

Register prefix with the connected NDN hub and call onInterest when a matching interest is received.

Parameters
registeredPrefixIdThe getNextEntryId() for the registered prefix ID which Face got so it could return it to the caller.
prefixCopyThe Name for the prefix to register, which is NOT copied for this internal Node method. The Face registerPrefix is responsible for making a copy and passing a shared_ptr for Node to use.
onInterest(optional) If not an empty OnInterestCallback(), this creates an interest filter from prefix so that when an Interest is received which matches the filter, this calls the function object onInterest(prefix, interest, face, interestFilterId, filter). This copies the function object, so you may need to use func_lib::ref() as appropriate. If onInterest is an empty OnInterestCallback(), it is ignored and you must call setInterestFilter.
onRegisterFailedA function object to call if failed to retrieve the connected hub’s ID or failed to register the prefix. This calls onRegisterFailed(prefix) where prefix is the prefix given to registerPrefix.
onRegisterSuccessA function object to call when registerPrefix receives a success message from the forwarder. This calls onRegisterSuccess(prefix, registeredPrefixId) where prefix and registeredPrefixId are the values given to registerPrefix. If onRegisterSuccess is an empty OnRegisterSuccess(), this does not use it.
flagsThe flags for finer control of which interests are forwarded to the application.
wireFormatA WireFormat object used to encode the message.
commandKeyChainThe KeyChain object for signing interests.
commandCertificateNameThe certificate name for signing interests.
faceThe face which is passed to the onInterest callback. If onInterest is null, this is ignored.
void ndn::Node::removePendingInterest ( uint64_t  pendingInterestId)
inline

Remove the pending interest entry with the pendingInterestId from the pending interest table.

This does not affect another pending interest with a different pendingInterestId, even if it has the same interest name. If there is no entry with the pendingInterestId, do nothing.

Parameters
pendingInterestIdThe ID returned from expressInterest.
void ndn::Node::removeRegisteredPrefix ( uint64_t  registeredPrefixId)
inline

Remove the registered prefix entry with the registeredPrefixId from the registered prefix table.

This does not affect another registered prefix with a different registeredPrefixId, even if it has the same prefix name. If there is no entry with the registeredPrefixId, do nothing. If an interest filter was automatically created by registerPrefix, also remove it.

Parameters
registeredPrefixIdThe ID returned from registerPrefix.
void ndn::Node::send ( const uint8_t *  encoding,
size_t  encodingLength 
)

Send the encoded packet out through the face.

Parameters
encodingThe array of bytes for the encoded packet to send.
encodingLengthThe number of bytes in the encoding array.
Exceptions
runtime_errorIf the encoded Data packet size exceeds getMaxNdnPacketSize().
void ndn::Node::setInterestFilter ( uint64_t  interestFilterId,
const ptr_lib::shared_ptr< const InterestFilter > &  filterCopy,
const OnInterestCallback onInterest,
Face face 
)
inline

Add an entry to the local interest filter table to call the onInterest callback for a matching incoming Interest.

This method only modifies the library's local callback table and does not register the prefix with the forwarder. It will always succeed. To register a prefix with the forwarder, use registerPrefix.

Parameters
interestFilterIdThe getNextEntryId() for the interest filter ID which Face got so it could return it to the caller.
filterCopyThe InterestFilter with a prefix and optional regex filter used to match the name of an incoming Interest, which is NOT copied for this internal Node method. The Face setInterestFilter is responsible for making a copy and passing a shared_ptr for Node to use.
onInterestWhen an Interest is received which matches the filter, this calls onInterest(prefix, interest, face, interestFilterId, filter).
faceThe face which is passed to the onInterest callback.
void ndn::Node::unsetInterestFilter ( uint64_t  interestFilterId)
inline

Remove the interest filter entry which has the interestFilterId from the interest filter table.

This does not affect another interest filter with a different interestFilterId, even if it has the same prefix name. If there is no entry with the interestFilterId, do nothing.

Parameters
interestFilterIdThe ID returned from setInterestFilter.

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