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...
 
uint64_t expressInterest (const Interest &interest, const OnData &onData, const OnTimeout &onTimeout, WireFormat &wireFormat)
 Send the Interest through the transport, read the entire response and call onData(interest, data). 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...
 
uint64_t registerPrefix (const Name &prefix, const OnInterestCallback &onInterest, const OnRegisterFailed &onRegisterFailed, 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 removeRegisteredPrefix (uint64_t registeredPrefixId)
 Remove the registered prefix entry with the registeredPrefixId from the registered prefix table. More...
 
uint64_t setInterestFilter (const InterestFilter &filter, 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 putData (const Data &data, WireFormat &wireFormat)
 The OnInterestCallback calls this to put a Data packet which satisfies an Interest. 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 binary XML 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 ()
 

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

uint64_t ndn::Node::expressInterest ( const Interest interest,
const OnData onData,
const OnTimeout onTimeout,
WireFormat wireFormat 
)

Send the Interest through the transport, read the entire response and call onData(interest, data).

Parameters
interestA reference to the Interest. This copies the Interest.
onDataA function object to call when a matching data packet is received. This copies the function object, so you may need to use func_lib::ref() as appropriate.
onTimeoutA function object to call if the interest times out. 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.
wireFormatA WireFormat object used to encode the message.
Returns
The pending interest ID which can be used with removePendingInterest.
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.
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 binary XML element is received.

You must extend this class to override this method.

Parameters
elementpointer to the binary XML 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::putData ( const Data data,
WireFormat wireFormat 
)

The OnInterestCallback calls this to put a Data packet which satisfies an Interest.

Parameters
dataThe Data packet which satisfies the interest.
wireFormatA WireFormat object used to encode the Data packet.
Exceptions
runtime_errorIf the encoded Data packet size exceeds getMaxNdnPacketSize().
uint64_t ndn::Node::registerPrefix ( const Name prefix,
const OnInterestCallback onInterest,
const OnRegisterFailed onRegisterFailed,
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
prefixA reference to a Name for the prefix to register. This copies the Name.
onInterest(optional) If not null, 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 null, 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.
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. If null, assume we are connected to a legacy NDNx forwarder.
commandCertificateNameThe certificate name for signing interests.
faceThe face which is passed to the onInterest callback. If onInterest is null, this is ignored.
Returns
The registered prefix ID which can be used with removeRegisteredPrefix.
void ndn::Node::removePendingInterest ( uint64_t  pendingInterestId)

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)

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().
uint64_t ndn::Node::setInterestFilter ( const InterestFilter filter,
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
filterThe InterestFilter with a prefix and optional regex filter used to match the name of an incoming Interest. This makes a copy of filter.
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.
Returns
The interest filter ID which can be used with unsetInterestFilter.
void ndn::Node::unsetInterestFilter ( uint64_t  interestFilterId)

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: